From 31266435d8cb22f08a4dfa406fa3798d22e7fbf6 Mon Sep 17 00:00:00 2001 From: Nikola Irinchev Date: Thu, 19 Sep 2024 20:56:45 +0200 Subject: [PATCH] Fix incorrect intent checking for namespace messages --- .vscode/launch.json | 2 +- src/participant/prompts/history.ts | 4 ++-- src/participant/prompts/namespace.ts | 31 +++++++++++++++------------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 2ca2ae136..e7f6ca212 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -14,7 +14,7 @@ "--extensionDevelopmentPath=${workspaceFolder}" ], "outFiles": [ - "${workspaceFolder}/out/**/*.js" + "${workspaceFolder}/dist/**/*.js" ], "preLaunchTask": "${defaultBuildTask}" }, diff --git a/src/participant/prompts/history.ts b/src/participant/prompts/history.ts index d14ded4bd..58223876e 100644 --- a/src/participant/prompts/history.ts +++ b/src/participant/prompts/history.ts @@ -39,7 +39,7 @@ export function getHistoryMessages({ ]; if ( responseTypesToSkip.indexOf( - (historyItem.result as ChatResult)?.metadata.intent + (historyItem.result as ChatResult)?.metadata?.intent ) > -1 ) { continue; @@ -50,7 +50,7 @@ export function getHistoryMessages({ message += fragment.value.value; if ( - (historyItem.result as ChatResult)?.metadata.intent === + (historyItem.result as ChatResult)?.metadata?.intent === 'askForNamespace' ) { // When the message is the assistant asking for part of a namespace, diff --git a/src/participant/prompts/namespace.ts b/src/participant/prompts/namespace.ts index f311d5c2b..787517aa2 100644 --- a/src/participant/prompts/namespace.ts +++ b/src/participant/prompts/namespace.ts @@ -1,6 +1,7 @@ import * as vscode from 'vscode'; import { getHistoryMessages } from './history'; +import type { ChatResult } from '../constants'; export const DB_NAME_ID = 'DATABASE_NAME'; export const COL_NAME_ID = 'COLLECTION_NAME'; @@ -64,20 +65,22 @@ No names found. // message was to connect. We want to use the last // message they sent before the connection name as their prompt. let userPrompt = request.prompt; - if ( - connectionNames.includes(request.prompt) && - (context.history[context.history.length - 1] as vscode.ChatResponseTurn) - ?.result?.metadata?.askToConnect - ) { - // Go through the history in reverse order to find the last user message. - for (let i = historyMessages.length - 1; i >= 0; i--) { - if ( - historyMessages[i].role === vscode.LanguageModelChatMessageRole.User - ) { - userPrompt = historyMessages[i].content; - // Remove the item from the history messages array. - historyMessages = historyMessages.slice(0, i); - break; + if (connectionNames.includes(request.prompt)) { + const previousResponse = context.history[ + context.history.length - 1 + ] as vscode.ChatResponseTurn; + const intent = (previousResponse?.result as ChatResult).metadata.intent; + if (intent === 'askToConnect') { + // Go through the history in reverse order to find the last user message. + for (let i = historyMessages.length - 1; i >= 0; i--) { + if ( + historyMessages[i].role === vscode.LanguageModelChatMessageRole.User + ) { + userPrompt = historyMessages[i].content; + // Remove the item from the history messages array. + historyMessages = historyMessages.slice(0, i); + break; + } } } }