From b5db053ca74ea36d38212d5a67ffae3cfc4e8b7a Mon Sep 17 00:00:00 2001 From: gptlang Date: Tue, 20 Feb 2024 17:47:05 +0000 Subject: [PATCH 1/8] feat: add temperature option --- lua/CopilotChat/init.lua | 1 + rplugin/python3/CopilotChat/copilot.py | 3 ++- rplugin/python3/CopilotChat/handlers/chat_handler.py | 11 ++++++++--- rplugin/python3/CopilotChat/utilities.py | 3 ++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lua/CopilotChat/init.lua b/lua/CopilotChat/init.lua index 99994646..dc35d479 100644 --- a/lua/CopilotChat/init.lua +++ b/lua/CopilotChat/init.lua @@ -24,6 +24,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 '' local debug = options and options.debug or false _COPILOT_CHAT_GLOBAL_CONFIG.debug = debug diff --git a/rplugin/python3/CopilotChat/copilot.py b/rplugin/python3/CopilotChat/copilot.py index c03e7927..d31fd872 100644 --- a/rplugin/python3/CopilotChat/copilot.py +++ b/rplugin/python3/CopilotChat/copilot.py @@ -100,6 +100,7 @@ def ask( code: str, language: str = "", model: str = "gpt-4", + temperature: float = 0.1, ): if not self.token: self.authenticate() @@ -112,7 +113,7 @@ def ask( url = "https://api.githubcopilot.com/chat/completions" self.chat_history.append(typings.Message(prompt, "user")) data = utilities.generate_request( - self.chat_history, code, language, system_prompt=system_prompt, model=model + self.chat_history, code, language, system_prompt=system_prompt, model=model, temperature=temperature ) full_response = "" diff --git a/rplugin/python3/CopilotChat/handlers/chat_handler.py b/rplugin/python3/CopilotChat/handlers/chat_handler.py index 8e2745e2..ea819eea 100644 --- a/rplugin/python3/CopilotChat/handlers/chat_handler.py +++ b/rplugin/python3/CopilotChat/handlers/chat_handler.py @@ -44,6 +44,11 @@ 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: + temperature = 0.1 + else: + temperature = float(temperature) self.proxy = self.nvim.eval("g:copilot_chat_proxy") if "://" not in self.proxy: self.proxy = None @@ -62,7 +67,7 @@ def chat( system_prompt, prompt, code, filetype, winnr, disable_separators ) - self._add_chat_messages(system_prompt, prompt, code, filetype, model) + self._add_chat_messages(system_prompt, prompt, code, filetype, model,temperature=temperature) # Stop the spinner self.nvim.exec_lua('require("CopilotChat.spinner").hide()') @@ -226,7 +231,7 @@ def _add_folds( self.nvim.command(full_command) def _add_chat_messages( - self, system_prompt: str, prompt: str, code: str, file_type: str, model: str + self, system_prompt: str, prompt: str, code: str, file_type: str, model: str, temperature: float = 0.1 ): if self.copilot is None: self.copilot = Copilot(proxy=self.proxy) @@ -268,7 +273,7 @@ def _add_chat_messages( ) # TODO: Abort request if the user closes the layout for token in self.copilot.ask( - system_prompt, prompt, code, language=cast(str, file_type), model=model + system_prompt, prompt, code, language=cast(str, file_type), model=model, temperature=temperature ): self.nvim.exec_lua( 'require("CopilotChat.utils").log_info(...)', f"Token: {token}" diff --git a/rplugin/python3/CopilotChat/utilities.py b/rplugin/python3/CopilotChat/utilities.py index f9a5c618..94d31f31 100644 --- a/rplugin/python3/CopilotChat/utilities.py +++ b/rplugin/python3/CopilotChat/utilities.py @@ -16,6 +16,7 @@ def generate_request( language: str = "", system_prompt=prompts.COPILOT_INSTRUCTIONS, model="gpt-4", + temperature=0.1, ): messages = [ { @@ -43,7 +44,7 @@ def generate_request( "model": model, "n": 1, "stream": True, - "temperature": 0.1, # TODO: add temperature setting, refer the suggestion from user https://discord.com/channels/1200633211236122665/1209114805147926538/1209189717791477870 + "temperature": temperature, "top_p": 1, "messages": messages, } From 9efb087d99bcddbef1a899b6939efee8ddac1e76 Mon Sep 17 00:00:00 2001 From: gptlang Date: Tue, 20 Feb 2024 17:48:07 +0000 Subject: [PATCH 2/8] pre-commit --- CHANGELOG.md | 40 ++++++++----------- rplugin/python3/CopilotChat/copilot.py | 7 +++- .../CopilotChat/handlers/chat_handler.py | 19 +++++++-- 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9845ffa..963d1016 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,63 +2,55 @@ ## [1.6.2](https://github.com/CopilotC-Nvim/CopilotChat.nvim/compare/v1.6.1...v1.6.2) (2024-02-20) - ### Bug Fixes -* set filetype to markdown for toggle vsplit buffer ([1e250ff](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/1e250ff1d751fc187e220ac596eb745f09e805aa)) +- set filetype to markdown for toggle vsplit buffer ([1e250ff](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/1e250ff1d751fc187e220ac596eb745f09e805aa)) ## [1.6.1](https://github.com/CopilotC-Nvim/CopilotChat.nvim/compare/v1.6.0...v1.6.1) (2024-02-18) - ### Bug Fixes -* **code_actions:** Add check for 'No diagnostics available' in diagnostic prompts ([e46fa23](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/e46fa23fe7c43a29c849fb9b6a1d565d2e0b83f1)) +- **code_actions:** Add check for 'No diagnostics available' in diagnostic prompts ([e46fa23](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/e46fa23fe7c43a29c849fb9b6a1d565d2e0b83f1)) ## [1.6.0](https://github.com/CopilotC-Nvim/CopilotChat.nvim/compare/v1.5.0...v1.6.0) (2024-02-18) - ### Features -* add language settings for copilot answers ([8e40e41](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/8e40e41c5bdabe675b2e54c80347dd85f1a9d550)) -* add support for visual mode in show_prompt_actions function ([13dfbba](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/13dfbba39e2202ad6bae5b4806ce7e42f75c94a0)) -* disable vim diagnostics on chat buffer for vsplit handler ([fe1808e](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/fe1808e51760c2fa71ca4176551161c73b2f2f73)) - +- add language settings for copilot answers ([8e40e41](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/8e40e41c5bdabe675b2e54c80347dd85f1a9d550)) +- add support for visual mode in show_prompt_actions function ([13dfbba](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/13dfbba39e2202ad6bae5b4806ce7e42f75c94a0)) +- disable vim diagnostics on chat buffer for vsplit handler ([fe1808e](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/fe1808e51760c2fa71ca4176551161c73b2f2f73)) ### Bug Fixes -* add validation before call FixDiagnostic command ([81c5060](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/81c506027e6a638973e3187dd98fc70cae024719)) -* reorder system prompt and language prompt ([0d474a1](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/0d474a14b3bf67469946aa639e3de1a42b016373)) +- add validation before call FixDiagnostic command ([81c5060](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/81c506027e6a638973e3187dd98fc70cae024719)) +- reorder system prompt and language prompt ([0d474a1](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/0d474a14b3bf67469946aa639e3de1a42b016373)) ## [1.5.0](https://github.com/CopilotC-Nvim/CopilotChat.nvim/compare/v1.4.0...v1.5.0) (2024-02-17) - ### Features -* add options to hide system prompts ([98a6191](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/98a61913f4cd798fb042f4b21f6a3e1a457c3959)) -* add prompt actions support in Telescope integration ([f124645](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/f124645d4b48df59790c9763687b94cf7dd3f5bf)) -* integrate CopilotChat with telescope.nvim for code actions ([0cabac6](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/0cabac6af8c838d4984b766f5d985a04259d3a4d)) +- add options to hide system prompts ([98a6191](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/98a61913f4cd798fb042f4b21f6a3e1a457c3959)) +- add prompt actions support in Telescope integration ([f124645](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/f124645d4b48df59790c9763687b94cf7dd3f5bf)) +- integrate CopilotChat with telescope.nvim for code actions ([0cabac6](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/0cabac6af8c838d4984b766f5d985a04259d3a4d)) ## [1.4.0](https://github.com/CopilotC-Nvim/CopilotChat.nvim/compare/v1.3.0...v1.4.0) (2024-02-16) - ### Features -* add diagnostic troubleshooting command ([0e5eced](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/0e5ecedda4d7a9cc6eeef1424889d8d9550bf4f3)) -* add toggle command for vertical split in CopilotChat ([48209d6](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/48209d6b98cb50c9dae59da70ebda351282cf8f7)) -* **integration:** set filetype to 'copilot-chat' for support edgy.nvim ([60718ed](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/60718ed6e806fa86fd78cb3bf55a05f1a74b257e)) +- add diagnostic troubleshooting command ([0e5eced](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/0e5ecedda4d7a9cc6eeef1424889d8d9550bf4f3)) +- add toggle command for vertical split in CopilotChat ([48209d6](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/48209d6b98cb50c9dae59da70ebda351282cf8f7)) +- **integration:** set filetype to 'copilot-chat' for support edgy.nvim ([60718ed](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/60718ed6e806fa86fd78cb3bf55a05f1a74b257e)) ## [1.3.0](https://github.com/CopilotC-Nvim/CopilotChat.nvim/compare/v1.2.0...v1.3.0) (2024-02-14) - ### Features -* add reset buffer for CopilotChatReset command ([bf6d29f](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/bf6d29f3bde05c8a2b0f127737af13cc6df73b9a)) -* CopilotChatReset command ([528e6b4](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/528e6b4b33737e4863fccdb7ed2c6d7aec4f2029)) - +- add reset buffer for CopilotChatReset command ([bf6d29f](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/bf6d29f3bde05c8a2b0f127737af13cc6df73b9a)) +- CopilotChatReset command ([528e6b4](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/528e6b4b33737e4863fccdb7ed2c6d7aec4f2029)) ### Bug Fixes -* Include more info about refusal reason ([46bdf01](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/46bdf018069072a8a43c468ee1cede45536909a3)) +- Include more info about refusal reason ([46bdf01](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/46bdf018069072a8a43c468ee1cede45536909a3)) ## [1.2.0](https://github.com/CopilotC-Nvim/CopilotChat.nvim/compare/v1.1.0...v1.2.0) (2024-02-13) diff --git a/rplugin/python3/CopilotChat/copilot.py b/rplugin/python3/CopilotChat/copilot.py index d31fd872..100d41e2 100644 --- a/rplugin/python3/CopilotChat/copilot.py +++ b/rplugin/python3/CopilotChat/copilot.py @@ -113,7 +113,12 @@ def ask( url = "https://api.githubcopilot.com/chat/completions" self.chat_history.append(typings.Message(prompt, "user")) data = utilities.generate_request( - self.chat_history, code, language, system_prompt=system_prompt, model=model, temperature=temperature + self.chat_history, + code, + language, + system_prompt=system_prompt, + model=model, + temperature=temperature, ) full_response = "" diff --git a/rplugin/python3/CopilotChat/handlers/chat_handler.py b/rplugin/python3/CopilotChat/handlers/chat_handler.py index ea819eea..59233de7 100644 --- a/rplugin/python3/CopilotChat/handlers/chat_handler.py +++ b/rplugin/python3/CopilotChat/handlers/chat_handler.py @@ -67,7 +67,9 @@ def chat( system_prompt, prompt, code, filetype, winnr, disable_separators ) - self._add_chat_messages(system_prompt, prompt, code, filetype, model,temperature=temperature) + self._add_chat_messages( + system_prompt, prompt, code, filetype, model, temperature=temperature + ) # Stop the spinner self.nvim.exec_lua('require("CopilotChat.spinner").hide()') @@ -231,7 +233,13 @@ def _add_folds( self.nvim.command(full_command) def _add_chat_messages( - self, system_prompt: str, prompt: str, code: str, file_type: str, model: str, temperature: float = 0.1 + self, + system_prompt: str, + prompt: str, + code: str, + file_type: str, + model: str, + temperature: float = 0.1, ): if self.copilot is None: self.copilot = Copilot(proxy=self.proxy) @@ -273,7 +281,12 @@ def _add_chat_messages( ) # TODO: Abort request if the user closes the layout for token in self.copilot.ask( - system_prompt, prompt, code, language=cast(str, file_type), model=model, temperature=temperature + system_prompt, + prompt, + code, + language=cast(str, file_type), + model=model, + temperature=temperature, ): self.nvim.exec_lua( 'require("CopilotChat.utils").log_info(...)', f"Token: {token}" From 017289a7cdaa71ab2b512291e15429b676f9bbda Mon Sep 17 00:00:00 2001 From: gptlang Date: Tue, 20 Feb 2024 17:48:36 +0000 Subject: [PATCH 3/8] readme: example temperature config --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 08b4d95c..26fedf60 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ return { disable_extra_info = 'no', -- Disable extra information (e.g: system prompt) in the response. language = "English" -- Copilot answer language settings when using default prompts. Default language is English. -- proxy = "socks5://127.0.0.1:3000", -- Proxies requests via https or socks. + -- temperature = 0.1, }, build = function() vim.notify("Please update the remote plugins by running ':UpdateRemotePlugins', then restart Neovim.") From 641867327f500ff38eb699e267784b2e13a515d1 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 20 Feb 2024 17:49:01 +0000 Subject: [PATCH 4/8] chore(doc): auto generate docs --- doc/CopilotChat.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/CopilotChat.txt b/doc/CopilotChat.txt index 2ad03ce2..af8396e7 100644 --- a/doc/CopilotChat.txt +++ b/doc/CopilotChat.txt @@ -57,6 +57,7 @@ LAZY.NVIM ~ disable_extra_info = 'no', -- Disable extra information (e.g: system prompt) in the response. language = "English" -- Copilot answer language settings when using default prompts. Default language is English. -- proxy = "socks5://127.0.0.1:3000", -- Proxies requests via https or socks. + -- temperature = 0.1, }, build = function() vim.notify("Please update the remote plugins by running ':UpdateRemotePlugins', then restart Neovim.") From b38a4e9af74afb13f54cd346c7fd147018c38f02 Mon Sep 17 00:00:00 2001 From: Jack Muratore Date: Tue, 20 Feb 2024 14:39:36 -0500 Subject: [PATCH 5/8] fix: add check for temperature if empty string (#60) --- rplugin/python3/CopilotChat/handlers/chat_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rplugin/python3/CopilotChat/handlers/chat_handler.py b/rplugin/python3/CopilotChat/handlers/chat_handler.py index 59233de7..7d752a0e 100644 --- a/rplugin/python3/CopilotChat/handlers/chat_handler.py +++ b/rplugin/python3/CopilotChat/handlers/chat_handler.py @@ -45,7 +45,7 @@ def chat( self.nvim.eval("g:copilot_chat_disable_separators") == "yes" ) temperature = self.nvim.eval("g:copilot_chat_temperature") - if temperature is None: + if temperature is None or temperature == "": temperature = 0.1 else: temperature = float(temperature) From ae67b64347053dfdd09ee5e67dd6bc8efa9399f6 Mon Sep 17 00:00:00 2001 From: Huynh Duc Dung Date: Wed, 21 Feb 2024 03:42:31 +0800 Subject: [PATCH 6/8] docs: add new contributor and temperature option --- .all-contributorsrc | 7 +++++++ README.md | 3 ++- lua/CopilotChat/init.lua | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index e734b8a4..a5a6e81a 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -88,6 +88,13 @@ "avatar_url": "https://avatars.githubusercontent.com/u/122616073?v=4", "profile": "https://github.com/neutrinoA4", "contributions": ["code", "doc"] + }, + { + "login": "banjocat", + "name": "Jack Muratore", + "avatar_url": "https://avatars.githubusercontent.com/u/3247309?v=4", + "profile": "https://github.com/banjocat", + "contributions": ["code"] } ], "contributorsPerLine": 7, diff --git a/README.md b/README.md index 26fedf60..87ae0d9e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-12-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-13-orange.svg?style=flat-square)](#contributors-) @@ -462,6 +462,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Erno Hopearuoho
Erno Hopearuoho

💻 Shaun Garwood
Shaun Garwood

💻 neutrinoA4
neutrinoA4

💻 📖 + Jack Muratore
Jack Muratore

💻 diff --git a/lua/CopilotChat/init.lua b/lua/CopilotChat/init.lua index dc35d479..01fcdadf 100644 --- a/lua/CopilotChat/init.lua +++ b/lua/CopilotChat/init.lua @@ -16,6 +16,7 @@ _COPILOT_CHAT_GLOBAL_CONFIG = {} -- - hide_system_prompt: ('yes' | 'no') default: 'yes'. -- - proxy: (string?) default: ''. -- - language: (string?) default: ''. +-- - temperature: (string?) default: ''. -- - prompts: (table?) default: default_prompts. -- - debug: (boolean?) default: false. M.setup = function(options) From 70c41457630eaba4d4a67cca32dfc51f5bd8bc1c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 20 Feb 2024 19:42:58 +0000 Subject: [PATCH 7/8] chore(doc): auto generate docs --- doc/CopilotChat.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/CopilotChat.txt b/doc/CopilotChat.txt index af8396e7..36db2dce 100644 --- a/doc/CopilotChat.txt +++ b/doc/CopilotChat.txt @@ -495,7 +495,7 @@ CONTRIBUTORS ✨ *CopilotChat-copilot-chat-for-neovim-contributors-✨* Thanks goes to these wonderful people (emoji key ): -gptlang💻 📖Dung Duc Huynh (Kaka)💻 📖Ahmed Haracic💻Trí Thiện Nguyễn💻He Zhizhou💻Guruprakash Rajakkannu💻kristofka💻PostCyberPunk📖Katsuhiko Nishimra💻Erno Hopearuoho💻Shaun Garwood💻neutrinoA4💻 📖This project follows the all-contributors +gptlang💻 📖Dung Duc Huynh (Kaka)💻 📖Ahmed Haracic💻Trí Thiện Nguyễn💻He Zhizhou💻Guruprakash Rajakkannu💻kristofka💻PostCyberPunk📖Katsuhiko Nishimra💻Erno Hopearuoho💻Shaun Garwood💻neutrinoA4💻 📖Jack Muratore💻This project follows the all-contributors specification. Contributions of any kind are welcome! @@ -507,7 +507,7 @@ STARGAZERS OVER TIME ~ ============================================================================== 2. Links *CopilotChat-links* -1. *All Contributors*: https://img.shields.io/badge/all_contributors-12-orange.svg?style=flat-square +1. *All Contributors*: https://img.shields.io/badge/all_contributors-13-orange.svg?style=flat-square 2. *@treyhunner*: 3. *@nekowasabi*: 4. *@jellydn*: From 21eac2c74dac92407393416edd0132b9c2981508 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 21 Feb 2024 03:44:42 +0800 Subject: [PATCH 8/8] chore(main): release 1.7.0 (#61) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- CHANGELOG.md | 12 ++++++++++++ version.txt | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 963d1016..51c16f35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## [1.7.0](https://github.com/CopilotC-Nvim/CopilotChat.nvim/compare/v1.6.2...v1.7.0) (2024-02-20) + + +### Features + +* add temperature option ([b5db053](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/b5db053ca74ea36d38212d5a67ffae3cfc4e8b7a)) + + +### Bug Fixes + +* add check for temperature if empty string ([#60](https://github.com/CopilotC-Nvim/CopilotChat.nvim/issues/60)) ([b38a4e9](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/b38a4e9af74afb13f54cd346c7fd147018c38f02)) + ## [1.6.2](https://github.com/CopilotC-Nvim/CopilotChat.nvim/compare/v1.6.1...v1.6.2) (2024-02-20) ### Bug Fixes diff --git a/version.txt b/version.txt index fdd3be6d..bd8bf882 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.6.2 +1.7.0