Skip to content

Commit 9f2fde8

Browse files
authored
fix(amazonq): Improve responses for saved prompts, workspace rules aws#6805
## Problem The system prompt for saved prompts and workspace rules is too vague, users reporting they are sometimes ignored entirely. ## Solution Add system prompt for saved prompt and workspace rules to improve quality of responses
1 parent 3b7082a commit 9f2fde8

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Amazon Q chat: Improve responses for saved prompts and workspace rules"
4+
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -980,9 +980,15 @@ export class ChatController {
980980
if (Array.isArray(prompts) && prompts.length > 0) {
981981
triggerPayload.additionalContextLengths = this.telemetryHelper.getContextLengths(prompts)
982982
for (const prompt of prompts.slice(0, 20)) {
983+
// Add system prompt for user prompts and workspace rules
984+
const contextType = this.telemetryHelper.getContextType(prompt)
985+
const description =
986+
contextType === 'rule' || contextType === 'prompt'
987+
? `You must follow the instructions in ${prompt.relativePath}. Below are lines ${prompt.startLine}-${prompt.endLine} of this file:\n`
988+
: prompt.description
983989
const entry = {
984990
name: prompt.name.substring(0, aditionalContentNameLimit),
985-
description: prompt.description.substring(0, aditionalContentNameLimit),
991+
description: description.substring(0, aditionalContentNameLimit),
986992
innerContext: prompt.content.substring(0, additionalContentInnerContextLimit),
987993
}
988994
// make sure the relevantDocument + additionalContext
@@ -994,7 +1000,6 @@ export class ChatController {
9941000
break
9951001
}
9961002

997-
const contextType = this.telemetryHelper.getContextType(prompt)
9981003
if (contextType === 'rule') {
9991004
triggerPayload.truncatedAdditionalContextLengths.ruleContextLength += entry.innerContext.length
10001005
} else if (contextType === 'prompt') {

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ import { AuthUtil } from '../../../codewhisperer/util/authUtil'
4242
import { getSelectedCustomization } from '../../../codewhisperer/util/customizationUtil'
4343
import { undefinedIfEmpty } from '../../../shared/utilities/textUtilities'
4444
import { AdditionalContextPrompt } from '../../../amazonq/lsp/types'
45-
import { getUserPromptsDirectory } from '../../constants'
45+
import { getUserPromptsDirectory, promptFileExtension } from '../../constants'
46+
import { isInDirectory } from '../../../shared/filesystemUtilities'
4647

4748
export function logSendTelemetryEventFailure(error: any) {
4849
let requestId: string | undefined
@@ -148,13 +149,14 @@ export class CWCTelemetryHelper {
148149
}
149150

150151
public getContextType(prompt: AdditionalContextPrompt): string {
151-
if (prompt.relativePath.startsWith(path.join('.amazonq', 'rules'))) {
152-
return 'rule'
153-
} else if (prompt.filePath.startsWith(getUserPromptsDirectory())) {
154-
return 'prompt'
155-
} else {
156-
return 'file'
152+
if (prompt.filePath.endsWith(promptFileExtension)) {
153+
if (isInDirectory(path.join('.amazonq', 'rules'), prompt.relativePath)) {
154+
return 'rule'
155+
} else if (isInDirectory(getUserPromptsDirectory(), prompt.filePath)) {
156+
return 'prompt'
157+
}
157158
}
159+
return 'file'
158160
}
159161

160162
public getContextLengths(prompts: AdditionalContextPrompt[]): AdditionalContextLengths {

0 commit comments

Comments
 (0)