Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make recipes uses models based on backend property #1210

Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 8 additions & 35 deletions packages/backend/src/assets/ai.json

Large diffs are not rendered by default.

32 changes: 1 addition & 31 deletions packages/frontend/src/lib/RecipeDetails.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const initialCatalog: ApplicationCatalog = {
name: 'Recipe 1',
readme: 'readme 1',
categories: [],
models: ['model1', 'model2'],
recommended: ['model1', 'model2'],
description: 'description 1',
repository: 'repo 1',
},
Expand Down Expand Up @@ -183,36 +183,6 @@ test('swap model panel should be hidden on models tab', async () => {
expect(swapModelPanel2.classList.contains('hidden'));
});

test('should display default model information when model is the recommended', async () => {
mocks.getApplicationsStateMock.mockResolvedValue([]);
vi.mocked(catalogStore).catalog = readable<ApplicationCatalog>(initialCatalog);
render(RecipeDetails, {
recipeId: 'recipe 1',
modelId: 'model1',
});

const modelInfo = screen.getByLabelText('model-selected');
expect(modelInfo.textContent).equal('Model 1');
const licenseBadge = screen.getByLabelText('license-model');
expect(licenseBadge.textContent).equal('?');
const defaultWarning = screen.getByLabelText('model-warning');
expect(defaultWarning.textContent).contains('This is the default, recommended model for this recipe.');
});

test('should display non-default model information when model is not the recommended one', async () => {
mocks.getApplicationsStateMock.mockResolvedValue([]);
vi.mocked(catalogStore).catalog = readable<ApplicationCatalog>(initialCatalog);
render(RecipeDetails, {
recipeId: 'recipe 1',
modelId: 'model2',
});

const modelInfo = screen.getByLabelText('model-selected');
expect(modelInfo.textContent).equal('Model 2');
const defaultWarning = screen.getByLabelText('model-warning');
expect(defaultWarning.textContent).contains('The default model for this recipe is Model 1');
});

