diff --git a/packages/backend/src/playground.ts b/packages/backend/src/playground.ts index 7c2cec78d..3a0629df3 100644 --- a/packages/backend/src/playground.ts +++ b/packages/backend/src/playground.ts @@ -11,7 +11,7 @@ import type { ModelResponse } from '@shared/src/models/IModelResponse'; import path from 'node:path'; import * as http from 'node:http'; import { getFreePort } from './utils/ports'; -import { QueryState } from '@shared/models/IPlaygroundQueryState'; +import type { QueryState } from '@shared/src/models/IPlaygroundQueryState'; import { MSG_NEW_PLAYGROUND_QUERIES_STATE } from '@shared/Messages'; const LOCALAI_IMAGE = 'quay.io/go-skynet/local-ai:v2.5.1'; @@ -115,13 +115,13 @@ export class PlayGroundManager { prompt: prompt, } as QueryState; - let post_data = JSON.stringify({ + const post_data = JSON.stringify({ model: modelInfo.file, prompt: prompt, temperature: 0.7, }); - let post_options: http.RequestOptions = { + const post_options: http.RequestOptions = { host: 'localhost', port: '' + state.port, path: '/v1/completions', @@ -131,24 +131,21 @@ export class PlayGroundManager { }, }; - let post_req = http.request(post_options, res => { + const post_req = http.request(post_options, res => { res.setEncoding('utf8'); const chunks = []; res.on('data', data => chunks.push(data)); - res.on('end', () => { - let resBody = chunks.join(); - switch (res.headers['content-type']) { - case 'application/json': - const result = JSON.parse(resBody); - console.log('result', result); - const q = this.queries.get(query.id); - if (!q) { - throw new Error('query not found in state'); - } - q.response = result as ModelResponse; - this.queries.set(query.id, q); - this.sendState(); - break; + res.on('end', async () => { + const resBody = chunks.join(); + if (res.headers['content-type'] === 'application/json') { + const result = JSON.parse(resBody); + const q = this.queries.get(query.id); + if (!q) { + throw new Error('query not found in state'); + } + q.response = result as ModelResponse; + this.queries.set(query.id, q); + await this.sendState(); } }); }); @@ -157,7 +154,7 @@ export class PlayGroundManager { post_req.end(); this.queries.set(query.id, query); - this.sendState(); + await this.sendState(); return query.id; } @@ -167,7 +164,7 @@ export class PlayGroundManager { getState(): QueryState[] { return Array.from(this.queries.values()); } - sendState() { + async sendState() { this.webview.postMessage({ id: MSG_NEW_PLAYGROUND_QUERIES_STATE, body: this.getState(), diff --git a/packages/backend/src/studio-api-impl.ts b/packages/backend/src/studio-api-impl.ts index 46994c4d9..79e8a576a 100644 --- a/packages/backend/src/studio-api-impl.ts +++ b/packages/backend/src/studio-api-impl.ts @@ -12,7 +12,7 @@ import type { Task } from '@shared/src/models/ITask'; import * as path from 'node:path'; import type { PlayGroundManager } from './playground'; import * as podmanDesktopApi from '@podman-desktop/api'; -import { QueryState } from '@shared/models/IPlaygroundQueryState'; +import type { QueryState } from '@shared/src/models/IPlaygroundQueryState'; export const RECENT_CATEGORY_ID = 'recent-category'; diff --git a/packages/frontend/src/stores/playground-queries.ts b/packages/frontend/src/stores/playground-queries.ts index f9dcf2f8e..9196ffd9d 100644 --- a/packages/frontend/src/stores/playground-queries.ts +++ b/packages/frontend/src/stores/playground-queries.ts @@ -1,9 +1,8 @@ import type { Readable } from 'svelte/store'; import { readable } from 'svelte/store'; -import type { QueryState } from '@shared/models/IPlaygroundQueryState'; -import { rpcBrowser } from '../utils/client'; +import type { QueryState } from '@shared/src/models/IPlaygroundQueryState'; import { MSG_NEW_PLAYGROUND_QUERIES_STATE } from '@shared/Messages'; -import { studioClient } from '/@/utils/client'; +import { rpcBrowser, studioClient } from '/@/utils/client'; export const playgroundQueries: Readable = readable([], set => { const sub = rpcBrowser.subscribe(MSG_NEW_PLAYGROUND_QUERIES_STATE, msg => { diff --git a/packages/shared/models/IRecipe.ts b/packages/shared/models/IRecipe.ts deleted file mode 100644 index 2f5c74f52..000000000 --- a/packages/shared/models/IRecipe.ts +++ /dev/null @@ -1,11 +0,0 @@ -export interface Recipe { - id?: string, - name: string, - categories: string[], - description: string, - icon?: string, - repository: string, - readme: string, - config?: string, - models?: string[], -} diff --git a/packages/shared/src/StudioAPI.ts b/packages/shared/src/StudioAPI.ts index b1fbfd14f..053f55dba 100644 --- a/packages/shared/src/StudioAPI.ts +++ b/packages/shared/src/StudioAPI.ts @@ -3,7 +3,7 @@ import type { Category } from './models/ICategory'; import type { RecipeStatus } from './models/IRecipeStatus'; import type { ModelInfo } from './models/IModelInfo'; import type { Task } from './models/ITask'; -import { QueryState } from './models/IPlaygroundQueryState'; +import type { QueryState } from './models/IPlaygroundQueryState'; export abstract class StudioAPI { abstract ping(): Promise; diff --git a/packages/shared/models/IPlaygroundQueryState.ts b/packages/shared/src/models/IPlaygroundQueryState.ts similarity index 67% rename from packages/shared/models/IPlaygroundQueryState.ts rename to packages/shared/src/models/IPlaygroundQueryState.ts index 4f28f708a..9f8ae9349 100644 --- a/packages/shared/models/IPlaygroundQueryState.ts +++ b/packages/shared/src/models/IPlaygroundQueryState.ts @@ -1,4 +1,4 @@ -import { ModelResponse } from "./IModelResponse"; +import type { ModelResponse } from './IModelResponse'; export interface QueryState { id: number;