Skip to content
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

fix(chat): show empty docs msg, schema set msg content correctly VSCODE-628 #851

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
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
30 changes: 21 additions & 9 deletions src/participant/participant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -792,10 +792,12 @@ export default class ParticipantController {
// TODO: Remove this when the issue is fixed.
messagesWithNamespace.messages[
messagesWithNamespace.messages.length - 1
].content =
// eslint-disable-next-line new-cap
] = vscode.LanguageModelChatMessage.User(
messagesWithNamespace.messages[
messagesWithNamespace.messages.length - 1
].content.trim() || 'see previous messages';
].content.trim() || 'see previous messages'
);

const responseContentWithNamespace = await this.getChatResponseContent({
modelInput: messagesWithNamespace,
Expand Down Expand Up @@ -1359,13 +1361,7 @@ export default class ParticipantController {
token,
});

this._streamResponseReference({
reference: {
url: MONGODB_DOCS_LINK,
title: 'View MongoDB documentation',
},
stream,
});
this._streamGenericDocsLink(stream);

this._telemetryService.trackCopilotParticipantResponse({
command: 'docs/copilot',
Expand All @@ -1390,6 +1386,16 @@ export default class ParticipantController {
stream.markdown(link);
}

_streamGenericDocsLink(stream: vscode.ChatResponseStream): void {
this._streamResponseReference({
reference: {
url: MONGODB_DOCS_LINK,
title: 'View MongoDB documentation',
},
stream,
});
}

async handleDocsRequest(
...args: [
vscode.ChatRequest,
Expand All @@ -1400,6 +1406,12 @@ export default class ParticipantController {
): Promise<ChatResult> {
const [request, context, stream, token] = args;

if (Prompts.isPromptEmpty(request)) {
stream.markdown(Prompts.generic.getEmptyRequestResponse());
this._streamGenericDocsLink(stream);
return emptyRequestChatResult(context.history);
}

const chatId = ChatMetadataStore.getChatIdFromHistoryOrNewChatId(
context.history
);
Expand Down
67 changes: 66 additions & 1 deletion src/test/suite/participant/participant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,52 @@ suite('Participant Controller Test Suite', function () {
'What is the name of the database you would like to run against?'
);
});

test('with history, and a blank prompt, it sets a message so it does not cause model error (VSCODE-626)', async function () {
const chatRequestMock = {
prompt: '',
command: 'schema',
references: [],
};
chatContextStub = {
history: [
Object.assign(Object.create(vscode.ChatRequestTurn.prototype), {
prompt:
'how do I make a find request vs favorite_fruits.pineapple?',
command: 'query',
references: [],
participant: CHAT_PARTICIPANT_ID,
}),
Object.assign(
Object.create(vscode.ChatResponseTurn.prototype),
{
participant: CHAT_PARTICIPANT_ID,
response: [
{
value: 'some code',
},
],
command: 'query',
result: {
metadata: {
intent: 'query',
chatId: 'abc',
},
},
}
),
],
};
await invokeChatHandler(chatRequestMock);

expect(sendRequestStub.calledOnce).to.be.true;
expect(sendRequestStub.firstCall.args[0][0].content).to.include(
'Parse all user messages to find a database name and a collection name.'
);
expect(sendRequestStub.firstCall.args[0][3].content).to.include(
'see previous messages'
);
});
});

suite(
Expand Down Expand Up @@ -1549,7 +1595,26 @@ Schema:

afterEach(function () {
global.fetch = initialFetch;
sinon.restore();
});

test('shows a message and docs link on empty prompt', async function () {
fetchStub = sinon.stub().resolves();
global.fetch = fetchStub;
const chatRequestMock = {
prompt: '',
command: 'docs',
references: [],
};
const res = await invokeChatHandler(chatRequestMock);
expect(fetchStub).to.not.have.been.called;
expect(sendRequestStub).to.have.not.been.called;
expect(res?.metadata.intent).to.equal('emptyRequest');
const defaultEmptyMsg = chatStreamStub.markdown.getCall(0).args[0];
expect(defaultEmptyMsg).to.include(
'Ask anything about MongoDB, from writing queries to questions a'
);
const referenceMsg = chatStreamStub.markdown.getCall(1).args[0];
expect(referenceMsg.value).to.include('View MongoDB documentation');
});

test('uses docs chatbot result if available', async function () {
Expand Down
Loading