Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for per-agent configuration #531

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,18 @@ Default "noop" agent is `copilot`.
For more information about extension agents, see [here](https://docs.github.com/en/copilot/using-github-copilot/using-extensions-to-integrate-external-tools-with-copilot-chat)
You can install more agents from [here](https://github.com/marketplace?type=apps&copilot_app=true)

You can optionally define extra per-agent configuration like this:

```lua
{
agents = {
perplexityai = {
model = 'llama-3.1-sonar-huge-128k-online'
},
}
}
```

### Contexts

Contexts are used to determine the context of the chat.
Expand Down Expand Up @@ -411,6 +423,7 @@ Also see [here](/lua/CopilotChat/config.lua):

history_path = vim.fn.stdpath('data') .. '/copilotchat_history', -- Default path to stored history
callback = nil, -- Callback to use when ask response is received
agents = nil, -- default per agent configuration

-- default selection
selection = function(source)
Expand Down
2 changes: 2 additions & 0 deletions lua/CopilotChat/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ local select = require('CopilotChat.select')
---@field highlight_headers boolean?
---@field history_path string?
---@field callback fun(response: string, source: CopilotChat.config.source)?
---@field agents table<string, table>?
---@field selection nil|fun(source: CopilotChat.config.source):CopilotChat.config.selection?
---@field contexts table<string, CopilotChat.config.context>?
---@field prompts table<string, CopilotChat.config.prompt|string>?
Expand Down Expand Up @@ -124,6 +125,7 @@ return {

history_path = vim.fn.stdpath('data') .. '/copilotchat_history', -- Default path to stored history
callback = nil, -- Callback to use when ask response is received
agents = nil, -- default per agent configuration

-- default selection
selection = function(source)
Expand Down
27 changes: 16 additions & 11 deletions lua/CopilotChat/copilot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
---@field model string?
---@field agent string?
---@field temperature number?
---@field extra_body table?
---@field on_progress nil|fun(response: string):nil

---@class CopilotChat.copilot.embed.opts
Expand Down Expand Up @@ -707,19 +708,23 @@ function Copilot:ask(prompt, opts)
full_response = full_response .. content
end

local body = vim.json.encode(
generate_ask_request(
self.history,
prompt,
system_prompt,
generated_messages,
model,
temperature,
max_output_tokens,
not vim.startswith(model, 'o1')
)
local request = generate_ask_request(
self.history,
prompt,
system_prompt,
generated_messages,
model,
temperature,
max_output_tokens,
not vim.startswith(model, 'o1')
)

if opts.extra_body then
request = vim.tbl_extend('force', request, opts.extra_body)
end

local body = vim.json.encode(request)

if vim.startswith(model, 'claude') then
self:enable_claude()
end
Expand Down
1 change: 1 addition & 0 deletions lua/CopilotChat/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ function M.ask(prompt, config)
model = selected_model,
agent = selected_agent,
temperature = config.temperature,
extra_body = config.agents and selected_agent and config.agents[selected_agent],
on_progress = function(token)
vim.schedule(function()
state.chat:append(token)
Expand Down