Skip to content

Commit 2e54467

Browse files
authored
Merge pull request #155 from Robitx/signature_cleanup (resolve: #154)
feat: improve/simlify gp.Prompt and gp.cmd.ChatNew function signatures
2 parents a55dbda + 0362efe commit 2e54467

File tree

3 files changed

+161
-73
lines changed

3 files changed

+161
-73
lines changed

README.md

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ Here are some more examples:
734734
.. "```{{filetype}}\n{{selection}}\n```\n\n"
735735
.. "Please respond by writing table driven unit tests for the code above."
736736
local agent = gp.get_command_agent()
737-
gp.Prompt(params, gp.Target.enew, nil, agent.model, template, agent.system_prompt)
737+
gp.Prompt(params, gp.Target.vnew, agent, template)
738738
end,
739739
````
740740

@@ -747,7 +747,7 @@ Here are some more examples:
747747
.. "```{{filetype}}\n{{selection}}\n```\n\n"
748748
.. "Please respond by explaining the code above."
749749
local agent = gp.get_chat_agent()
750-
gp.Prompt(params, gp.Target.popup, nil, agent.model, template, agent.system_prompt)
750+
gp.Prompt(params, gp.Target.popup, agent, template)
751751
end,
752752
````
753753

@@ -760,7 +760,7 @@ Here are some more examples:
760760
.. "```{{filetype}}\n{{selection}}\n```\n\n"
761761
.. "Please analyze for code smells and suggest improvements."
762762
local agent = gp.get_chat_agent()
763-
gp.Prompt(params, gp.Target.enew("markdown"), nil, agent.model, template, agent.system_prompt)
763+
gp.Prompt(params, gp.Target.enew("markdown"), agent, template)
764764
end,
765765
````
766766

@@ -769,9 +769,12 @@ Here are some more examples:
769769
```lua
770770
-- example of adding command which opens new chat dedicated for translation
771771
Translator = function(gp, params)
772-
local agent = gp.get_command_agent()
773-
local chat_system_prompt = "You are a Translator, please translate between English and Chinese."
774-
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)
775778
end,
776779
```
777780

@@ -786,7 +789,16 @@ Here are some more examples:
786789
end,
787790
```
788791

789-
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+
```
790802

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

@@ -871,13 +883,14 @@ The raw plugin text editing method `Prompt` has seven aprameters:
871883
}
872884
```
873885

874-
- `prompt`
875-
- string used similarly as bash/zsh prompt in terminal, when plugin asks for user command to gpt.
876-
- if `nil`, user is not asked to provide input (for specific predefined commands - document this, explain that, write tests ..)
877-
- simple `🤖 ~ ` might be used or you could use different msg to convey info about the method which is called
878-
(`🤖 rewrite ~`, `🤖 popup ~`, `🤖 enew ~`, `🤖 inline ~`, etc.)
879-
- `model`
880-
- 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+
881894
- `template`
882895

883896
- template of the user message send to gpt
@@ -889,7 +902,10 @@ The raw plugin text editing method `Prompt` has seven aprameters:
889902
| `{{selection}}` | last or currently selected text |
890903
| `{{command}}` | instructions provided by the user |
891904

892-
- `system_template`
893-
- 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.)
894910
- `whisper`
895911
- optional string serving as a default for input prompt (for example generated from speech by Whisper)

lua/gp/config.lua

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -523,10 +523,10 @@ local config = {
523523
gp.Prompt(
524524
params,
525525
gp.Target.rewrite,
526-
nil, -- command will run directly without any prompting for user input
527-
agent.model,
526+
agent,
528527
template,
529-
agent.system_prompt
528+
nil, -- command will run directly without any prompting for user input
529+
nil -- no predefined instructions (e.g. speech-to-text from Whisper)
530530
)
531531
end,
532532

@@ -542,9 +542,12 @@ local config = {
542542

543543
-- -- example of adding command which opens new chat dedicated for translation
544544
-- Translator = function(gp, params)
545-
-- local agent = gp.get_command_agent()
546545
-- local chat_system_prompt = "You are a Translator, please translate between English and Chinese."
547-
-- gp.cmd.ChatNew(params, agent.model, chat_system_prompt)
546+
-- gp.cmd.ChatNew(params, chat_system_prompt)
547+
--
548+
-- -- -- you can also create a chat with a specific fixed agent like this:
549+
-- -- local agent = gp.get_chat_agent("ChatGPT4o")
550+
-- -- gp.cmd.ChatNew(params, chat_system_prompt, agent)
548551
-- end,
549552

550553
-- -- example of adding command which writes unit tests for the selected code
@@ -553,7 +556,7 @@ local config = {
553556
-- .. "```{{filetype}}\n{{selection}}\n```\n\n"
554557
-- .. "Please respond by writing table driven unit tests for the code above."
555558
-- local agent = gp.get_command_agent()
556-
-- gp.Prompt(params, gp.Target.enew, nil, agent.model, template, agent.system_prompt)
559+
-- gp.Prompt(params, gp.Target.enew, agent, template)
557560
-- end,
558561

559562
-- -- example of adding command which explains the selected code
@@ -562,7 +565,7 @@ local config = {
562565
-- .. "```{{filetype}}\n{{selection}}\n```\n\n"
563566
-- .. "Please respond by explaining the code above."
564567
-- local agent = gp.get_chat_agent()
565-
-- gp.Prompt(params, gp.Target.popup, nil, agent.model, template, agent.system_prompt)
568+
-- gp.Prompt(params, gp.Target.popup, agent, template)
566569
-- end,
567570
},
568571
}

0 commit comments

Comments
 (0)