Skip to content

Commit

Permalink
Adding Language to user events
Browse files Browse the repository at this point in the history
  • Loading branch information
laileni-aws committed Oct 10, 2024
1 parent 9f0d6ec commit a2c4257
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ export class Messenger {
chatEvent.assistantResponseEvent.content.length > 0
) {
message += chatEvent.assistantResponseEvent.content
codeBlockLanguage = this.extractCodeBlockLanguage(message)
if (codeBlockLanguage === 'plaintext') {
codeBlockLanguage = this.extractCodeBlockLanguage(message)
}
this.dispatcher.sendChatMessage(
new ChatMessage(
{
Expand Down Expand Up @@ -341,9 +343,21 @@ export class Messenger {
}

private extractCodeBlockLanguage(message: string): string {
const firstLine = message.split('\n')[0]
const match = firstLine.match(/^```(\w+)/)
return match ? match[1] : 'plaintext'
// This fulfills both the cases of unit test generation(java, python) and general use case(Non java and Non python) languages.
const codeBlockStart = message.indexOf('```')
if (codeBlockStart === -1) {
return 'plaintext'
}

const languageStart = codeBlockStart + 3
const languageEnd = message.indexOf('\n', languageStart)

if (languageEnd === -1) {
return 'plaintext'
}

const language = message.substring(languageStart, languageEnd).trim()
return language !== '' ? language : 'plaintext'
}

public sendErrorMessage(errorMessage: string | undefined, tabID: string, requestID: string | undefined) {
Expand Down

0 comments on commit a2c4257

Please sign in to comment.