Skip to content

Commit

Permalink
merge pr for py10 and disable_extra_info
Browse files Browse the repository at this point in the history
  • Loading branch information
gptlang committed Feb 4, 2024
2 parents 1877e35 + 1f57cf4 commit 1ddbfe5
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 12 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Release
on:
push:
branches:
- release
pull_request:
branches:
- main
- release

jobs:
release:
name: release
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v3
id: release
with:
release-type: simple
package-name: CopilotChat.nvim
- uses: actions/checkout@v3
- name: tag stable versions
if: ${{ steps.release.outputs.release_created }}
run: |
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
git remote add gh-token "https://${{ secrets.GITHUB_TOKEN }}@github.com/google-github-actions/release-please-action.git"
git tag -d stable || true
git push origin :stable || true
git tag -a stable -m "Last Stable Release"
git push origin stable
1 change: 1 addition & 0 deletions lua/CopilotChat/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ _COPILOT_CHAT_GLOBAL_CONFIG = {}
-- - debug: (boolean?) default: false.
M.setup = function(options)
vim.g.copilot_chat_show_help = options and options.show_help or 'yes'
vim.g.copilot_chat_disable_separators = options and options.disable_extra_info or false
local debug = options and options.debug or false
_COPILOT_CHAT_GLOBAL_CONFIG.debug = debug

Expand Down
32 changes: 23 additions & 9 deletions rplugin/python3/handlers/chat_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ def chat(
disable_end_separator: bool = False,
model: str = "gpt-4",
):
no_annoyance = self.nvim.eval("g:copilot_chat_disable_separators") == "yes"
if system_prompt is None:
system_prompt = self._construct_system_prompt(prompt)

# Start the spinner
self.nvim.exec_lua('require("CopilotChat.spinner").show()')

Expand All @@ -46,15 +46,17 @@ def chat(
)

if not disable_start_separator:
self._add_start_separator(system_prompt, prompt, code, filetype, winnr)
self._add_start_separator(
system_prompt, prompt, code, filetype, winnr, no_annoyance
)

self._add_chat_messages(system_prompt, prompt, code, filetype, model)

# Stop the spinner
self.nvim.exec_lua('require("CopilotChat.spinner").hide()')

if not disable_end_separator:
self._add_end_separator(model)
self._add_end_separator(model, no_annoyance)

# private

Expand All @@ -75,14 +77,15 @@ def _add_start_separator(
code: str,
file_type: str,
winnr: int,
no_annoyance: bool = False,
):
if is_module_installed("tiktoken"):
if is_module_installed("tiktoken") and not no_annoyance:
self._add_start_separator_with_token_count(
system_prompt, prompt, code, file_type, winnr
)
else:
self._add_regular_start_separator(
system_prompt, prompt, code, file_type, winnr
system_prompt, prompt, code, file_type, winnr, no_annoyance
)

def _add_regular_start_separator(
Expand All @@ -92,15 +95,17 @@ def _add_regular_start_separator(
code: str,
file_type: str,
winnr: int,
no_annoyance: bool = False,
):
if code:
if code and not no_annoyance:
code = f"\n \nCODE:\n```{file_type}\n{code}\n```"

last_row_before = len(self.buffer.lines())
system_prompt_height = len(system_prompt.split("\n"))
code_height = len(code.split("\n"))

start_separator = f"""### User
start_separator = (
f"""### User
SYSTEM PROMPT:
```
Expand All @@ -111,8 +116,13 @@ def _add_regular_start_separator(
### Copilot
"""
if not no_annoyance
else f"### User\n{prompt}\n\n### Copilot\n\n"
)
self.buffer.append(start_separator.split("\n"))

if no_annoyance:
return
self._add_folds(code, code_height, last_row_before, system_prompt_height, winnr)

def _add_start_separator_with_token_count(
Expand Down Expand Up @@ -222,13 +232,17 @@ def _add_chat_messages(
token.split("\n"),
)

def _add_end_separator(self, model: str):
def _add_end_separator(self, model: str, no_annoyance: bool = False):
current_datetime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
model_info = f"\n#### Answer provided by Copilot (Model: `{model}`) on {current_datetime}."
additional_instructions = (
"\n> For additional queries, please use the `CopilotChat` command."
)
disclaimer = "\n> Please be aware that the AI's output may not always be accurate. Always cross-verify the output.\n---\n"
disclaimer = "\n> Please be aware that the AI's output may not always be accurate. Always cross-verify the output."

end_message = model_info + additional_instructions + disclaimer

if no_annoyance:
end_message = "\n" + current_datetime + "\n---\n"

self.buffer.append(end_message.split("\n"))
6 changes: 3 additions & 3 deletions rplugin/python3/mypynvim/ui_components/popup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from copy import deepcopy
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Callable, Dict, Optional, Union, Unpack
from typing import TYPE_CHECKING, Any, Callable, Dict, Optional, Union

if TYPE_CHECKING:
from mypynvim.core.nvim import MyNvim
Expand All @@ -14,7 +14,7 @@
from mypynvim.core.window import MyWindow

from .calculator import Calculator
from .types import PaddingKeys, PopUpArgs, PopUpConfiguration, Relative
from .types import PaddingKeys, PopUpConfiguration, Relative


@dataclass
Expand All @@ -33,7 +33,7 @@ def __init__(
padding: PaddingKeys = {},
enter: bool = False,
opts={},
**kwargs: Unpack[PopUpArgs],
**kwargs,
):
self.nvim: MyNvim = nvim
self.calculator: Calculator = Calculator(self.nvim)
Expand Down

0 comments on commit 1ddbfe5

Please sign in to comment.