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


##########
apisix/plugins/ai-protocols/converters/anthropic-messages-to-openai-chat.lua:
##########
@@ -62,6 +63,42 @@ local function sanitize_tool_name(name)
 end
 
 
+-- Map an Anthropic tool name to the name used on the OpenAI side, recording
+-- the mapping so the response converter can restore the original name.
+-- `maps.forward` is original → openai, `maps.reverse` is openai → original.
+-- Both the `tools` array and the `tool_use` blocks in the conversation history
+-- go through here, so a tool always carries the same name in both places.
+local function openai_tool_name(name, maps)
+    local mapped = maps.forward[name]
+    if mapped then
+        return mapped
+    end
+
+    if string_len(name) <= TOOL_NAME_MAX_LEN
+            and not ngx_re_find(name, "[^a-zA-Z0-9_-]", "jo") then
+        return name
+    end

Review Comment:
   Heads-up that the fix for this changed shape in the latest push. Instead of 
reserving the already-valid names and handing out numeric suffixes, any name 
that had to be rewritten — because of an invalid character, because it was too 
long, or both — now gets `_<sha256(original)[:8]>` appended. That makes the 
collision impossible by construction rather than by bookkeeping, and it matches 
what LiteLLM's adapter emits for the over-64-char case byte for byte.
   
   Your original case still holds as a test (`get weather` vs `get_weather`), 
it just resolves to `get_weather_dce3870e` and `get_weather` now.



-- 
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