Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ai): fix Azure streaming with raw JSON transmission mode #14148

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/unreleased/kong/fix-ai-azure-streaming.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: "**ai-proxy**: Fixed a bug where Azure streaming responses would be missing individual tokens."
type: bugfix
scope: Plugin
4 changes: 2 additions & 2 deletions kong/llm/drivers/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ function _M.frame_to_events(frame, content_type)
-- some new LLMs return the JSON object-by-object,
-- because that totally makes sense to parse?!
local frame_start = frame and frame:sub(1, 1)
if frame_start == "," or frame_start == "[" then
if (not kong or not kong.ctx.plugin.truncated_frame) and (frame_start == "," or frame_start == "[") then
local done = false

-- if this is the first frame, it will begin with array opener '['
Expand Down Expand Up @@ -416,7 +416,7 @@ function _M.frame_to_events(frame, content_type)
if #dat > 0 and #event_lines == i then
ngx.log(ngx.DEBUG, "[ai-proxy] truncated sse frame head")
if kong then
kong.ctx.plugin.truncated_frame = dat
kong.ctx.plugin.truncated_frame = fmt("%s%s", (kong.ctx.plugin.truncated_frame or ""), dat)
end

break -- stop parsing immediately, server has done something wrong
Expand Down
Loading