From 2f91e98e351bb256b11c87dd70e5f87d6d20ac00 Mon Sep 17 00:00:00 2001 From: Philippe Martin Date: Wed, 17 Jan 2024 16:49:44 +0100 Subject: [PATCH] fix: linter --- packages/backend/src/playground.ts | 36 +++++---- .../src/pages/ModelPlayground.spec.ts | 76 +++++++++---------- .../frontend/src/stores/playground-queries.ts | 10 +-- packages/shared/src/MessageProxy.ts | 20 +++-- 4 files changed, 77 insertions(+), 65 deletions(-) diff --git a/packages/backend/src/playground.ts b/packages/backend/src/playground.ts index 2e6eee720..7c2cec78d 100644 --- a/packages/backend/src/playground.ts +++ b/packages/backend/src/playground.ts @@ -1,4 +1,10 @@ -import { provider, containerEngine, type Webview, type ProviderContainerConnection, type ImageInfo } from '@podman-desktop/api'; +import { + provider, + containerEngine, + type Webview, + type ProviderContainerConnection, + type ImageInfo, +} from '@podman-desktop/api'; import type { LocalModelInfo } from '@shared/src/models/ILocalModelInfo'; import type { ModelResponse } from '@shared/src/models/IModelResponse'; @@ -52,7 +58,7 @@ export class PlayGroundManager { let image = await this.selectImage(connection, LOCALAI_IMAGE); if (!image) { - await containerEngine.pullImage(connection.connection, LOCALAI_IMAGE, () => { }); + await containerEngine.pullImage(connection.connection, LOCALAI_IMAGE, () => {}); image = await this.selectImage(connection, LOCALAI_IMAGE); if (!image) { throw new Error(`Unable to find ${LOCALAI_IMAGE} image`); @@ -75,10 +81,10 @@ export class PlayGroundManager { PortBindings: { '8080/tcp': [ { - HostPort: '' + freePort - } - ] - } + HostPort: '' + freePort, + }, + ], + }, }, Cmd: ['--models-path', '/models', '--context-size', '700', '--threads', '4'], }); @@ -110,9 +116,9 @@ export class PlayGroundManager { } as QueryState; let post_data = JSON.stringify({ - "model": modelInfo.file, - "prompt": prompt, - "temperature": 0.7 + model: modelInfo.file, + prompt: prompt, + temperature: 0.7, }); let post_options: http.RequestOptions = { @@ -121,14 +127,14 @@ export class PlayGroundManager { path: '/v1/completions', method: 'POST', headers: { - 'Content-Type': 'application/json' - } + 'Content-Type': 'application/json', + }, }; let post_req = http.request(post_options, res => { res.setEncoding('utf8'); const chunks = []; - res.on('data', (data) => chunks.push(data)); + res.on('data', data => chunks.push(data)); res.on('end', () => { let resBody = chunks.join(); switch (res.headers['content-type']) { @@ -145,7 +151,7 @@ export class PlayGroundManager { break; } }); - }); + }); // post the data post_req.write(post_data); post_req.end(); @@ -162,8 +168,8 @@ export class PlayGroundManager { return Array.from(this.queries.values()); } sendState() { - this.webview.postMessage({ - id: MSG_NEW_PLAYGROUND_QUERIES_STATE, + this.webview.postMessage({ + id: MSG_NEW_PLAYGROUND_QUERIES_STATE, body: this.getState(), }); } diff --git a/packages/frontend/src/pages/ModelPlayground.spec.ts b/packages/frontend/src/pages/ModelPlayground.spec.ts index 35f0db7a7..ed559bc75 100644 --- a/packages/frontend/src/pages/ModelPlayground.spec.ts +++ b/packages/frontend/src/pages/ModelPlayground.spec.ts @@ -15,8 +15,8 @@ const mocks = vi.hoisted(() => { f(mocks.playgroundQueriesSubscribeMock()); return () => {}; }, - } - } + }, + }; }); vi.mock('../utils/client', async () => { @@ -24,22 +24,22 @@ vi.mock('../utils/client', async () => { studioClient: { startPlayground: mocks.startPlaygroundMock, askPlayground: mocks.askPlaygroundMock, - askPlaygroundQueries: () => { }, + askPlaygroundQueries: () => {}, }, rpcBrowser: { subscribe: () => { return { - unsubscribe: () => { }, - } - } - } + unsubscribe: () => {}, + }; + }, + }, }; }); vi.mock('../stores/playground-queries', async () => { return { playgroundQueries: mocks.playgroundQueriesMock, - } + }; }); beforeEach(() => { @@ -50,15 +50,15 @@ test('should start playground at init time and call askPlayground when button cl mocks.playgroundQueriesSubscribeMock.mockReturnValue([]); render(ModelPlayground, { model: { - id: "model1", - name: "Model 1", - description: "A description", - hw: "CPU", - registry: "Hugging Face", + id: 'model1', + name: 'Model 1', + description: 'A description', + hw: 'CPU', + registry: 'Hugging Face', popularity: 3, - license: "?", - url: "https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF/resolve/main/llama-2-7b-chat.Q5_K_S.gguf" - } as ModelInfo + license: '?', + url: 'https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF/resolve/main/llama-2-7b-chat.Q5_K_S.gguf', + } as ModelInfo, }); await new Promise(resolve => setTimeout(resolve, 200)); @@ -83,19 +83,19 @@ test('should display query without response', async () => { id: 1, modelId: 'model1', prompt: 'what is 1+1?', - } + }, ]); render(ModelPlayground, { model: { - id: "model1", - name: "Model 1", - description: "A description", - hw: "CPU", - registry: "Hugging Face", + id: 'model1', + name: 'Model 1', + description: 'A description', + hw: 'CPU', + registry: 'Hugging Face', popularity: 3, - license: "?", - url: "https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF/resolve/main/llama-2-7b-chat.Q5_K_S.gguf" - } as ModelInfo + license: '?', + url: 'https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF/resolve/main/llama-2-7b-chat.Q5_K_S.gguf', + } as ModelInfo, }); await new Promise(resolve => setTimeout(resolve, 200)); @@ -116,23 +116,23 @@ test('should display query without response', async () => { response: { choices: [ { - text: "The response is 2" - } - ] - } - } + text: 'The response is 2', + }, + ], + }, + }, ]); render(ModelPlayground, { model: { - id: "model1", - name: "Model 1", - description: "A description", - hw: "CPU", - registry: "Hugging Face", + id: 'model1', + name: 'Model 1', + description: 'A description', + hw: 'CPU', + registry: 'Hugging Face', popularity: 3, - license: "?", - url: "https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF/resolve/main/llama-2-7b-chat.Q5_K_S.gguf" - } as ModelInfo + license: '?', + url: 'https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF/resolve/main/llama-2-7b-chat.Q5_K_S.gguf', + } as ModelInfo, }); await new Promise(resolve => setTimeout(resolve, 200)); diff --git a/packages/frontend/src/stores/playground-queries.ts b/packages/frontend/src/stores/playground-queries.ts index 454f8b30c..f9dcf2f8e 100644 --- a/packages/frontend/src/stores/playground-queries.ts +++ b/packages/frontend/src/stores/playground-queries.ts @@ -5,15 +5,15 @@ import { rpcBrowser } from '../utils/client'; import { MSG_NEW_PLAYGROUND_QUERIES_STATE } from '@shared/Messages'; import { studioClient } from '/@/utils/client'; -export const playgroundQueries: Readable = readable([], (set) => { - const sub = rpcBrowser.subscribe(MSG_NEW_PLAYGROUND_QUERIES_STATE, (msg) => { +export const playgroundQueries: Readable = readable([], set => { + const sub = rpcBrowser.subscribe(MSG_NEW_PLAYGROUND_QUERIES_STATE, msg => { set(msg); }); - // Initialize the store manually - studioClient.getPlaygroundStates().then((state) => { + // Initialize the store manually + studioClient.getPlaygroundStates().then(state => { set(state); }); return () => { sub.unsubscribe(); - } + }; }); diff --git a/packages/shared/src/MessageProxy.ts b/packages/shared/src/MessageProxy.ts index c99b5a15d..6e5e777b6 100644 --- a/packages/shared/src/MessageProxy.ts +++ b/packages/shared/src/MessageProxy.ts @@ -137,8 +137,8 @@ export class RpcBrowser { const { resolve, reject } = this.promises.get(message.id) || {}; - if(message.status === 'error') { - reject?.(message.error) + if (message.status === 'error') { + reject?.(message.error); } else { resolve?.(message.body); } @@ -147,10 +147,10 @@ export class RpcBrowser { const handler = this.subscribers.get(message.id); handler?.(message.body); } else { - console.error("Received incompatible message.", message); + console.error('Received incompatible message.', message); return; } - }) + }); } getProxy(): T { @@ -203,11 +203,17 @@ export class RpcBrowser { return { unsubscribe: () => { this.subscribers.delete(msgId); - } - } + }, + }; } isSubscribedMessage(content: any): content is ISubscribedMessage { - return content !== undefined && content !== null && 'id' in content && 'body' in content && this.subscribers.has(content.id); + return ( + content !== undefined && + content !== null && + 'id' in content && + 'body' in content && + this.subscribers.has(content.id) + ); } }