Skip to content

Commit

Permalink
run completions.create async
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed Mar 20, 2024
1 parent 2d6e1a5 commit 3098934
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/backend/src/managers/playgroundV2Manager.spec.ts
Expand Up @@ -182,15 +182,15 @@ test('valid submit should create IPlaygroundMessage and notify the webview', asy
id: expect.anything(),
options: undefined,
role: 'user',
timestamp: date.getTime(),
timestamp: expect.any(Number),
});
expect(conversations[0].messages[1]).toStrictEqual({
choices: undefined,
completed: expect.any(Number),
content: '',
id: expect.anything(),
role: 'assistant',
timestamp: date.getTime(),
timestamp: expect.any(Number),
});

expect(webviewMock.postMessage).toHaveBeenLastCalledWith({
Expand Down
26 changes: 16 additions & 10 deletions packages/backend/src/managers/playgroundV2Manager.ts
Expand Up @@ -126,16 +126,22 @@ export class PlaygroundV2Manager extends Publisher<PlaygroundV2[]> implements Di
if (systemPrompt) {
messages.push({ role: 'system', content: systemPrompt });
}
const response = await client.chat.completions.create({
messages,
stream: true,
model: modelInfo.file.file,
...options,
});
// process stream async
this.processStream(playground.id, response).catch((err: unknown) => {
console.error('Something went wrong while processing stream', err);
});
client.chat.completions
.create({
messages,
stream: true,
model: modelInfo.file.file,
...options,
})
.then(response => {
// process stream async
this.processStream(playground.id, response).catch((err: unknown) => {
console.error('Something went wrong while processing stream', err);
});
})
.catch((err: unknown) => {
console.error('Something went wrong while creating model reponse', err);
});
}

/**
Expand Down

0 comments on commit 3098934

Please sign in to comment.