Skip to content

feat: start a recipe with llama-stack backend #3016

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { VMType } from '@shared/models/IPodman';
import { POD_LABEL_MODEL_ID, POD_LABEL_RECIPE_ID } from '../../utils/RecipeConstants';
import type { InferenceServer } from '@shared/models/IInference';
import type { RpcExtension } from '@shared/messages/MessageProxy';
import type { LlamaStackManager } from '../llama-stack/llamaStackManager';

const taskRegistryMock = {
createTask: vi.fn(),
Expand Down Expand Up @@ -75,6 +76,10 @@ const recipeManager = {
buildRecipe: vi.fn(),
} as unknown as RecipeManager;

const llamaStackManager = {
getLlamaStackContainer: vi.fn(),
} as unknown as LlamaStackManager;

vi.mock('@podman-desktop/api', () => ({
window: {
withProgress: vi.fn(),
Expand Down Expand Up @@ -139,6 +144,11 @@ beforeEach(() => {
id: 'fake-task',
}));
vi.mocked(modelsManagerMock.uploadModelToPodmanMachine).mockResolvedValue('downloaded-model-path');
vi.mocked(llamaStackManager.getLlamaStackContainer).mockResolvedValue({
containerId: 'container1',
port: 10001,
playgroundPort: 10002,
});
});

function getInitializedApplicationManager(): ApplicationManager {
Expand All @@ -151,6 +161,7 @@ function getInitializedApplicationManager(): ApplicationManager {
telemetryMock,
podManager,
recipeManager,
llamaStackManager,
);

manager.init();
Expand All @@ -160,11 +171,11 @@ function getInitializedApplicationManager(): ApplicationManager {
describe('requestPullApplication', () => {
test('task should be set to error if pull application raise an error', async () => {
vi.mocked(window.withProgress).mockRejectedValue(new Error('pull application error'));
const trackingId = await getInitializedApplicationManager().requestPullApplication(
connectionMock,
recipeMock,
remoteModelMock,
);
const trackingId = await getInitializedApplicationManager().requestPullApplication({
connection: connectionMock,
recipe: recipeMock,
model: remoteModelMock,
});

// ensure the task is created
await vi.waitFor(() => {
Expand Down Expand Up @@ -292,9 +303,16 @@ describe('startApplication', () => {

describe('pullApplication', () => {
test('labels should be propagated', async () => {
await getInitializedApplicationManager().pullApplication(connectionMock, recipeMock, remoteModelMock, {
'test-label': 'test-value',
});
await getInitializedApplicationManager().pullApplication(
{
connection: connectionMock,
recipe: recipeMock,
model: remoteModelMock,
},
{
'test-label': 'test-value',
},
);

// clone the recipe
expect(recipeManager.cloneRecipe).toHaveBeenCalledWith(recipeMock, {
Expand All @@ -314,11 +332,18 @@ describe('pullApplication', () => {
'model-id': remoteModelMock.id,
});
// build the recipe
expect(recipeManager.buildRecipe).toHaveBeenCalledWith(connectionMock, recipeMock, remoteModelMock, {
'test-label': 'test-value',
'recipe-id': recipeMock.id,
'model-id': remoteModelMock.id,
});
expect(recipeManager.buildRecipe).toHaveBeenCalledWith(
{
connection: connectionMock,
recipe: recipeMock,
model: remoteModelMock,
},
{
'test-label': 'test-value',
'recipe-id': recipeMock.id,
'model-id': remoteModelMock.id,
},
);
// create AI App task must be created
expect(taskRegistryMock.createTask).toHaveBeenCalledWith('Creating AI App', 'loading', {
'test-label': 'test-value',
Expand Down Expand Up @@ -361,9 +386,17 @@ describe('pullApplication', () => {
},
} as InferenceServer,
});
await getInitializedApplicationManager().pullApplication(connectionMock, recipeMock, remoteModelMock, {
'test-label': 'test-value',
});
vi.mocked(modelsManagerMock.requestDownloadModel).mockResolvedValue('/path/to/model');
await getInitializedApplicationManager().pullApplication(
{
connection: connectionMock,
recipe: recipeMock,
model: remoteModelMock,
},
{
'test-label': 'test-value',
},
);

// clone the recipe
expect(recipeManager.cloneRecipe).toHaveBeenCalledWith(recipeMock, {
Expand All @@ -379,11 +412,18 @@ describe('pullApplication', () => {
// upload model to podman machine
expect(modelsManagerMock.uploadModelToPodmanMachine).not.toHaveBeenCalled();
// build the recipe
expect(recipeManager.buildRecipe).toHaveBeenCalledWith(connectionMock, recipeMock, remoteModelMock, {
'test-label': 'test-value',
'recipe-id': recipeMock.id,
'model-id': remoteModelMock.id,
});
expect(recipeManager.buildRecipe).toHaveBeenCalledWith(
{
connection: connectionMock,
recipe: recipeMock,
model: remoteModelMock,
},
{
'test-label': 'test-value',
'recipe-id': recipeMock.id,
'model-id': remoteModelMock.id,
},
);
// create AI App task must be created
expect(taskRegistryMock.createTask).toHaveBeenCalledWith('Creating AI App', 'loading', {
'test-label': 'test-value',
Expand Down Expand Up @@ -427,7 +467,11 @@ describe('pullApplication', () => {
},
} as unknown as PodInfo);

await getInitializedApplicationManager().pullApplication(connectionMock, recipeMock, remoteModelMock);
await getInitializedApplicationManager().pullApplication({
connection: connectionMock,
recipe: recipeMock,
model: remoteModelMock,
});

// removing existing application should create a task to notify the user
expect(taskRegistryMock.createTask).toHaveBeenCalledWith('Removing AI App', 'loading', {
Expand Down Expand Up @@ -456,7 +500,11 @@ describe('pullApplication', () => {
],
});

await getInitializedApplicationManager().pullApplication(connectionMock, recipeMock, remoteModelMock);
await getInitializedApplicationManager().pullApplication({
connection: connectionMock,
recipe: recipeMock,
model: remoteModelMock,
});

// the remove pod should have been called
expect(containerEngine.createContainer).toHaveBeenCalledWith(
Expand Down
Loading
Loading