Skip to content

Commit b8d0a9d

Browse files
authored
feat: show date time and additional information on end separator (CopilotC-Nvim#53)
* feat: show date time and addition information on end separator * refactor: merge system prompts to one file
1 parent ca6321c commit b8d0a9d

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

rplugin/python3/handlers/chat_handler.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from datetime import datetime
12
from typing import Optional, cast
23

3-
import prompts as prompts
4+
import prompts as system_prompts
45
from copilot import Copilot
56
from mypynvim.core.buffer import MyBuffer
67
from mypynvim.core.nvim import MyNvim
@@ -52,18 +53,18 @@ def chat(
5253
self.nvim.exec_lua('require("CopilotChat.spinner").hide()')
5354

5455
if not disable_end_separator:
55-
self._add_end_separator()
56+
self._add_end_separator(model)
5657

5758
# private
5859

5960
def _construct_system_prompt(self, prompt: str):
60-
system_prompt = prompts.COPILOT_INSTRUCTIONS
61-
if prompt == prompts.FIX_SHORTCUT:
62-
system_prompt = prompts.COPILOT_FIX
63-
elif prompt == prompts.TEST_SHORTCUT:
64-
system_prompt = prompts.COPILOT_TESTS
65-
elif prompt == prompts.EXPLAIN_SHORTCUT:
66-
system_prompt = prompts.COPILOT_EXPLAIN
61+
system_prompt = system_prompts.COPILOT_INSTRUCTIONS
62+
if prompt == system_prompts.FIX_SHORTCUT:
63+
system_prompt = system_prompts.COPILOT_FIX
64+
elif prompt == system_prompts.TEST_SHORTCUT:
65+
system_prompt = system_prompts.COPILOT_TESTS
66+
elif prompt == system_prompts.EXPLAIN_SHORTCUT:
67+
system_prompt = system_prompts.COPILOT_EXPLAIN
6768
return system_prompt
6869

6970
def _add_start_separator(
@@ -204,6 +205,13 @@ def _add_chat_messages(
204205
token.split("\n"),
205206
)
206207

207-
def _add_end_separator(self):
208-
end_separator = "\n---\n"
209-
self.buffer.append(end_separator.split("\n"))
208+
def _add_end_separator(self, model: str):
209+
current_datetime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
210+
model_info = f"\n#### Answer provided by Copilot (Model: `{model}`) on {current_datetime}."
211+
additional_instructions = (
212+
"\n> For additional queries, please use the `CopilotChat` command."
213+
)
214+
disclaimer = "\n> Please be aware that the AI's output may not always be accurate. Always cross-verify the output.\n---\n"
215+
216+
end_message = model_info + additional_instructions + disclaimer
217+
self.buffer.append(end_message.split("\n"))

rplugin/python3/handlers/inplace_chat_handler.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
from mypynvim.ui_components.layout import Box, Layout
66
from mypynvim.ui_components.popup import PopUp
77

8-
from . import prompts
9-
108
# Define constants for the models
119
MODEL_GPT4 = "gpt-4"
1210
MODEL_GPT35_TURBO = "gpt-3.5-turbo"
@@ -243,10 +241,10 @@ def _set_keymaps(self):
243241
self.prompt_popup.map("n", "<C-m>", lambda cb=self._toggle_system_model: cb())
244242

245243
self.prompt_popup.map(
246-
"n", "'", lambda: self._set_prompt(prompts.PROMPT_SIMPLE_DOCSTRING)
244+
"n", "'", lambda: self._set_prompt(system_prompts.PROMPT_SIMPLE_DOCSTRING)
247245
)
248246
self.prompt_popup.map(
249-
"n", "s", lambda: self._set_prompt(prompts.PROMPT_SEPARATE)
247+
"n", "s", lambda: self._set_prompt(system_prompts.PROMPT_SEPARATE)
250248
)
251249

252250
self.prompt_popup.map(

rplugin/python3/handlers/prompts.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

rplugin/python3/prompts.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,5 @@
247247
Your code output should keep the same level of indentation as the user's code.
248248
You MUST add whitespace in the beginning of each line as needed to match the user's code.
249249
"""
250+
PROMPT_SIMPLE_DOCSTRING = "add simple docstring to this code"
251+
PROMPT_SEPARATE = "add comments separating the code into sections"

0 commit comments

Comments
 (0)