Skip to content

Commit b5db053

Browse files
committed
feat: add temperature option
1 parent ca6f4dd commit b5db053

4 files changed

Lines changed: 13 additions & 5 deletions

File tree

lua/CopilotChat/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ M.setup = function(options)
2424
vim.g.copilot_chat_hide_system_prompt = options and options.hide_system_prompt or 'yes'
2525
vim.g.copilot_chat_proxy = options and options.proxy or ''
2626
vim.g.copilot_chat_language = options and options.language or ''
27+
vim.g.copilot_chat_temperature = options and options.temperature or ''
2728
local debug = options and options.debug or false
2829
_COPILOT_CHAT_GLOBAL_CONFIG.debug = debug
2930

rplugin/python3/CopilotChat/copilot.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def ask(
100100
code: str,
101101
language: str = "",
102102
model: str = "gpt-4",
103+
temperature: float = 0.1,
103104
):
104105
if not self.token:
105106
self.authenticate()
@@ -112,7 +113,7 @@ def ask(
112113
url = "https://api.githubcopilot.com/chat/completions"
113114
self.chat_history.append(typings.Message(prompt, "user"))
114115
data = utilities.generate_request(
115-
self.chat_history, code, language, system_prompt=system_prompt, model=model
116+
self.chat_history, code, language, system_prompt=system_prompt, model=model, temperature=temperature
116117
)
117118

118119
full_response = ""

rplugin/python3/CopilotChat/handlers/chat_handler.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ def chat(
4444
disable_separators = (
4545
self.nvim.eval("g:copilot_chat_disable_separators") == "yes"
4646
)
47+
temperature = self.nvim.eval("g:copilot_chat_temperature")
48+
if temperature is None:
49+
temperature = 0.1
50+
else:
51+
temperature = float(temperature)
4752
self.proxy = self.nvim.eval("g:copilot_chat_proxy")
4853
if "://" not in self.proxy:
4954
self.proxy = None
@@ -62,7 +67,7 @@ def chat(
6267
system_prompt, prompt, code, filetype, winnr, disable_separators
6368
)
6469

65-
self._add_chat_messages(system_prompt, prompt, code, filetype, model)
70+
self._add_chat_messages(system_prompt, prompt, code, filetype, model,temperature=temperature)
6671

6772
# Stop the spinner
6873
self.nvim.exec_lua('require("CopilotChat.spinner").hide()')
@@ -226,7 +231,7 @@ def _add_folds(
226231
self.nvim.command(full_command)
227232

228233
def _add_chat_messages(
229-
self, system_prompt: str, prompt: str, code: str, file_type: str, model: str
234+
self, system_prompt: str, prompt: str, code: str, file_type: str, model: str, temperature: float = 0.1
230235
):
231236
if self.copilot is None:
232237
self.copilot = Copilot(proxy=self.proxy)
@@ -268,7 +273,7 @@ def _add_chat_messages(
268273
)
269274
# TODO: Abort request if the user closes the layout
270275
for token in self.copilot.ask(
271-
system_prompt, prompt, code, language=cast(str, file_type), model=model
276+
system_prompt, prompt, code, language=cast(str, file_type), model=model, temperature=temperature
272277
):
273278
self.nvim.exec_lua(
274279
'require("CopilotChat.utils").log_info(...)', f"Token: {token}"

rplugin/python3/CopilotChat/utilities.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def generate_request(
1616
language: str = "",
1717
system_prompt=prompts.COPILOT_INSTRUCTIONS,
1818
model="gpt-4",
19+
temperature=0.1,
1920
):
2021
messages = [
2122
{
@@ -43,7 +44,7 @@ def generate_request(
4344
"model": model,
4445
"n": 1,
4546
"stream": True,
46-
"temperature": 0.1, # TODO: add temperature setting, refer the suggestion from user https://discord.com/channels/1200633211236122665/1209114805147926538/1209189717791477870
47+
"temperature": temperature,
4748
"top_p": 1,
4849
"messages": messages,
4950
}

0 commit comments

Comments
 (0)