Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Bug Fix",
"description": "Amazon Q chat: Improve responses for saved prompts and workspace rules"
}
Original file line number Diff line number Diff line change
Expand Up @@ -980,9 +980,15 @@ export class ChatController {
if (Array.isArray(prompts) && prompts.length > 0) {
triggerPayload.additionalContextLengths = this.telemetryHelper.getContextLengths(prompts)
for (const prompt of prompts.slice(0, 20)) {
// Add system prompt for user prompts and workspace rules
const contextType = this.telemetryHelper.getContextType(prompt)
const description =
contextType === 'rule' || contextType === 'prompt'
? `You must follow the instructions in ${prompt.relativePath}. Below are lines ${prompt.startLine}-${prompt.endLine} of this file:\n`
: prompt.description
const entry = {
name: prompt.name.substring(0, aditionalContentNameLimit),
description: prompt.description.substring(0, aditionalContentNameLimit),
description: description.substring(0, aditionalContentNameLimit),
innerContext: prompt.content.substring(0, additionalContentInnerContextLimit),
}
// make sure the relevantDocument + additionalContext
Expand All @@ -994,7 +1000,6 @@ export class ChatController {
break
}

const contextType = this.telemetryHelper.getContextType(prompt)
if (contextType === 'rule') {
triggerPayload.truncatedAdditionalContextLengths.ruleContextLength += entry.innerContext.length
} else if (contextType === 'prompt') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ import { AuthUtil } from '../../../codewhisperer/util/authUtil'
import { getSelectedCustomization } from '../../../codewhisperer/util/customizationUtil'
import { undefinedIfEmpty } from '../../../shared/utilities/textUtilities'
import { AdditionalContextPrompt } from '../../../amazonq/lsp/types'
import { getUserPromptsDirectory } from '../../constants'
import { getUserPromptsDirectory, promptFileExtension } from '../../constants'
import { isInDirectory } from '../../../shared/filesystemUtilities'

export function logSendTelemetryEventFailure(error: any) {
let requestId: string | undefined
Expand Down Expand Up @@ -148,13 +149,14 @@ export class CWCTelemetryHelper {
}

public getContextType(prompt: AdditionalContextPrompt): string {
if (prompt.relativePath.startsWith(path.join('.amazonq', 'rules'))) {
return 'rule'
} else if (prompt.filePath.startsWith(getUserPromptsDirectory())) {
return 'prompt'
} else {
return 'file'
if (prompt.filePath.endsWith(promptFileExtension)) {
if (isInDirectory(path.join('.amazonq', 'rules'), prompt.relativePath)) {
return 'rule'
} else if (isInDirectory(getUserPromptsDirectory(), prompt.filePath)) {
return 'prompt'
}
}
return 'file'
}

public getContextLengths(prompts: AdditionalContextPrompt[]): AdditionalContextLengths {
Expand Down
Loading