fix: pass context to provider for stream data parsing (#1475)
* fix: pass context to provider for stream data parsing * fix: luatype --------- Co-authored-by: yetone <yetoneful@gmail.com>
This commit is contained in:
@@ -154,6 +154,8 @@ end
|
|||||||
function M._stream(opts)
|
function M._stream(opts)
|
||||||
local provider = opts.provider or Providers[Config.provider]
|
local provider = opts.provider or Providers[Config.provider]
|
||||||
|
|
||||||
|
---@cast provider AvanteProviderFunctor
|
||||||
|
|
||||||
local prompt_opts = M.generate_prompts(opts)
|
local prompt_opts = M.generate_prompts(opts)
|
||||||
|
|
||||||
---@type string
|
---@type string
|
||||||
@@ -285,10 +287,10 @@ function M._stream(opts)
|
|||||||
{ once = true }
|
{ once = true }
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
provider.parse_stream_data(data, handler_opts)
|
provider.parse_stream_data(resp_ctx, data, handler_opts)
|
||||||
else
|
else
|
||||||
if provider.parse_stream_data ~= nil then
|
if provider.parse_stream_data ~= nil then
|
||||||
provider.parse_stream_data(data, handler_opts)
|
provider.parse_stream_data(resp_ctx, data, handler_opts)
|
||||||
else
|
else
|
||||||
parse_stream_data(data)
|
parse_stream_data(data)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ function M.build_bedrock_payload(prompt_opts, body_opts)
|
|||||||
return model_handler.build_bedrock_payload(prompt_opts, body_opts)
|
return model_handler.build_bedrock_payload(prompt_opts, body_opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.parse_stream_data(data, opts)
|
function M.parse_stream_data(ctx, data, opts)
|
||||||
-- @NOTE: Decode and process Bedrock response
|
-- @NOTE: Decode and process Bedrock response
|
||||||
-- Each response contains a Base64-encoded `bytes` field, which is decoded into JSON.
|
-- Each response contains a Base64-encoded `bytes` field, which is decoded into JSON.
|
||||||
-- The `type` field in the decoded JSON determines how the response is handled.
|
-- The `type` field in the decoded JSON determines how the response is handled.
|
||||||
@@ -37,7 +37,7 @@ function M.parse_stream_data(data, opts)
|
|||||||
local jsn = vim.json.decode(bedrock_data_match)
|
local jsn = vim.json.decode(bedrock_data_match)
|
||||||
local data_stream = vim.base64.decode(jsn.bytes)
|
local data_stream = vim.base64.decode(jsn.bytes)
|
||||||
local json = vim.json.decode(data_stream)
|
local json = vim.json.decode(data_stream)
|
||||||
M.parse_response({}, data_stream, json.type, opts)
|
M.parse_response(ctx, data_stream, json.type, opts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ function M.parse_messages(opts)
|
|||||||
return { messages = messages }
|
return { messages = messages }
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.parse_stream_data(data, opts)
|
function M.parse_stream_data(ctx, data, opts)
|
||||||
---@type CohereChatResponse
|
---@type CohereChatResponse
|
||||||
local json = vim.json.decode(data)
|
local json = vim.json.decode(data)
|
||||||
if json.type ~= nil then
|
if json.type ~= nil then
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ vim.g.avante_login = vim.g.avante_login
|
|||||||
---@field tool_use_list? AvanteLLMToolUse[]
|
---@field tool_use_list? AvanteLLMToolUse[]
|
||||||
---@field retry_after? integer
|
---@field retry_after? integer
|
||||||
---
|
---
|
||||||
---@alias AvanteStreamParser fun(line: string, handler_opts: AvanteHandlerOptions): nil
|
---@alias AvanteStreamParser fun(ctx: any, line: string, handler_opts: AvanteHandlerOptions): nil
|
||||||
---@alias AvanteLLMStartCallback fun(opts: AvanteLLMStartCallbackOptions): nil
|
---@alias AvanteLLMStartCallback fun(opts: AvanteLLMStartCallbackOptions): nil
|
||||||
---@alias AvanteLLMChunkCallback fun(chunk: string): any
|
---@alias AvanteLLMChunkCallback fun(chunk: string): any
|
||||||
---@alias AvanteLLMStopCallback fun(opts: AvanteLLMStopCallbackOptions): nil
|
---@alias AvanteLLMStopCallback fun(opts: AvanteLLMStopCallbackOptions): nil
|
||||||
|
|||||||
Reference in New Issue
Block a user