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

Simple chat: Bring back chat telemetry #2291

Merged
merged 4 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ This is a log of all notable changes to Cody for VS Code. [Unreleased] changes a
### Fixed

- Fixes an issue where the sidebar would not properly load when not signed in. [pull/2267](https://github.com/sourcegraph/cody/pull/2267)
- Fixes an issue where telemetry events were not properly logged with the new chat experience. [pull/2291](https://github.com/sourcegraph/cody/pull/2291)

### Changed

Expand Down
2 changes: 2 additions & 0 deletions vscode/src/chat/chat-view/SimpleChatModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { TranscriptJSON } from '@sourcegraph/cody-shared/src/chat/transcript'
import { InteractionJSON } from '@sourcegraph/cody-shared/src/chat/transcript/interaction'
import { errorToChatError, InteractionMessage } from '@sourcegraph/cody-shared/src/chat/transcript/messages'
import { reformatBotMessageForChat } from '@sourcegraph/cody-shared/src/chat/viewHelpers'
import { ContextFileSource } from '@sourcegraph/cody-shared/src/codebase-context/messages'
import { Message } from '@sourcegraph/cody-shared/src/sourcegraph-api'

import { contextItemsToContextFiles } from './chat-helpers'
Expand Down Expand Up @@ -166,6 +167,7 @@ export interface ContextItem {
uri: vscode.Uri
range?: vscode.Range
text: string
source?: ContextFileSource
}

export function contextItemId(contextItem: ContextItem): string {
Expand Down
47 changes: 43 additions & 4 deletions vscode/src/chat/chat-view/SimpleChatPanelProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,12 @@ export class SimpleChatPanelProvider implements vscode.Disposable, IChatPanelPro
await this.saveSession(text)
// trigger the context progress indicator
this.postViewTranscript({ speaker: 'assistant' })
await this.generateAssistantResponse(requestID, userContextFiles, addEnhancedContext)
await this.generateAssistantResponse(
requestID,
userContextFiles,
addEnhancedContext,
submitType === 'user' ? text : undefined
)
// Set the title of the webview panel to the current text
if (this.webviewPanel) {
this.webviewPanel.title = this.history.getChat(this.sessionID)?.chatTitle || getChatPanelTitle(text)
Expand Down Expand Up @@ -536,7 +541,8 @@ export class SimpleChatPanelProvider implements vscode.Disposable, IChatPanelPro
private async generateAssistantResponse(
requestID: string,
userContextFiles?: ContextFile[],
addEnhancedContext = true
addEnhancedContext = true,
userPrompt: string | undefined = undefined
philipp-spiess marked this conversation as resolved.
Show resolved Hide resolved
): Promise<void> {
try {
const contextWindowBytes = 28000 // 7000 tokens * 4 bytes per token
Expand Down Expand Up @@ -565,6 +571,35 @@ export class SimpleChatPanelProvider implements vscode.Disposable, IChatPanelPro
this.postError(new Error(warningMsg))
}

if (userPrompt) {
// Create a summary of how many code snippets of each context source are being
// included in the prompt
const contextSummary: { [key: string]: number } = {}
for (const { source } of newContextUsed) {
if (!source) {
continue
}
if (contextSummary[source]) {
contextSummary[source] += 1
} else {
contextSummary[source] = 1
}
}

const properties = {
requestID,
chatModel: this.chatModel.modelID,
promptText: userPrompt,
contextSummary,
}
telemetryService.log('CodyVSCodeExtension:recipe:chat-question:executed', properties, {
hasV2Event: true,
})
telemetryRecorder.recordEvent('cody.recipe.chat-question', 'executed', {
metadata: { ...contextSummary },
})
}

this.postViewTranscript({ speaker: 'assistant' })

this.sendLLMRequest(prompt, {
Expand Down Expand Up @@ -1059,7 +1094,7 @@ class ContextProvider implements IContextProvider {
return []
}
logDebug('SimpleChatPanelProvider', 'getEnhancedContext > searching local embeddings')
const contextItems = []
const contextItems: ContextItem[] = []
const embeddingsResults = await this.localEmbeddings.getContext(text, NUM_CODE_RESULTS + NUM_TEXT_RESULTS)
for (const result of embeddingsResults) {
const uri = vscode.Uri.from({
Expand All @@ -1075,6 +1110,7 @@ class ContextProvider implements IContextProvider {
uri,
range,
text: result.content,
source: 'embeddings',
})
}
return contextItems
Expand All @@ -1097,7 +1133,7 @@ class ContextProvider implements IContextProvider {
}

logDebug('SimpleChatPanelProvider', 'getEnhancedContext > searching remote embeddings')
const contextItems = []
const contextItems: ContextItem[] = []
const embeddings = await this.embeddingsClient.search([repoId], text, NUM_CODE_RESULTS, NUM_TEXT_RESULTS)
if (isError(embeddings)) {
throw new Error(`Error retrieving embeddings: ${embeddings}`)
Expand All @@ -1118,6 +1154,7 @@ class ContextProvider implements IContextProvider {
uri,
range,
text: codeResult.content,
source: 'embeddings',
})
}

Expand All @@ -1135,6 +1172,7 @@ class ContextProvider implements IContextProvider {
uri,
range,
text: textResult.content,
source: 'embeddings',
})
}

Expand Down Expand Up @@ -1324,6 +1362,7 @@ export function deserializedContextFilesToContextItems(
uri,
range,
text: text || '',
source: file.source,
}
})
}
Expand Down
1 change: 1 addition & 0 deletions vscode/src/chat/chat-view/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export class DefaultPrompter implements IPrompter {
(item: ContextItem) => this.renderContextItem(item)
)
newContextUsed.push(...used)

philipp-spiess marked this conversation as resolved.
Show resolved Hide resolved
if (limitReached) {
warnings.push('Ignored current user-specified context items due to context limit')
return { prompt: promptBuilder.build(), warnings, newContextUsed }
Expand Down
Loading