File tree Expand file tree Collapse file tree 3 files changed +20
-9
lines changed
amazonq/.changes/next-release
core/src/codewhispererChat/controllers/chat Expand file tree Collapse file tree 3 files changed +20
-9
lines changed Original file line number Diff line number Diff line change 1+ {
2+ "type" : " Bug Fix" ,
3+ "description" : " Amazon Q chat: Improve responses for saved prompts and workspace rules"
4+ }
Original file line number Diff line number Diff 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' ) {
Original file line number Diff line number Diff line change @@ -42,7 +42,8 @@ import { AuthUtil } from '../../../codewhisperer/util/authUtil'
4242import { getSelectedCustomization } from '../../../codewhisperer/util/customizationUtil'
4343import { undefinedIfEmpty } from '../../../shared/utilities/textUtilities'
4444import { AdditionalContextPrompt } from '../../../amazonq/lsp/types'
45- import { getUserPromptsDirectory } from '../../constants'
45+ import { getUserPromptsDirectory , promptFileExtension } from '../../constants'
46+ import { isInDirectory } from '../../../shared/filesystemUtilities'
4647
4748export 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 {
You can’t perform that action at this time.
0 commit comments