Skip to content

Commit

Permalink
fix(ai): fix Azure streaming with raw JSON transmission mode (#14148)
Browse files Browse the repository at this point in the history
FTI-6419

(cherry picked from commit 17836b4)
  • Loading branch information
tysoekong authored and github-actions[bot] committed Jan 15, 2025
1 parent 76fe0c9 commit 23268dd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
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

0 comments on commit 23268dd

Please sign in to comment.