nic-6443 commented on code in PR #13321:
URL: https://github.com/apache/apisix/pull/13321#discussion_r3162069737


##########
apisix/plugins/ai-protocols/converters/anthropic-messages-to-openai-chat.lua:
##########
@@ -321,32 +683,81 @@ local function openai_to_anthropic_sse(openai_chunk, 
state)
             role = "assistant",
             model = openai_chunk.model,
             content = {},
-            usage = { input_tokens = 0, output_tokens = 0 }
+            usage = { input_tokens = 0, output_tokens = 0 },
         }
         setmetatable(message.content, core.json.empty_array_mt)
 
         table.insert(events, make_sse_event("message_start", {
             type = "message_start",
             message = message,
         }))
-        push_content_block_start(events, 0, { type = "text", text = "" })
 
         state.is_first = false
-        state.content_index = 0
-        state.current_open_block = 0
+        state.next_content_index = 0
+        state.current_open_block = nil
+        state.current_block_type = nil
         state.tool_call_indices = {}
     end
 
-    -- 2. Handle text content delta
+    -- Normalize finish_reason: nil, empty, "null", whitespace → no finish
+    local finish_reason
+    if choice then
+        local fr = choice.finish_reason
+        if type(fr) == "string" and fr ~= "" and fr ~= "null" then
+            -- Strip whitespace
+            local trimmed = fr:match("^%s*(.-)%s*$")
+            if trimmed and trimmed ~= "" then

Review Comment:
   Fixed in c9ecc0f - now trims first, then checks for empty/null.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to