中立消息 ↔ Anthropic wire 格式 转换
neutral->wire: 中立消息列表 → {:system .. :messages ..} response->neutral: Anthropic 响应 → 中立 assistant 消息
Anthropic wire 形态:
多模态:user 消息的 :content 为中立部件向量(见 model/content)时翻译成 Anthropic 内容块——image/* → image 块(内联 base64 source / url source)、 application/pdf → document 块。Anthropic 不收音频,遇到即抛 :validation-error (不静默丢内容)。:type 为字符串的元素视为 Anthropic 原生块(citations 的 document、cache_control 断点等),原样透传。
assistant 消息带 :blocks {:format :anthropic-content :data [...]} 时原样吐回 (thinking 块 + signature 必须逐字回传);格式认不出或没有 :blocks 就走 text + tool_use 重建。见 docs/provider-variant-design.md。
中立消息 ↔ Anthropic wire 格式 转换
neutral->wire: 中立消息列表 → {:system .. :messages ..}
response->neutral: Anthropic 响应 → 中立 assistant 消息
Anthropic wire 形态:
- system 是顶层参数(不在 messages 里)
- user: {:role "user" :content "..."}
- assistant: {:role "assistant" :content "..."}
- assistant+tools: {:role "assistant"
:content [{:type "text" :text ..}?
{:type "tool_use" :id .. :name .. :input {..}}]}
- tool result: {:role "user"
:content [{:type "tool_result" :tool_use_id .. :content ..}]}
连续的 tool 结果合并进同一条 user 消息的 content 数组。
**多模态**:user 消息的 :content 为中立部件向量(见 model/content)时翻译成
Anthropic 内容块——image/* → image 块(内联 base64 source / url source)、
application/pdf → document 块。Anthropic 不收音频,遇到即抛 :validation-error
(不静默丢内容)。:type 为**字符串**的元素视为 Anthropic 原生块(citations 的
document、cache_control 断点等),原样透传。
assistant 消息带 :blocks {:format :anthropic-content :data [...]} 时**原样吐回**
(thinking 块 + signature 必须逐字回传);格式认不出或没有 :blocks 就走
text + tool_use 重建。见 docs/provider-variant-design.md。中立消息 ↔ OpenAI wire 格式 转换
neutral->wire: 中立消息列表 → OpenAI chat messages response->neutral: OpenAI 响应 → 中立 assistant 消息
OpenAI wire 形态:
多模态:user 消息的 :content 为中立部件向量(见 model/content)时, 按 media type 顶层类别翻译——image/* → image_url(内联走 data URI)、 audio/* → input_audio(仅 wav/mp3,OpenAI 不收 URL 音频)、 application/pdf → file.file_data。其余类型不静默丢,抛 :validation-error。 :type 为字符串的元素视为 OpenAI 原生块,原样透传。
中立消息 ↔ OpenAI wire 格式 转换
neutral->wire: 中立消息列表 → OpenAI chat messages
response->neutral: OpenAI 响应 → 中立 assistant 消息
OpenAI wire 形态:
- system/user: {:role "system"/"user" :content "..."}
- assistant: {:role "assistant" :content "..."}
- assistant+tools: {:role "assistant" :content nil
:tool_calls [{:id .. :type "function"
:function {:name .. :arguments "{json}"}}]}
- tool result: {:role "tool" :tool_call_id .. :content "..."}
**多模态**:user 消息的 :content 为中立部件向量(见 model/content)时,
按 media type 顶层类别翻译——image/* → image_url(内联走 data URI)、
audio/* → input_audio(仅 wav/mp3,OpenAI 不收 URL 音频)、
application/pdf → file.file_data。其余类型不静默丢,抛 :validation-error。
:type 为**字符串**的元素视为 OpenAI 原生块,原样透传。中立消息 ↔ OpenAI Responses API wire 格式转换。
OpenAI Responses 与 Chat Completions 的差别在协议形状,不在语义: system -> instructions;消息 -> input items;工具定义扁平化; function_call / function_call_output 是顶层 item。
中立消息 ↔ OpenAI Responses API wire 格式转换。 OpenAI Responses 与 Chat Completions 的差别在协议形状,不在语义: system -> instructions;消息 -> input items;工具定义扁平化; function_call / function_call_output 是顶层 item。
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |