Skip to content

Commit 07e01d4

Browse files
authored
feat(telemetry): improve tracking for docs chatbot VSCODE-660 (#900)
1 parent 07ebbd0 commit 07e01d4

File tree

5 files changed

+47
-20
lines changed

5 files changed

+47
-20
lines changed

src/participant/constants.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
import type * as vscode from 'vscode';
22
import { ChatMetadataStore } from './chatMetadata';
3+
import type { ParticipantResponseType } from './participantTypes';
34

45
export const CHAT_PARTICIPANT_ID = 'mongodb.participant';
56
export const CHAT_PARTICIPANT_MODEL = 'gpt-4o';
67
export const COPILOT_EXTENSION_ID = 'GitHub.copilot';
78
export const COPILOT_CHAT_EXTENSION_ID = 'GitHub.copilot-chat';
89

9-
export type ParticipantResponseType =
10-
| 'query'
11-
| 'schema'
12-
| 'docs'
13-
| 'generic'
14-
| 'emptyRequest'
15-
| 'cancelledRequest'
16-
| 'askToConnect'
17-
| 'askForNamespace';
18-
1910
export const codeBlockIdentifier = {
2011
start: '```javascript',
2112
end: '```',

src/participant/participant.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,22 +1540,23 @@ export default class ParticipantController {
15401540
}
15411541

15421542
async _handleDocsRequestWithChatbot({
1543-
prompt,
1543+
request,
15441544
chatId,
15451545
token,
15461546
stream,
15471547
context,
15481548
}: {
1549-
prompt: string;
15501549
chatId: string;
15511550
token: vscode.CancellationToken;
15521551
context: vscode.ChatContext;
1552+
request: vscode.ChatRequest;
15531553
stream: vscode.ChatResponseStream;
15541554
}): Promise<{
15551555
responseContent: string;
15561556
responseReferences?: Reference[];
15571557
docsChatbotMessageId: string;
15581558
}> {
1559+
const prompt = request.prompt;
15591560
stream.push(
15601561
new vscode.ChatResponseProgressPart('Consulting MongoDB documentation...')
15611562
);
@@ -1597,6 +1598,10 @@ export default class ParticipantController {
15971598
signal: abortController.signal,
15981599
});
15991600

1601+
const stats = Prompts.docs.getStats(history, { request, context });
1602+
1603+
this._telemetryService.trackParticipantPrompt(stats);
1604+
16001605
log.info('Docs chatbot message sent', {
16011606
chatId,
16021607
docsChatbotConversationId,
@@ -1694,7 +1699,7 @@ export default class ParticipantController {
16941699

16951700
try {
16961701
docsResult = await this._handleDocsRequestWithChatbot({
1697-
prompt: request.prompt,
1702+
request,
16981703
chatId,
16991704
token,
17001705
stream,

src/participant/prompts/docs.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { ParticipantPromptProperties } from '../../telemetry/telemetryService';
2+
import type { PromptArgsBase } from './promptBase';
3+
import { PromptBase } from './promptBase';
4+
import type * as vscode from 'vscode';
5+
6+
export class DocsPrompt extends PromptBase<PromptArgsBase> {
7+
protected getAssistantPrompt(): string {
8+
throw new Error('Method not implemented.');
9+
}
10+
11+
public getStats(
12+
messages: vscode.LanguageModelChatMessage[],
13+
{ request, context }: PromptArgsBase
14+
): ParticipantPromptProperties {
15+
return super.getStats(messages, { request, context }, false);
16+
}
17+
}

src/participant/prompts/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import { SchemaPrompt } from './schema';
88
import { ExportToPlaygroundPrompt } from './exportToPlayground';
99
import { ExportToLanguagePrompt } from './exportToLanguage';
1010
import { isContentEmpty } from './promptBase';
11+
import { DocsPrompt } from './docs';
1112

1213
export { getContentLength } from './promptBase';
1314

1415
export class Prompts {
1516
public static generic = new GenericPrompt();
17+
public static docs = new DocsPrompt();
1618
public static intent = new IntentPrompt();
1719
public static namespace = new NamespacePrompt();
1820
public static query = new QueryPrompt();

src/test/suite/participant/participant.test.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ import {
4343
import EditDocumentCodeLensProvider from '../../../editors/editDocumentCodeLensProvider';
4444
import PlaygroundResultProvider from '../../../editors/playgroundResultProvider';
4545
import { CollectionTreeItem, DatabaseTreeItem } from '../../../explorer';
46-
import type { SendMessageToParticipantOptions } from '../../../participant/participantTypes';
46+
import type {
47+
ParticipantRequestType,
48+
SendMessageToParticipantOptions,
49+
} from '../../../participant/participantTypes';
4750
import { DocumentSource } from '../../../documentSource';
4851

4952
// The Copilot's model in not available in tests,
@@ -125,7 +128,7 @@ suite('Participant Controller Test Suite', function () {
125128
);
126129

127130
const assertCommandTelemetry = (
128-
command: string,
131+
command: ParticipantRequestType,
129132
chatRequest: vscode.ChatRequest,
130133
{
131134
expectSampleDocs = false,
@@ -148,10 +151,13 @@ suite('Participant Controller Test Suite', function () {
148151
expect(properties.has_sample_documents).to.equal(expectSampleDocs);
149152
expect(properties.history_size).to.equal(chatContextStub.history.length);
150153

151-
// Total message length includes participant as well as user prompt
152-
expect(properties.total_message_length).to.be.greaterThan(
153-
properties.user_input_length
154-
);
154+
/** For docs chatbot requests, the length of the prompt would be longer as it gets the prompt history prepended.*/
155+
if (command !== 'docs') {
156+
// Total message length includes participant as well as user prompt
157+
expect(properties.total_message_length).to.be.greaterThan(
158+
properties.user_input_length
159+
);
160+
}
155161

156162
// User prompt length should be at least equal to the supplied user prompt, but my occasionally
157163
// be greater - e.g. when we enhance the context.
@@ -1709,8 +1715,14 @@ Schema:
17091715
expect(fetchStub).to.have.been.called;
17101716
expect(sendRequestStub).to.have.not.been.called;
17111717

1712-
assertResponseTelemetry('docs/chatbot', {
1718+
assertCommandTelemetry('docs', chatRequestMock, {
1719+
expectSampleDocs: false,
17131720
callIndex: 0,
1721+
expectedInternalPurpose: undefined,
1722+
});
1723+
1724+
assertResponseTelemetry('docs/chatbot', {
1725+
callIndex: 1,
17141726
});
17151727
});
17161728

0 commit comments

Comments
 (0)