Skip to content

Commit

Permalink
fix: anthropic chat prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
olimorris committed Mar 9, 2024
1 parent 69ca724 commit 21e56b4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
9 changes: 2 additions & 7 deletions lua/codecompanion/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ M.static.actions = {
},
{
role = "user",
contains_code = true,
content = function(context)
local diagnostics =
require("codecompanion.helpers.lsp").get_diagnostics(context.start_line, context.end_line, context.bufnr)
Expand All @@ -480,13 +481,7 @@ M.static.actions = {
.. context.filetype
.. ". This is a list of the diagnostic messages:\n\n"
.. concatenated_diagnostics
end,
},
{
role = "user",
contains_code = true,
content = function(context)
return "This is the code, for context:\n\n"
.. "\n\nThis is the code, for context:\n\n"
.. "```"
.. context.filetype
.. "\n"
Expand Down
8 changes: 6 additions & 2 deletions lua/codecompanion/adapters/anthropic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ return {
---@return table
form_parameters = function(params, messages)
local system_prompt_index = get_system_prompt(messages)
params.system = messages[system_prompt_index].content
if system_prompt_index then
params.system = messages[system_prompt_index].content
end

return params
end,
Expand All @@ -48,7 +50,9 @@ return {
---@return table
form_messages = function(messages)
local system_prompt_index = get_system_prompt(messages)
table.remove(messages, system_prompt_index)
if system_prompt_index then
table.remove(messages, system_prompt_index)
end

return { messages = messages }
end,
Expand Down
6 changes: 6 additions & 0 deletions lua/codecompanion/strategies/inline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ function Inline:execute(user_input)
fire_autocmd("started")

local output = {}

if not adapter then
vim.notify("No adapter found for inline requests", vim.log.levels.ERROR)
return
end

client.new():stream(adapter:set_params(), messages, self.context.bufnr, function(err, data, done)
if err then
fire_autocmd("finished")
Expand Down

0 comments on commit 21e56b4

Please sign in to comment.