Skip to content

Commit

Permalink
fix: handle bedrock exceptions (#1483)
Browse files Browse the repository at this point in the history
  • Loading branch information
brookhong authored Mar 4, 2025
1 parent ab63b52 commit e1d2d82
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lua/avante/llm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ function M._stream(opts)
end

-- If stream is not enabled, then handle the response here
if spec.body.stream == false and result.status == 200 then
if (spec.body.stream == nil or spec.body.stream == false) and result.status == 200 then
vim.schedule(function()
completed = true
parse_response_without_stream(result.body)
Expand Down
10 changes: 10 additions & 0 deletions lua/avante/providers/bedrock.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ function M.parse_stream_data(ctx, data, opts)
end
end

function M.parse_response_without_stream(data, event_state, opts)
local bedrock_match = data:gmatch("exception(%b{})")
opts.on_chunk("\n**Exception caught**\n\n")
for bedrock_data_match in bedrock_match do
local jsn = vim.json.decode(bedrock_data_match)
opts.on_chunk("- " .. jsn.message .. "\n")
end
vim.schedule(function() opts.on_stop({ reason = "complete" }) end)
end

---@param provider AvanteBedrockProviderFunctor
---@param prompt_opts AvantePromptOptions
---@return table
Expand Down

0 comments on commit e1d2d82

Please sign in to comment.