Skip to content

Commit

Permalink
Fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
umpox committed Aug 1, 2023
1 parent c399307 commit 137b4d2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 35 deletions.
65 changes: 34 additions & 31 deletions lib/shared/src/intent-detector/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,44 +73,47 @@ export class SourcegraphIntentDetectorClient implements IntentDetector {
): Promise<Intent> {
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<string>(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<string>(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>(.*?)<\/classification>/)?.[1]
if (!responseClassification) {
Expand Down
8 changes: 5 additions & 3 deletions vscode/test/fixtures/mock-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ export async function run<T>(around: () => Promise<T>): Promise<T> {
// 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`)
})

Expand Down
5 changes: 4 additions & 1 deletion vscode/webviews/Recipes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { VSCodeWrapper } from './utils/VSCodeApi'

import styles from './Recipes.module.css'

type ClickableRecipeID = Exclude<RecipeID, 'chat-question' | 'inline-touch' | 'inline-chat' | 'my-prompt' | 'next-questions' | 'non-stop'>
type ClickableRecipeID = Exclude<
RecipeID,
'chat-question' | 'inline-touch' | 'inline-chat' | 'my-prompt' | 'next-questions' | 'non-stop'
>

type RecipeListType = Record<ClickableRecipeID, string>

Expand Down
3 changes: 3 additions & 0 deletions web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const editor: Editor = {
getActiveTextEditorSelectionOrEntireFile() {
return null
},
getActiveTextEditorDiagnosticsForRange() {
return null
},
getActiveTextEditorVisibleContent() {
return null
},
Expand Down

0 comments on commit 137b4d2

Please sign in to comment.