Skip to content

Commit

Permalink
fix: prettier
Browse files Browse the repository at this point in the history
Signed-off-by: axel7083 <[email protected]>
  • Loading branch information
axel7083 committed Jan 19, 2024
1 parent 98512a6 commit 57de3e5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
29 changes: 15 additions & 14 deletions packages/backend/src/managers/playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import * as http from 'node:http';
import { getFreePort } from '../utils/ports';
import type { QueryState } from '@shared/src/models/IPlaygroundQueryState';
import { MSG_NEW_PLAYGROUND_QUERIES_STATE, MSG_PLAYGROUNDS_STATE_UPDATE } from '@shared/Messages';
import { PlaygroundState, PlaygroundStatus } from '@shared/src/models/IPlaygroundState';
import type { PlaygroundState, PlaygroundStatus } from '@shared/src/models/IPlaygroundState';

// TODO: this should not be hardcoded
const LOCALAI_IMAGE = 'quay.io/go-skynet/local-ai:v2.5.1';
Expand All @@ -47,7 +47,7 @@ function findFirstProvider(): ProviderContainerConnection | undefined {
export class PlayGroundManager {
private queryIdCounter = 0;

// Map<modelId, state>
// Dict modelId => state
private playgrounds: Map<string, PlaygroundState>;
private queries: Map<number, QueryState>;

Expand All @@ -62,7 +62,7 @@ export class PlayGroundManager {
}

setPlaygroundStatus(modelId: string, status: PlaygroundStatus) {
this.updatePlaygroundState(modelId, {
return this.updatePlaygroundState(modelId, {
modelId: modelId,
...(this.playgrounds.get(modelId) || {}),
status: status,
Expand All @@ -83,11 +83,11 @@ export class PlayGroundManager {
throw new Error('model is already running');
}

this.setPlaygroundStatus(modelId, 'starting');
await this.setPlaygroundStatus(modelId, 'starting');

const connection = findFirstProvider();
if (!connection) {
this.setPlaygroundStatus(modelId, 'error');
await this.setPlaygroundStatus(modelId, 'error');
throw new Error('Unable to find an engine to start playground');
}

Expand All @@ -96,7 +96,7 @@ export class PlayGroundManager {
await containerEngine.pullImage(connection.connection, LOCALAI_IMAGE, () => {});
image = await this.selectImage(connection, LOCALAI_IMAGE);
if (!image) {
this.setPlaygroundStatus(modelId, 'error');
await this.setPlaygroundStatus(modelId, 'error');
throw new Error(`Unable to find ${LOCALAI_IMAGE} image`);
}
}
Expand Down Expand Up @@ -126,7 +126,7 @@ export class PlayGroundManager {
Cmd: ['--models-path', '/models', '--context-size', '700', '--threads', '4'],
});

this.updatePlaygroundState(modelId, {
await this.updatePlaygroundState(modelId, {
container: {
containerId: result.id,
port: freePort,
Expand All @@ -141,24 +141,25 @@ export class PlayGroundManager {

async stopPlayground(modelId: string): Promise<void> {
const state = this.playgrounds.get(modelId);
if (!state || !state.container) {
if (state?.container === undefined) {
throw new Error('model is not running');
}
this.setPlaygroundStatus(modelId, 'stopping');
await this.setPlaygroundStatus(modelId, 'stopping');
// We do not await since it can take a lot of time
containerEngine
.stopContainer(state.container.engineId, state.container.containerId)
.then(() => {
this.setPlaygroundStatus(modelId, 'stopped');
.then(async () => {
await this.setPlaygroundStatus(modelId, 'stopped');
})
.catch(e => {
this.setPlaygroundStatus(modelId, 'error');
.catch(async (error: unknown) => {
console.error(error);
await this.setPlaygroundStatus(modelId, 'error');
});
}

async askPlayground(modelInfo: LocalModelInfo, prompt: string): Promise<number> {
const state = this.playgrounds.get(modelInfo.id);
if (!state || !state.container) {
if (state?.container === undefined) {
throw new Error('model is not running');
}

Expand Down
5 changes: 2 additions & 3 deletions packages/backend/src/studio-api-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import type { QueryState } from '@shared/src/models/IPlaygroundQueryState';
import * as path from 'node:path';
import type { CatalogManager } from './managers/catalogManager';
import type { Catalog } from '@shared/src/models/ICatalog';
import { PlaygroundState } from '@shared/src/models/IPlaygroundState';
import type { PlaygroundState } from '@shared/src/models/IPlaygroundState';

export class StudioApiImpl implements StudioAPI {
constructor(
Expand Down Expand Up @@ -64,8 +64,7 @@ export class StudioApiImpl implements StudioAPI {

async pullApplication(recipeId: string): Promise<void> {
const recipe = this.catalogManager.getRecipes().find(recipe => recipe.id === recipeId);
if (!recipe)
throw new Error('Not found');
if (!recipe) throw new Error('Not found');

// the user should have selected one model, we use the first one for the moment
const modelId = recipe.models[0];
Expand Down
2 changes: 0 additions & 2 deletions packages/shared/src/models/IPlaygroundQueryState.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { ModelResponse } from './IModelResponse';

type PlaygroundStatus = 'none' | 'stopped' | 'starting' | 'stopping' | 'running' | 'error';

export interface QueryState {
id: number;
modelId: string;
Expand Down

0 comments on commit 57de3e5

Please sign in to comment.