From 137b4d23781ee4f3f71d19ca0ea8f1ec196e0b91 Mon Sep 17 00:00:00 2001 From: Tom Ross Date: Tue, 1 Aug 2023 09:49:03 +0100 Subject: [PATCH] Fix error --- lib/shared/src/intent-detector/client.ts | 65 +++++++++++++----------- vscode/test/fixtures/mock-server.ts | 8 +-- vscode/webviews/Recipes.tsx | 5 +- web/src/App.tsx | 3 ++ 4 files changed, 46 insertions(+), 35 deletions(-) diff --git a/lib/shared/src/intent-detector/client.ts b/lib/shared/src/intent-detector/client.ts index 3b3d02c05c79..3543b669c999 100644 --- a/lib/shared/src/intent-detector/client.ts +++ b/lib/shared/src/intent-detector/client.ts @@ -73,44 +73,47 @@ export class SourcegraphIntentDetectorClient implements IntentDetector { ): Promise { const completionsClient = this.completionsClient if (!completionsClient) { - return fallback; + return fallback } const preamble = this.buildInitialTranscript(options) const examples = this.buildExampleTranscript(options) - const result = await new Promise(resolve => { - let responseText = ''; - return completionsClient.stream({ - fast: true, - temperature: 0, - maxTokensToSample: ANSWER_TOKENS, - topK: -1, - topP: -1, - messages: [ - ...preamble, - ...examples, - { - speaker: 'human', - text: input, + const result = await new Promise(resolve => { + let responseText = '' + return completionsClient.stream( + { + fast: true, + temperature: 0, + maxTokensToSample: ANSWER_TOKENS, + topK: -1, + topP: -1, + messages: [ + ...preamble, + ...examples, + { + speaker: 'human', + text: input, + }, + { + speaker: 'assistant', + }, + ], + }, + { + onChange: (text: string) => { + responseText = text }, - { - speaker: 'assistant', + onComplete: () => { + resolve(responseText) }, - ], - }, { - onChange: (text: string) => { - responseText = text - }, - onComplete: () => { - resolve(responseText) - }, - onError: (message: string, statusCode?: number) => { - console.error(`Error detecting intent: Status code ${statusCode}: ${message}`); - resolve(fallback) - }, - }) - }) + onError: (message: string, statusCode?: number) => { + console.error(`Error detecting intent: Status code ${statusCode}: ${message}`) + resolve(fallback) + }, + } + ) + }) const responseClassification = result.match(/(.*?)<\/classification>/)?.[1] if (!responseClassification) { diff --git a/vscode/test/fixtures/mock-server.ts b/vscode/test/fixtures/mock-server.ts index c2e3aca466d8..db2d65afa55d 100644 --- a/vscode/test/fixtures/mock-server.ts +++ b/vscode/test/fixtures/mock-server.ts @@ -37,9 +37,11 @@ export async function run(around: () => Promise): Promise { // or have a method on the server to send a set response the next time it sees a trigger word in the request. const request = req as MockRequest const lastHumanMessageIndex = request.body.messages.length - 2 - const response = request.body.messages[lastHumanMessageIndex].text.includes(FIXUP_PROMPT_TAG) || request.body.messages[lastHumanMessageIndex].text.includes(NON_STOP_FIXUP_PROMPT_TAG) - ? responses.fixup - : responses.chat + const response = + request.body.messages[lastHumanMessageIndex].text.includes(FIXUP_PROMPT_TAG) || + request.body.messages[lastHumanMessageIndex].text.includes(NON_STOP_FIXUP_PROMPT_TAG) + ? responses.fixup + : responses.chat res.send(`event: completion\ndata: {"completion": ${JSON.stringify(response)}}\n\nevent: done\ndata: {}\n\n`) }) diff --git a/vscode/webviews/Recipes.tsx b/vscode/webviews/Recipes.tsx index afb18e3ca994..4430597b5745 100644 --- a/vscode/webviews/Recipes.tsx +++ b/vscode/webviews/Recipes.tsx @@ -9,7 +9,10 @@ import { VSCodeWrapper } from './utils/VSCodeApi' import styles from './Recipes.module.css' -type ClickableRecipeID = Exclude +type ClickableRecipeID = Exclude< + RecipeID, + 'chat-question' | 'inline-touch' | 'inline-chat' | 'my-prompt' | 'next-questions' | 'non-stop' +> type RecipeListType = Record diff --git a/web/src/App.tsx b/web/src/App.tsx index 53a16c6d84ee..669b1088e3cf 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -23,6 +23,9 @@ const editor: Editor = { getActiveTextEditorSelectionOrEntireFile() { return null }, + getActiveTextEditorDiagnosticsForRange() { + return null + }, getActiveTextEditorVisibleContent() { return null },