Skip to content

Commit 9d2ee26

Browse files
committed
fix(amazonq): improve system prompts for rules
1 parent 131005d commit 9d2ee26

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-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+
let description = prompt.description
984+
// Add system prompt for user prompts and workspace rules
985+
const contextType = this.telemetryHelper.getContextType(prompt)
986+
if (contextType === 'rule' || contextType === 'prompt') {
987+
description = `You must follow the instructions in ${prompt.relativePath}. Below are lines ${prompt.startLine}-${prompt.endLine} of this file:\n`
988+
}
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: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ 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'
4646

4747
export function logSendTelemetryEventFailure(error: any) {
4848
let requestId: string | undefined
@@ -148,13 +148,14 @@ export class CWCTelemetryHelper {
148148
}
149149

150150
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'
151+
if (prompt.filePath.endsWith(promptFileExtension)) {
152+
if (prompt.relativePath.startsWith(path.join('.amazonq', 'rules'))) {
153+
return 'rule'
154+
} else if (prompt.filePath.startsWith(getUserPromptsDirectory())) {
155+
return 'prompt'
156+
}
157157
}
158+
return 'file'
158159
}
159160

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

0 commit comments

Comments
 (0)