fix(gemini): check if json can be decoded (#446)
Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
parent
3ccb71d7ef
commit
7912070c6f
@ -140,6 +140,7 @@ M.defaults = {
|
||||
wrap = true, -- similar to vim.o.wrap
|
||||
width = 30, -- default % based on available width in vertical layout
|
||||
height = 30, -- default % based on available height in horizontal layout
|
||||
direction = "right", -- "left" | "right"
|
||||
sidebar_header = {
|
||||
align = "center", -- left, center, right for title
|
||||
rounded = true,
|
||||
|
@ -50,9 +50,16 @@ M.parse_message = function(opts)
|
||||
end
|
||||
|
||||
M.parse_response = function(data_stream, _, opts)
|
||||
local json = vim.json.decode(data_stream)
|
||||
if json.candidates and #json.candidates > 0 then
|
||||
local ok, json = pcall(vim.json.decode, data_stream)
|
||||
if not ok then
|
||||
opts.on_complete(json)
|
||||
end
|
||||
if json.candidates then
|
||||
if #json.candidates > 0 then
|
||||
opts.on_chunk(json.candidates[1].content.parts[1].text)
|
||||
elseif json.candidates.finishReason and json.candidates.finishReason == "STOP" then
|
||||
opts.on_complete(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1383,7 +1383,7 @@ function Sidebar:create_input()
|
||||
if self:get_layout() == "vertical" then
|
||||
return "bottom"
|
||||
end
|
||||
return "right"
|
||||
return Config.windows.direction
|
||||
end
|
||||
|
||||
local get_size = function()
|
||||
|
Loading…
x
Reference in New Issue
Block a user