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
  • Loading branch information
tysoekong authored Jan 15, 2025
1 parent e9510e9 commit 17836b4
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

1 comment on commit 17836b4

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel Build

Docker image available kong/kong-dev:17836b48336e386a40084c38e2b5bc7547a33c78
Artifacts available https://github.com/Kong/kong/actions/runs/12785077268

Please sign in to comment.