Skip to content

Commit 336cbb9

Browse files
authored
Merge branch 'main' into feature/on_complete_callback
2 parents 1834a41 + 56740e0 commit 336cbb9

File tree

6 files changed

+345
-156
lines changed

6 files changed

+345
-156
lines changed

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
root = true
2+
3+
[*]
4+
indent_style = tab
5+
indent_size = 1
6+
tab_width = 4
7+
end_of_line = lf
8+
insert_final_newline = true
9+
charset = utf-8
10+

README.md

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,9 @@ Voice commands (`:GpWhisper*`) depend on `SoX` (Sound eXchange) to handle audio
207207

208208
## 5. Configuration
209209

210-
Bellow is a linked snippet with the default values, but I suggest starting with minimal config possible (just `openai_api_key` if you don't have `OPENAI_API_KEY` env set up). Defaults change over time to improve things, options might get deprecated and so on - it's better to change only things where the default doesn't fit your needs.
210+
Below is a linked snippet with the default values, but I suggest starting with minimal config possible (just `openai_api_key` if you don't have `OPENAI_API_KEY` env set up). Defaults change over time to improve things, options might get deprecated and so on - it's better to change only things where the default doesn't fit your needs.
211211

212-
https://github.com/Robitx/gp.nvim/blob/d90816b2e9185202d72f7b1346b6d33b36350886/lua/gp/config.lua#L8-L355
212+
https://github.com/Robitx/gp.nvim/blob/3adf3dc7589f54cf7af887879c995aa9846aace5/lua/gp/config.lua#L8-L568
213213

214214
# Usage
215215

@@ -311,12 +311,15 @@ Provides custom context per repository:
311311

312312
## Speech commands
313313

314-
#### `:GpWhisper` <!-- {doc=:GpWhisper} -->
314+
#### `:GpWhisper` {lang?} <!-- {doc=:GpWhisper} -->
315315

316316
Transcription replaces the current line, visual selection or range in the current buffer. Use your mouth to ask a question in a chat buffer instead of writing it by hand, dictate some comments for the code, notes or even your next novel..
317317

318318
For the rest of the whisper commands, the transcription is used as an editable prompt for the equivalent non whisper command - `GpWhisperRewrite` dictates instructions for `GpRewrite` etc.
319319

320+
You can override the default language by setting {lang} with the 2 letter
321+
shortname of your language (e.g. "en" for English, "fr" for French etc).
322+
320323
#### `:GpWhisperRewrite` <!-- {doc=:GpWhisperRewrite} -->
321324

322325
Similar to `:GpRewrite`, but the prompt instruction dialog uses transcribed spoken instructions.
@@ -463,7 +466,7 @@ Ahoy there!
463466

464467
# Shortcuts
465468

466-
There are no default global shortcuts to mess with your own config. Bellow are examples for you to adjust or just use directly.
469+
There are no default global shortcuts to mess with your own config. Below are examples for you to adjust or just use directly.
467470

468471
## Native
469472

@@ -731,7 +734,7 @@ Here are some more examples:
731734
.. "```{{filetype}}\n{{selection}}\n```\n\n"
732735
.. "Please respond by writing table driven unit tests for the code above."
733736
local agent = gp.get_command_agent()
734-
gp.Prompt(params, gp.Target.enew, nil, agent.model, template, agent.system_prompt)
737+
gp.Prompt(params, gp.Target.vnew, agent, template)
735738
end,
736739
````
737740

@@ -744,7 +747,7 @@ Here are some more examples:
744747
.. "```{{filetype}}\n{{selection}}\n```\n\n"
745748
.. "Please respond by explaining the code above."
746749
local agent = gp.get_chat_agent()
747-
gp.Prompt(params, gp.Target.popup, nil, agent.model, template, agent.system_prompt)
750+
gp.Prompt(params, gp.Target.popup, agent, template)
748751
end,
749752
````
750753

@@ -757,7 +760,7 @@ Here are some more examples:
757760
.. "```{{filetype}}\n{{selection}}\n```\n\n"
758761
.. "Please analyze for code smells and suggest improvements."
759762
local agent = gp.get_chat_agent()
760-
gp.Prompt(params, gp.Target.enew("markdown"), nil, agent.model, template, agent.system_prompt)
763+
gp.Prompt(params, gp.Target.enew("markdown"), agent, template)
761764
end,
762765
````
763766

@@ -766,9 +769,12 @@ Here are some more examples:
766769
```lua
767770
-- example of adding command which opens new chat dedicated for translation
768771
Translator = function(gp, params)
769-
local agent = gp.get_command_agent()
770-
local chat_system_prompt = "You are a Translator, please translate between English and Chinese."
771-
gp.cmd.ChatNew(params, agent.model, chat_system_prompt)
772+
local chat_system_prompt = "You are a Translator, please translate between English and Chinese."
773+
gp.cmd.ChatNew(params, chat_system_prompt)
774+
775+
-- -- you can also create a chat with a specific fixed agent like this:
776+
-- local agent = gp.get_chat_agent("ChatGPT4o")
777+
-- gp.cmd.ChatNew(params, chat_system_prompt, agent)
772778
end,
773779
```
774780

@@ -783,7 +789,16 @@ Here are some more examples:
783789
end,
784790
```
785791

786-
The raw plugin text editing method `Prompt` has seven aprameters:
792+
The raw plugin text editing method `Prompt` has following signature:
793+
```lua
794+
---@param params table # vim command parameters such as range, args, etc.
795+
---@param target integer | function | table # where to put the response
796+
---@param agent table # obtained from get_command_agent or get_chat_agent
797+
---@param template string # template with model instructions
798+
---@param prompt string | nil # nil for non interactive commads
799+
---@param whisper string | nil # predefined input (e.g. obtained from Whisper)
800+
Prompt(params, target, agent, template, prompt, whisper)
801+
```
787802

788803
- `params` is a [table passed to neovim user commands](https://neovim.io/doc/user/lua-guide.html#lua-guide-commands-create), `Prompt` currently uses:
789804

@@ -868,25 +883,29 @@ The raw plugin text editing method `Prompt` has seven aprameters:
868883
}
869884
```
870885

871-
- `prompt`
872-
- string used similarly as bash/zsh prompt in terminal, when plugin asks for user command to gpt.
873-
- if `nil`, user is not asked to provide input (for specific predefined commands - document this, explain that, write tests ..)
874-
- simple `🤖 ~ ` might be used or you could use different msg to convey info about the method which is called
875-
(`🤖 rewrite ~`, `🤖 popup ~`, `🤖 enew ~`, `🤖 inline ~`, etc.)
876-
- `model`
877-
- see [gpt model overview](https://platform.openai.com/docs/models/overview)
886+
887+
- `agent` table obtainable via `get_command_agent` and `get_chat_agent` methods which have following signature:
888+
```lua
889+
---@param name string | nil
890+
---@return table # { cmd_prefix, name, model, system_prompt, provider }
891+
get_command_agent(name)
892+
```
893+
878894
- `template`
879895

880896
- template of the user message send to gpt
881-
- string can include variables bellow:
897+
- string can include variables below:
882898

883899
| name | Description |
884900
| --------------- | --------------------------------- |
885901
| `{{filetype}}` | filetype of the current buffer |
886902
| `{{selection}}` | last or currently selected text |
887903
| `{{command}}` | instructions provided by the user |
888904

889-
- `system_template`
890-
- See [gpt api intro](https://platform.openai.com/docs/guides/chat/introduction)
905+
- `prompt`
906+
- string used similarly as bash/zsh prompt in terminal, when plugin asks for user command to gpt.
907+
- if `nil`, user is not asked to provide input (for specific predefined commands - document this, explain that, write tests ..)
908+
- simple `🤖 ~ ` might be used or you could use different msg to convey info about the method which is called
909+
(`🤖 rewrite ~`, `🤖 popup ~`, `🤖 enew ~`, `🤖 inline ~`, etc.)
891910
- `whisper`
892911
- optional string serving as a default for input prompt (for example generated from speech by Whisper)

doc/gp.nvim.txt

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*gp.nvim.txt* For NVIM v0.8.0 Last change: 2024 July 09
1+
*gp.nvim.txt* For NVIM v0.8.0 Last change: 2024 July 17
22

33
==============================================================================
44
Table of Contents *gp.nvim-table-of-contents*
@@ -245,14 +245,14 @@ recording and processing:
245245

246246
5. CONFIGURATION *gp.nvim-5.-configuration*
247247

248-
Bellow is a linked snippet with the default values, but I suggest starting with
248+
Below is a linked snippet with the default values, but I suggest starting with
249249
minimal config possible (just `openai_api_key` if you don’t have
250250
`OPENAI_API_KEY` env set up). Defaults change over time to improve things,
251251
options might get deprecated and so on - it’s better to change only things
252252
where the default doesn’t fit your needs.
253253

254254

255-
https://github.com/Robitx/gp.nvim/blob/d90816b2e9185202d72f7b1346b6d33b36350886/lua/gp/config.lua#L8-L355
255+
https://github.com/Robitx/gp.nvim/blob/3adf3dc7589f54cf7af887879c995aa9846aace5/lua/gp/config.lua#L8-L568
256256

257257

258258
==============================================================================
@@ -396,7 +396,7 @@ Provides custom context per repository:
396396
SPEECH COMMANDS *gp.nvim-speech-commands*
397397

398398

399-
:GpWhisper *:GpWhisper*
399+
:GpWhisper {lang?} *:GpWhisper*
400400

401401
Transcription replaces the current line, visual selection or range in the
402402
current buffer. Use your mouth to ask a question in a chat buffer instead of
@@ -407,6 +407,9 @@ For the rest of the whisper commands, the transcription is used as an editable
407407
prompt for the equivalent non whisper command - `GpWhisperRewrite` dictates
408408
instructions for `GpRewrite` etc.
409409

410+
You can override the default language by setting {lang} with the 2 letter
411+
shortname of your language (e.g. "en" for English, "fr" for French etc).
412+
410413

411414
:GpWhisperRewrite *:GpWhisperRewrite*
412415

@@ -601,7 +604,7 @@ resulting `test` file:
601604
==============================================================================
602605
4. Shortcuts *gp.nvim-shortcuts*
603606

604-
There are no default global shortcuts to mess with your own config. Bellow are
607+
There are no default global shortcuts to mess with your own config. Below are
605608
examples for you to adjust or just use directly.
606609

607610

@@ -876,7 +879,7 @@ Here are some more examples:
876879
.. "```{{filetype}}\n{{selection}}\n```\n\n"
877880
.. "Please respond by writing table driven unit tests for the code above."
878881
local agent = gp.get_command_agent()
879-
gp.Prompt(params, gp.Target.enew, nil, agent.model, template, agent.system_prompt)
882+
gp.Prompt(params, gp.Target.vnew, agent, template)
880883
end,
881884
<
882885
- `:GpExplain`
@@ -887,7 +890,7 @@ Here are some more examples:
887890
.. "```{{filetype}}\n{{selection}}\n```\n\n"
888891
.. "Please respond by explaining the code above."
889892
local agent = gp.get_chat_agent()
890-
gp.Prompt(params, gp.Target.popup, nil, agent.model, template, agent.system_prompt)
893+
gp.Prompt(params, gp.Target.popup, agent, template)
891894
end,
892895
<
893896
- `:GpCodeReview`
@@ -898,16 +901,19 @@ Here are some more examples:
898901
.. "```{{filetype}}\n{{selection}}\n```\n\n"
899902
.. "Please analyze for code smells and suggest improvements."
900903
local agent = gp.get_chat_agent()
901-
gp.Prompt(params, gp.Target.enew("markdown"), nil, agent.model, template, agent.system_prompt)
904+
gp.Prompt(params, gp.Target.enew("markdown"), agent, template)
902905
end,
903906
<
904907
- `:GpTranslator`
905908
>lua
906909
-- example of adding command which opens new chat dedicated for translation
907910
Translator = function(gp, params)
908-
local agent = gp.get_command_agent()
909-
local chat_system_prompt = "You are a Translator, please translate between English and Chinese."
910-
gp.cmd.ChatNew(params, agent.model, chat_system_prompt)
911+
local chat_system_prompt = "You are a Translator, please translate between English and Chinese."
912+
gp.cmd.ChatNew(params, chat_system_prompt)
913+
914+
-- -- you can also create a chat with a specific fixed agent like this:
915+
-- local agent = gp.get_chat_agent("ChatGPT4o")
916+
-- gp.cmd.ChatNew(params, chat_system_prompt, agent)
911917
end,
912918
<
913919
- `:GpBufferChatNew`
@@ -920,7 +926,17 @@ Here are some more examples:
920926
end,
921927
<
922928

923-
The raw plugin text editing method `Prompt` has seven aprameters:
929+
The raw plugin text editing method `Prompt` has following signature:
930+
931+
>lua
932+
---@param params table # vim command parameters such as range, args, etc.
933+
---@param target integer | function | table # where to put the response
934+
---@param agent table # obtained from get_command_agent or get_chat_agent
935+
---@param template string # template with model instructions
936+
---@param prompt string | nil # nil for non interactive commads
937+
---@param whisper string | nil # predefined input (e.g. obtained from Whisper)
938+
Prompt(params, target, agent, template, prompt, whisper)
939+
<
924940

925941
- `params` is a |table passed to neovim user commands|, `Prompt` currently uses:
926942
- `range, line1, line2` to work with |ranges|
@@ -999,23 +1015,26 @@ The raw plugin text editing method `Prompt` has seven aprameters:
9991015
end,
10001016
}
10011017
<
1002-
- `prompt`
1003-
- string used similarly as bash/zsh prompt in terminal, when plugin asks for user command to gpt.
1004-
- if `nil`, user is not asked to provide input (for specific predefined commands - document this, explain that, write tests ..)
1005-
- simple `🤖 ~` might be used or you could use different msg to convey info about the method which is called
1006-
(`🤖 rewrite ~`, `🤖 popup ~`, `🤖 enew ~`, `🤖 inline ~`, etc.)
1007-
- `model`
1008-
- see gpt model overview <https://platform.openai.com/docs/models/overview>
1018+
- `agent` table obtainable via `get_command_agent` and `get_chat_agent` methods
1019+
which have following signature:
1020+
>lua
1021+
---@param name string | nil
1022+
---@return table # { cmd_prefix, name, model, system_prompt, provider }
1023+
get_command_agent(name)
1024+
<
10091025
- `template`
10101026
- template of the user message send to gpt
1011-
- string can include variables bellow:
1027+
- string can include variables below:
10121028
name Description
10131029
--------------- -----------------------------------
10141030
{{filetype}} filetype of the current buffer
10151031
{{selection}} last or currently selected text
10161032
{{command}} instructions provided by the user
1017-
- `system_template`
1018-
- See gpt api intro <https://platform.openai.com/docs/guides/chat/introduction>
1033+
- `prompt`
1034+
- string used similarly as bash/zsh prompt in terminal, when plugin asks for user command to gpt.
1035+
- if `nil`, user is not asked to provide input (for specific predefined commands - document this, explain that, write tests ..)
1036+
- simple `🤖 ~` might be used or you could use different msg to convey info about the method which is called
1037+
(`🤖 rewrite ~`, `🤖 popup ~`, `🤖 enew ~`, `🤖 inline ~`, etc.)
10191038
- `whisper`
10201039
- optional string serving as a default for input prompt (for example generated from speech by Whisper)
10211040

0 commit comments

Comments
 (0)