Skip to content

Commit

Permalink
fix eslint
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 c90d760 commit e3cdf00
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 38 deletions.
39 changes: 19 additions & 20 deletions packages/backend/src/playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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',
Expand All @@ -131,24 +131,23 @@ 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;
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);
this.sendState().catch((err: unknown) => {
console.error('playground: unable to send the response to the frontend', err);
});
}
});
});
Expand All @@ -157,7 +156,7 @@ export class PlayGroundManager {
post_req.end();

this.queries.set(query.id, query);
this.sendState();
await this.sendState();
return query.id;
}

Expand All @@ -167,8 +166,8 @@ export class PlayGroundManager {
getState(): QueryState[] {
return Array.from(this.queries.values());
}
sendState() {
this.webview.postMessage({
async sendState() {
await this.webview.postMessage({
id: MSG_NEW_PLAYGROUND_QUERIES_STATE,
body: this.getState(),
});
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/studio-api-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/pages/ModelPlayground.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import '@testing-library/jest-dom/vitest';
import { vi, test, expect, beforeEach } from 'vitest';
import { screen, fireEvent, render } from '@testing-library/svelte';
import ModelPlayground from './ModelPlayground.svelte';
import type { ModelInfo } from '@shared/models/IModelInfo';
import type { ModelInfo } from '@shared/src/models/IModelInfo';
import userEvent from '@testing-library/user-event';

const mocks = vi.hoisted(() => {
Expand Down
5 changes: 2 additions & 3 deletions packages/frontend/src/stores/playground-queries.ts
Original file line number Diff line number Diff line change
@@ -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<QueryState[]> = readable<QueryState[]>([], set => {
const sub = rpcBrowser.subscribe(MSG_NEW_PLAYGROUND_QUERIES_STATE, msg => {
Expand Down
11 changes: 0 additions & 11 deletions packages/shared/models/IRecipe.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/shared/src/StudioAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ModelResponse } from "./IModelResponse";
import type { ModelResponse } from './IModelResponse';

export interface QueryState {
id: number;
Expand Down

0 comments on commit e3cdf00

Please sign in to comment.