test('button vs code should be visible if local repository is not empty', async () => {
mocks.getApplicationsStateMock.mockResolvedValue([]);
mocks.getLocalRepositoriesMock.mockReturnValue([
Expand Down
8 changes: 4 additions & 4 deletions packages/frontend/src/lib/RecipeDetails.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const deleteLocalClone = () => {
<div class="bg-charcoal-900 min-w-[200px] grow flex flex-col p-2 rounded-md space-y-3">
<div class="flex justify-between items-center">
<span class="text-sm" aria-label="model-selected">{model?.name}</span>
{#if recipe?.models?.[0] === model.id}
{#if recipe?.recommended?.[0] === model.id}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There maybe several recommended models now

<i class="fas fa-star fa-xs text-gray-900" title="Recommended model"></i>
{/if}
</div>
Expand All @@ -150,15 +150,15 @@ const deleteLocalClone = () => {
{/if}
</div>
<div class="px-2 text-xs text-gray-700" aria-label="model-warning">
{#if recipe?.models?.[0] === model.id}
{#if recipe?.recommended?.[0] === model.id}
* This is the default, recommended model for this recipe. You can <a
class="underline"
href="{`/recipe/${recipeId}/models`}">swap for a different compatible model</a
>.
{:else}
* The default model for this recipe is {findModel(recipe?.models?.[0])?.name}. You can
* The default model for this recipe is {findModel(recipe?.recommended?.[0])?.name}. You can
<a class="underline" href="{`/recipe/${recipeId}/models`}"
>swap for {findModel(recipe?.models?.[0])?.name} or a different compatible model</a
>swap for {findModel(recipe?.recommended?.[0])?.name} or a different compatible model</a
>.
{/if}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const initialCatalog: ApplicationCatalog = {
name: 'Recipe 1',
readme: 'readme 1',
categories: [],
models: ['model1', 'model2'],
recommended: ['model1', 'model2'],
description: 'description 1',
repository: 'repo 1',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,11 @@
import '@testing-library/jest-dom/vitest';
import { test, expect } from 'vitest';
import { screen, render } from '@testing-library/svelte';
import type { RecipeModelInfo } from '/@/models/RecipeModelInfo';
import ModelColumnRecipeRecommended from './ModelColumnRecipeRecommended.svelte';

test('expect the star icon to be rendered whn recipe is recommended', async () => {
render(ModelColumnRecipeRecommended, {
object: {
id: 'id',
inUse: false,
recommended: true,
} as RecipeModelInfo,
object: true,
});

const starIcon = screen.getByTitle('Recommended model');
Expand All @@ -37,11 +32,7 @@ test('expect the star icon to be rendered whn recipe is recommended', async () =

test('expect nothing when recipe is NOT recommended', async () => {
render(ModelColumnRecipeRecommended, {
object: {
id: 'id',
inUse: false,
recommended: false,
} as RecipeModelInfo,
object: false,
});

const starIcon = screen.queryByTitle('Recommended model');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<script lang="ts">
import type { RecipeModelInfo } from '/@/models/RecipeModelInfo';
export let object: RecipeModelInfo;
export let object: boolean;
</script>

{#if object.recommended}
{#if object}
<i class="fas fa-star fa-xs text-gray-900" title="Recommended model"></i>
{/if}
1 change: 1 addition & 0 deletions packages/frontend/src/models/RecipeModelInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import type { ModelInfo } from '@shared/src/models/IModelInfo';

// todo :remove
axel7083 marked this conversation as resolved.
Show resolved Hide resolved
export interface RecipeModelInfo extends ModelInfo {
recommended: boolean;
inUse: boolean;
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/pages/Recipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const initialCatalog: ApplicationCatalog = {
name: 'Recipe 1',
readme: 'readme 1',
categories: [],
models: ['model1', 'model2'],
recommended: ['model1', 'model2'],
description: 'description 1',
repository: 'repo 1',
},
Expand Down Expand Up @@ -156,7 +156,7 @@ const updatedCatalog: ApplicationCatalog = {
name: 'New Recipe Name',
readme: 'readme 1',
categories: [],
models: ['model1', 'model2'],
recommended: ['model1', 'model2'],
description: 'description 1',
repository: 'repo 1',
},
Expand Down
17 changes: 14 additions & 3 deletions packages/frontend/src/pages/Recipe.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,31 @@ import ContainerConnectionStatusInfo from '../lib/notification/ContainerConnecti
import { modelsInfo } from '../stores/modelsInfo';
import { checkContainerConnectionStatus } from '../utils/connectionUtils';
import { router } from 'tinro';
import { InferenceType } from '@shared/src/models/IInference';
import type { ModelInfo } from '@shared/src/models/IModelInfo';

export let recipeId: string;

// The recipe model provided
$: recipe = $catalog.recipes.find(r => r.id === recipeId);
$: categories = $catalog.categories;

// model selected to start the recipe
let selectedModelId: string;
$: selectedModelId = recipe?.models?.[0] ?? '';
$: selectedModelId = recipe?.recommended && recipe.recommended.length > 0 ? recipe?.recommended?.[0] : '';
axel7083 marked this conversation as resolved.
Show resolved Hide resolved

let connectionInfo: ContainerConnectionInfo | undefined;
$: if ($modelsInfo && selectedModelId) {
checkContainerConnectionStatus($modelsInfo, selectedModelId, 'recipe')
.then(value => (connectionInfo = value))
.catch((e: unknown) => console.log(String(e)));
}

let models: ModelInfo[];
$: models = $catalog.models.filter(
model => (model.backend ?? InferenceType.NONE) === (recipe?.backend ?? InferenceType.NONE),
axel7083 marked this conversation as resolved.
Show resolved Hide resolved
);

// Send recipe info to telemetry
let recipeTelemetry: string | undefined = undefined;
$: if (recipe && recipe.id !== recipeTelemetry) {
Expand Down Expand Up @@ -68,8 +78,9 @@ function setSelectedModel(modelId: string) {
</Route>
<Route path="/models">
<RecipeModels
modelsIds="{recipe?.models}"
selectedModelId="{selectedModelId}"
models="{models}"
selected="{selectedModelId}"
recommended="{recipe?.recommended ?? []}"
setSelectedModel="{setSelectedModel}" />
</Route>
</svelte:fragment>
Expand Down
18 changes: 15 additions & 3 deletions packages/frontend/src/pages/RecipeModels.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ beforeEach(() => {
{
id: 'recipe1',
name: 'Recipe 1',
models: ['model1'],
recommended: ['model1'],
categories: [],
description: 'Recipe 1',
readme: '',
Expand All @@ -63,9 +63,21 @@ beforeEach(() => {

test('should display model icon', async () => {
render(RecipeModels, {
selectedModelId: 'model1',
recommended: [],
selected: 'model1',
setSelectedModel: vi.fn(),
modelsIds: ['model1'],
models: [
{
id: 'model1',
name: 'Model 1',
url: 'https://podman-desktop.io',
registry: 'Podman Desktop',
license: 'Apache 2.0',
description: '',
hw: 'CPU',
memory: 4 * 1024 * 1024 * 1024,
},
],
});

await waitFor(async () => {
Expand Down
54 changes: 26 additions & 28 deletions packages/frontend/src/pages/RecipeModels.svelte
Original file line number Diff line number Diff line change
@@ -1,46 +1,44 @@
<script lang="ts">
import ModelColumnName from '/@/lib/table/model/ModelColumnName.svelte';
import { catalog } from '/@/stores/catalog';
import ModelColumnRecipeSelection from '../lib/table/model/ModelColumnRecipeSelection.svelte';
import ModelColumnRecipeRecommended from '../lib/table/model/ModelColumnRecipeRecommended.svelte';
import type { RecipeModelInfo } from '../models/RecipeModelInfo';
import ModelColumnIcon from '/@/lib/table/model/ModelColumnIcon.svelte';
import { Table, TableColumn, TableRow } from '@podman-desktop/ui-svelte';
import type { ModelInfo } from '@shared/src/models/IModelInfo';

export let modelsIds: string[] | undefined;
export let selectedModelId: string;
export let models: ModelInfo[];
export let recommended: string[];
export let selected: string;
export let setSelectedModel: (modelId: string) => void;

$: models = $catalog.models
.filter(m => modelsIds?.includes(m.id))
.map((m, i) => {
return {
...m,
recommended: i === 0,
inUse: m.id === selectedModelId,
} as RecipeModelInfo;
});
$: models = models.map((m, i) => {
return {
...m,
inUse: m.id === selected,
};
});

const columns: TableColumn<RecipeModelInfo>[] = [
new TableColumn<RecipeModelInfo>('', { width: '20px', renderer: ModelColumnRecipeSelection }),
new TableColumn<RecipeModelInfo>('', { width: '20px', renderer: ModelColumnRecipeRecommended }),
new TableColumn<RecipeModelInfo>('', { width: '32px', renderer: ModelColumnIcon }),
new TableColumn<RecipeModelInfo>('Name', { width: '4fr', renderer: ModelColumnName }),
const columns = [
new TableColumn<ModelInfo>('', { width: '20px', renderer: ModelColumnRecipeSelection }),
new TableColumn<ModelInfo, boolean>('', {
width: '20px',
renderer: ModelColumnRecipeRecommended,
renderMapping: object => recommended.includes(object.id),
}),
new TableColumn<ModelInfo>('', { width: '32px', renderer: ModelColumnIcon }),
new TableColumn<ModelInfo>('Name', { width: '4fr', renderer: ModelColumnName }),
];
const row = new TableRow<RecipeModelInfo>({});
const row = new TableRow<ModelInfo>({});

function setModelToUse(selected: RecipeModelInfo) {
function setModelToUse(selected: ModelInfo) {
setSelectedModel(selected.id);
}
</script>

{#if models}
<div class="flex flex-col grow min-h-full">
<div class="w-full min-h-full flex-1">
<div class="h-full">
<Table kind="model" data="{models}" columns="{columns}" row="{row}" on:update="{e => setModelToUse(e.detail)}">
</Table>
</div>
<div class="flex flex-col grow min-h-full">
<div class="w-full min-h-full flex-1">
<div class="h-full">
<Table kind="model" data="{models}" columns="{columns}" row="{row}" on:update="{e => setModelToUse(e.detail)}" />
</div>
</div>
{/if}
</div>
4 changes: 2 additions & 2 deletions packages/frontend/src/pages/Recipes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ beforeEach(() => {
{
id: 'recipe1',
name: 'Recipe 1',
models: ['model1'],
recommended: ['model1'],
categories: [],
description: 'Recipe 1',
readme: '',
Expand All @@ -59,7 +59,7 @@ beforeEach(() => {
{
id: 'recipe2',
name: 'Recipe 2',
models: ['model2'],
recommended: ['model2'],
categories: ['dummy-category'],
description: 'Recipe 2',
readme: '',
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/models/IRecipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface Recipe {
ref?: string;
readme: string;
basedir?: string;
models?: string[];
recommended?: string[];
/**
* The backend field aims to target which inference
* server the recipe requires
Expand Down