Skip to content

Commit

Permalink
fix: linter
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe Martin <[email protected]>
  • Loading branch information
feloy committed Jan 17, 2024
1 parent b897e9b commit c90d760
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 65 deletions.
36 changes: 21 additions & 15 deletions packages/backend/src/playground.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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`);
Expand All @@ -75,10 +81,10 @@ export class PlayGroundManager {
PortBindings: {
'8080/tcp': [
{
HostPort: '' + freePort
}
]
}
HostPort: '' + freePort,
},
],
},
},
Cmd: ['--models-path', '/models', '--context-size', '700', '--threads', '4'],
});
Expand Down Expand Up @@ -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 = {
Expand All @@ -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']) {
Expand All @@ -145,7 +151,7 @@ export class PlayGroundManager {
break;
}
});
});
});
// post the data
post_req.write(post_data);
post_req.end();
Expand All @@ -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(),
});
}
Expand Down
76 changes: 38 additions & 38 deletions packages/frontend/src/pages/ModelPlayground.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,31 @@ const mocks = vi.hoisted(() => {
f(mocks.playgroundQueriesSubscribeMock());
return () => {};
},
}
}
},
};
});

vi.mock('../utils/client', async () => {
return {
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(() => {
Expand All @@ -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));

Expand All @@ -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));

Expand All @@ -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));

Expand Down
10 changes: 5 additions & 5 deletions packages/frontend/src/stores/playground-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<QueryState[]> = readable<QueryState[]>([], (set) => {
const sub = rpcBrowser.subscribe(MSG_NEW_PLAYGROUND_QUERIES_STATE, (msg) => {
export const playgroundQueries: Readable<QueryState[]> = readable<QueryState[]>([], 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();
}
};
});
20 changes: 13 additions & 7 deletions packages/shared/src/MessageProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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>(): T {
Expand Down Expand Up @@ -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)
);
}
}

0 comments on commit c90d760

Please sign in to comment.