Skip to content

Commit

Permalink
feat: ability to stream advisor output
Browse files Browse the repository at this point in the history
  • Loading branch information
olimorris committed Feb 5, 2024
1 parent d3d38ff commit 8fd80bd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,12 @@ require("codecompanion").setup({
width = 95,
height = 10,
},
advisor = {
stream = false, -- Stream the output like a chat buffer?
},
chat = { -- Options for the chat strategy
type = "float", -- float|buffer
show_settings = false, -- Show the model settings in the chat window
show_settings = false, -- Show the model settings in the chat window?
show_token_count = true, -- Show the token count for the current chat?
buf_options = { -- Buffer options for the chat buffer
buflisted = false,
Expand Down
3 changes: 3 additions & 0 deletions lua/codecompanion/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ local defaults = {
width = 95,
height = 10,
},
advisor = {
stream = false,
},
chat = {
type = "float",
show_settings = false,
Expand Down
13 changes: 12 additions & 1 deletion lua/codecompanion/strategy/advisor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,24 @@ function Advisor:execute(user_input)
})
end

local messages = conversation.messages

if config.options.display.advisor.stream then
local chat = require("codecompanion.strategy.chat").new({
client = self.client,
messages = messages,
show_buffer = true,
})

return chat:submit()
end

self.client:advisor(conversation, function(err, data)
if err then
log:error("Advisor Error: %s", err)
vim.notify(err, vim.log.levels.ERROR)
end

local messages = conversation.messages
table.insert(messages, data.choices[1].message)
table.insert(messages, {
role = "user",
Expand Down

0 comments on commit 8fd80bd

Please sign in to comment.