Skip to content

fix: incorrect intent checking for namespace messages #822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
"${workspaceFolder}/dist/**/*.js"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change allows the debugger to bind breakpoints we put in the typescript files.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet! Nice add.

],
"preLaunchTask": "${defaultBuildTask}"
},
4 changes: 2 additions & 2 deletions src/participant/prompts/history.ts
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ export function getHistoryMessages({
];
if (
responseTypesToSkip.indexOf(
(historyItem.result as ChatResult)?.metadata.intent
(historyItem.result as ChatResult)?.metadata?.intent
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another thing I noticed - not sure if there were cases where it would have manifested, but technically metadata is optional on vscode.ChatResult. Even though we're casting to our ChatResult type, this cast would still succeed if metadata is undefined, making the unconditional access here incorrect.

) > -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,
31 changes: 17 additions & 14 deletions src/participant/prompts/namespace.ts
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where the bug was - askToConnect was replaced with intent, but because this was operating on the vscode.ChatResult.metadata, which is of type any, the compiler didn't complain.

) {
// 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;
}
}
}
}
Loading