Skip to content

Commit

Permalink
adopt playground containers
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed Jan 31, 2024
1 parent a1cb858 commit 6e2adff
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"views": {
"icons/containersList": [
{
"when": "ia-studio-model in containerLabelKeys",
"when": "ai-studio-model-id in containerLabelKeys",
"icon": "${brain-icon}"
}
]
Expand Down
33 changes: 32 additions & 1 deletion packages/backend/src/managers/playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ import { MSG_NEW_PLAYGROUND_QUERIES_STATE, MSG_PLAYGROUNDS_STATE_UPDATE } from '
import type { PlaygroundState, PlaygroundStatus } from '@shared/src/models/IPlaygroundState';
import type { ContainerRegistry } from '../registries/ContainerRegistry';

const LABEL_MODEL_ID = 'ai-studio-model-id';
const LABEL_MODEL_PORT = 'ai-studio-model-port';

// TODO: this should not be hardcoded
const PLAYGROUND_IMAGE = 'quay.io/bootsy/playground:v0';

Expand All @@ -60,6 +63,33 @@ export class PlayGroundManager {
this.queries = new Map<number, QueryState>();
}

async adoptRunningPlaygrounds() {
const containers = await containerEngine.listContainers();
const playgroundContainers = containers.filter(
c => LABEL_MODEL_ID in c.Labels && LABEL_MODEL_PORT in c.Labels && c.State === 'running',
);
for (const containerToAdopt of playgroundContainers) {
const modelId = containerToAdopt.Labels[LABEL_MODEL_ID];
if (this.playgrounds.has(modelId)) {
continue;
}
const modelPort = parseInt(containerToAdopt.Labels[LABEL_MODEL_PORT], 10);
if (isNaN(modelPort)) {
continue;
}
const state: PlaygroundState = {
modelId,
status: 'running',
container: {
containerId: containerToAdopt.Id,
engineId: containerToAdopt.engineId,
port: modelPort,
},
};
this.updatePlaygroundState(modelId, state);
}
}

async selectImage(connection: ProviderContainerConnection, image: string): Promise<ImageInfo | undefined> {
const images = (await containerEngine.listImages()).filter(im => im.RepoTags?.some(tag => tag === image));
return images.length > 0 ? images[0] : undefined;
Expand Down Expand Up @@ -143,7 +173,8 @@ export class PlayGroundManager {
},
},
Labels: {
'ia-studio-model': modelId,
[LABEL_MODEL_ID]: modelId,
[LABEL_MODEL_PORT]: '' + freePort,
},
Env: [`MODEL_PATH=/models/${path.basename(modelPath)}`],
Cmd: ['--models-path', '/models', '--context-size', '700', '--threads', '4'],
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/studio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export class Studio {

await this.catalogManager.loadCatalog();
await this.modelsManager.loadLocalModels();
await this.playgroundManager.adoptRunningPlaygrounds();

// Register the instance
this.rpcExtension.registerInstance<StudioApiImpl>(StudioApiImpl, this.studioApi);
Expand Down

0 comments on commit 6e2adff

Please sign in to comment.