Skip to content

Commit ee9f69c

Browse files
committed
Adding Q Chat metric: totalNumberOfCodeBlocks to telemetry
1 parent 1bdd6ca commit ee9f69c

File tree

5 files changed

+4201
-5
lines changed

5 files changed

+4201
-5
lines changed

package-lock.json

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/src/codewhispererChat/controllers/chat/messenger/messenger.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ export class Messenger {
8888
)
8989
)
9090
}
91+
92+
public countTotalNumberOfCodeBlocks(message: string): number {
93+
if (message === undefined) {
94+
return 0
95+
}
96+
const countOfCodeBlocks = message.match(/^```/gm)
97+
const numberOfTripleBackTicksInMarkdown = countOfCodeBlocks ? countOfCodeBlocks.length : 0
98+
return Math.floor(numberOfTripleBackTicksInMarkdown / 2)
99+
}
100+
91101
public async sendAIResponse(
92102
response: GenerateAssistantResponseCommandOutput,
93103
session: ChatSession,
@@ -264,6 +274,7 @@ export class Messenger {
264274
messageID,
265275
responseCode,
266276
codeReferenceCount: codeReference.length,
277+
totalNumberOfCodeBlocksInResponse: this.countTotalNumberOfCodeBlocks(message),
267278
})
268279
})
269280
}

packages/core/src/codewhispererChat/controllers/chat/model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export interface PromptAnswer {
7676
messageID: string
7777
responseCode: number
7878
codeReferenceCount: number
79+
totalNumberOfCodeBlocksInResponse: number
7980
}
8081

8182
export interface StopResponseMessage {

packages/core/src/codewhispererChat/controllers/chat/telemetryHelper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ export class CWCTelemetryHelper {
321321
cwsprChatProgrammingLanguage: triggerPayload.fileLanguage,
322322
cwsprChatActiveEditorTotalCharacters: triggerPayload.fileText?.length,
323323
cwsprChatActiveEditorImportCount: triggerPayload.codeQuery?.fullyQualifiedNames?.used?.length,
324-
cwsprChatResponseCodeSnippetCount: 0, // TODO
324+
cwsprChatResponseCodeSnippetCount: message.totalNumberOfCodeBlocksInResponse,
325325
cwsprChatResponseCode: message.responseCode,
326326
cwsprChatSourceLinkCount: message.suggestionCount,
327327
cwsprChatReferencesCount: message.codeReferenceCount,

0 commit comments

Comments
 (0)