Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit081d4c2

Browse files
authored
refactor(prompts)!: support template substitution in system_prompt (#1312)
Refactor prompt configuration to allow template substitution insystem_prompt strings using curly braces (e.g. {COPILOT_BASE}). Thisenables more flexible and composable prompt definitions. Also updatecallback signature to use the full response object. Update README toreflect new prompt usage.BREAKING CHANGE: callback receives the full response object instead of just content.
1 parentf22747a commit081d4c2

File tree

4 files changed

+39
-44
lines changed

4 files changed

+39
-44
lines changed

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ Define your own prompts in the configuration:
292292
system_prompt='You are fascinated by pirates, so please respond in pirate speak.',
293293
},
294294
NiceInstructions= {
295-
system_prompt='You are a nice coding tutor, so please respond in a friendly and helpful manner.'..require('CopilotChat.config.prompts').COPILOT_BASE.system_prompt,
295+
system_prompt='You are a nice coding tutor, so please respond in a friendly and helpful manner. {BASE_INSTRUCTIONS}',
296296
}
297297
}
298298
}

‎lua/CopilotChat/config.lua‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
---@fieldlanguagestring?
2222
---@fieldtemperaturenumber?
2323
---@fieldheadlessboolean?
24-
---@fieldcallbacknil|fun(response:string,source:CopilotChat.source)
24+
---@fieldcallbacknil|fun(response:CopilotChat.client.Message,source:CopilotChat.source)
2525
---@fieldremember_as_stickyboolean?
2626
---@fieldselectionfalse|nil|fun(source:CopilotChat.source):CopilotChat.select.Selection?
2727
---@fieldwindowCopilotChat.config.Window?

‎lua/CopilotChat/config/prompts.lua‎

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
localCOPILOT_BASE=[[
1+
---@classCopilotChat.config.prompts.Prompt:CopilotChat.config.Shared
2+
---@fieldpromptstring?
3+
---@fielddescriptionstring?
4+
---@fieldmappingstring?
5+
6+
---@typetable<string,CopilotChat.config.prompts.Prompt>
7+
return {
8+
COPILOT_BASE= {
9+
system_prompt=[[
210
When asked for your name, you must respond with "GitHub Copilot".
311
Follow the user's requirements carefully & to the letter.
412
Keep your answers short and impersonal.
@@ -72,15 +80,20 @@ When presenting code changes:
7280
4. Address any diagnostics issues when fixing code.
7381
5. If multiple changes are needed, present them as separate code blocks.
7482
</editFileInstructions>
75-
]]
83+
]],
84+
},
7685

77-
localCOPILOT_INSTRUCTIONS=[[
86+
COPILOT_INSTRUCTIONS= {
87+
system_prompt=[[
7888
You are a code-focused AI programming assistant that specializes in practical software engineering solutions.
79-
]]..COPILOT_BASE
8089
81-
localCOPILOT_EXPLAIN=[[
90+
{COPILOT_BASE}
91+
]],
92+
},
93+
94+
COPILOT_EXPLAIN= {
95+
system_prompt=[[
8296
You are a programming instructor focused on clear, practical explanations.
83-
]]..COPILOT_BASE..[[
8497
8598
When explaining code:
8699
- Provide concise high-level overview first
@@ -90,11 +103,16 @@ When explaining code:
90103
- Focus on complex parts rather than basic syntax
91104
- Use short paragraphs with clear structure
92105
- Mention performance considerations where relevant
93-
]]
94106
95-
localCOPILOT_REVIEW=[[
107+
{COPILOT_BASE}
108+
]],
109+
},
110+
111+
COPILOT_REVIEW= {
112+
system_prompt=[[
96113
You are a code reviewer focused on improving code quality and maintainability.
97-
]]..COPILOT_BASE..[[
114+
115+
{COPILOT_BASE}
98116
99117
Format each issue you find precisely as:
100118
line=<line_number>: <issue_description>
@@ -117,39 +135,17 @@ Multiple issues on one line should be separated by semicolons.
117135
End with: "**`To clear buffer highlights, please ask a different question.`**"
118136
119137
If no issues found, confirm the code is well-written and explain why.
120-
]]
121-
122-
---@classCopilotChat.config.prompts.Prompt:CopilotChat.config.Shared
123-
---@fieldpromptstring?
124-
---@fielddescriptionstring?
125-
---@fieldmappingstring?
126-
127-
---@typetable<string,CopilotChat.config.prompts.Prompt>
128-
return {
129-
COPILOT_BASE= {
130-
system_prompt=COPILOT_BASE,
131-
},
132-
133-
COPILOT_INSTRUCTIONS= {
134-
system_prompt=COPILOT_INSTRUCTIONS,
135-
},
136-
137-
COPILOT_EXPLAIN= {
138-
system_prompt=COPILOT_EXPLAIN,
139-
},
140-
141-
COPILOT_REVIEW= {
142-
system_prompt=COPILOT_REVIEW,
138+
]],
143139
},
144140

145141
Explain= {
146142
prompt='Write an explanation for the selected code as paragraphs of text.',
147-
system_prompt='COPILOT_EXPLAIN',
143+
system_prompt='{COPILOT_EXPLAIN}',
148144
},
149145

150146
Review= {
151147
prompt='Review the selected code.',
152-
system_prompt='COPILOT_REVIEW',
148+
system_prompt='{COPILOT_REVIEW}',
153149
callback=function(response,source)
154150
localdiagnostics= {}
155151
forlineinresponse:gmatch('[^\r\n]+')do

‎lua/CopilotChat/init.lua‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,6 @@ local function list_prompts()
183183
}
184184
end
185185

186-
ifval.system_promptandM.config.prompts[val.system_prompt]then
187-
val.system_prompt=M.config.prompts[val.system_prompt].system_prompt
188-
end
189-
190186
prompts_to_use[name]=val
191187
end
192188

@@ -506,11 +502,14 @@ function M.resolve_prompt(prompt, config)
506502

507503
config=vim.tbl_deep_extend('force',M.config,configor {})
508504
config,prompt=resolve(config,promptor'')
509-
ifprompts_to_use[config.system_prompt]then
510-
config.system_prompt=prompts_to_use[config.system_prompt].system_prompt
511-
end
512505

513506
ifconfig.system_promptthen
507+
forname,promptinpairs(prompts_to_use)do
508+
ifprompt.system_promptthen
509+
config.system_prompt=config.system_prompt:gsub('{'..name..'}',prompt.system_prompt)
510+
end
511+
end
512+
514513
config.system_prompt=config.system_prompt:gsub('{OS_NAME}',jit.os)
515514
config.system_prompt=config.system_prompt:gsub('{LANGUAGE}',config.language)
516515
ifstate.sourcethen
@@ -894,7 +893,7 @@ function M.ask(prompt, config)
894893
-- Call the callback function
895894
ifconfig.callbackthen
896895
utils.schedule_main()
897-
config.callback(response.content,state.source)
896+
config.callback(response,state.source)
898897
end
899898

900899
ifnotconfig.headlessthen

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp