From 8ff6db68eb00f739546db9954e8910f9c6c683e7 Mon Sep 17 00:00:00 2001 From: Huynh Duc Dung Date: Wed, 21 Feb 2024 04:11:02 +0800 Subject: [PATCH 1/3] fix: set default temperature and validate temperature value --- lua/CopilotChat/init.lua | 4 +- .../CopilotChat/handlers/chat_handler.py | 37 ++++++++++++++----- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/lua/CopilotChat/init.lua b/lua/CopilotChat/init.lua index 01fcdadf..bba15a1e 100644 --- a/lua/CopilotChat/init.lua +++ b/lua/CopilotChat/init.lua @@ -16,7 +16,7 @@ _COPILOT_CHAT_GLOBAL_CONFIG = {} -- - hide_system_prompt: ('yes' | 'no') default: 'yes'. -- - proxy: (string?) default: ''. -- - language: (string?) default: ''. --- - temperature: (string?) default: ''. +-- - temperature: (string?) default: '0.1'. Value between 0.0 and 1.0. -- - prompts: (table?) default: default_prompts. -- - debug: (boolean?) default: false. M.setup = function(options) @@ -25,7 +25,7 @@ M.setup = function(options) vim.g.copilot_chat_hide_system_prompt = options and options.hide_system_prompt or 'yes' vim.g.copilot_chat_proxy = options and options.proxy or '' vim.g.copilot_chat_language = options and options.language or '' - vim.g.copilot_chat_temperature = options and options.temperature or '' + vim.g.copilot_chat_temperature = options and options.temperature or '0.1' local debug = options and options.debug or false _COPILOT_CHAT_GLOBAL_CONFIG.debug = debug diff --git a/rplugin/python3/CopilotChat/handlers/chat_handler.py b/rplugin/python3/CopilotChat/handlers/chat_handler.py index 7d752a0e..7c9918e6 100644 --- a/rplugin/python3/CopilotChat/handlers/chat_handler.py +++ b/rplugin/python3/CopilotChat/handlers/chat_handler.py @@ -17,6 +17,9 @@ def is_module_installed(name): return False +DEFAULT_TEMPERATURE = 0.1 + + # TODO: Support Custom Instructions when this issue has been resolved https://github.com/microsoft/vscode-copilot-release/issues/563 class ChatHandler: has_show_extra_info = False @@ -44,14 +47,12 @@ def chat( disable_separators = ( self.nvim.eval("g:copilot_chat_disable_separators") == "yes" ) - temperature = self.nvim.eval("g:copilot_chat_temperature") - if temperature is None or temperature == "": - temperature = 0.1 - else: - temperature = float(temperature) - self.proxy = self.nvim.eval("g:copilot_chat_proxy") - if "://" not in self.proxy: - self.proxy = None + + # Validate and set temperature + temperature = self._get_temperature() + + # Set proxy + self._set_proxy() if system_prompt is None: system_prompt = self._construct_system_prompt(prompt) @@ -78,6 +79,24 @@ def chat( self._add_end_separator(model, disable_separators) # private + def _set_proxy(self): + self.proxy = self.nvim.eval("g:copilot_chat_proxy") + if "://" not in self.proxy: + self.proxy = None + + def _get_temperature(self): + temperature = self.nvim.eval("g:copilot_chat_temperature") + try: + temperature = float(temperature) + if not 0 <= temperature <= 1: + raise ValueError + except ValueError: + self.nvim.exec_lua( + 'require("CopilotChat.utils").log_error(...)', + "Invalid temperature value. Please provide a numeric value between 0 and 1.", + ) + temperature = DEFAULT_TEMPERATURE + return temperature def _construct_system_prompt(self, prompt: str): system_prompt = system_prompts.COPILOT_INSTRUCTIONS @@ -239,7 +258,7 @@ def _add_chat_messages( code: str, file_type: str, model: str, - temperature: float = 0.1, + temperature: float = DEFAULT_TEMPERATURE, ): if self.copilot is None: self.copilot = Copilot(proxy=self.proxy) From d7abc3e6be645ecc77a46764758d468916a46ac6 Mon Sep 17 00:00:00 2001 From: Huynh Duc Dung Date: Wed, 21 Feb 2024 04:16:18 +0800 Subject: [PATCH 2/3] chore: add logging for model temperature --- rplugin/python3/CopilotChat/handlers/chat_handler.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rplugin/python3/CopilotChat/handlers/chat_handler.py b/rplugin/python3/CopilotChat/handlers/chat_handler.py index 7c9918e6..3bc8788d 100644 --- a/rplugin/python3/CopilotChat/handlers/chat_handler.py +++ b/rplugin/python3/CopilotChat/handlers/chat_handler.py @@ -295,6 +295,9 @@ def _add_chat_messages( self.nvim.exec_lua( 'require("CopilotChat.utils").log_info(...)', f"Model: {model}" ) + self.nvim.exec_lua( + 'require("CopilotChat.utils").log_info(...)', f"Temperature: {temperature}" + ) self.nvim.exec_lua( 'require("CopilotChat.utils").log_info(...)', "Asking Copilot" ) From 847a35457106e9d6ec7a9675b25cf8f90f8e84cc Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 21 Feb 2024 05:27:25 +0800 Subject: [PATCH 3/3] chore(main): release 1.7.1 (#62) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- CHANGELOG.md | 7 +++++++ version.txt | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51c16f35..24ae3e2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [1.7.1](https://github.com/CopilotC-Nvim/CopilotChat.nvim/compare/v1.7.0...v1.7.1) (2024-02-20) + + +### Bug Fixes + +* set default temperature and validate temperature value ([8ff6db6](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/8ff6db68eb00f739546db9954e8910f9c6c683e7)) + ## [1.7.0](https://github.com/CopilotC-Nvim/CopilotChat.nvim/compare/v1.6.2...v1.7.0) (2024-02-20) diff --git a/version.txt b/version.txt index bd8bf882..943f9cbc 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.7.0 +1.7.1