Liking cljdoc? Tell your friends :D

im.ttalk.agent.provider.zhipu

智谱 GLM Provider —— 双协议支持。

  1. OpenAI 兼容(默认,create-provider): https://open.bigmodel.cn/api/paas/v4/chat/completions(Bearer 鉴权)

    • 思考开关:config 传 :thinking {:type "enabled"|"disabled" :clear_thinking true}(GLM-4.5+ 思考系列)
    • 思维链经 message.reasoning_content 返回,已由统一响应层归一化到 :reasoning 字段;流式推理 token 走回调 :reasoning-token
  2. Anthropic 兼容(create-anthropic-provider,官方推荐 coding/agent 场景, Claude Code 同款端点): https://open.bigmodel.cn/api/anthropic/v1/messages(Bearer 鉴权)

    • 完整复用 anthropic provider 的请求/响应/流式/工具调用/缓存/重试机制
    • 思考内容为 thinking 内容块,自动归一化到 :reasoning
  3. 异步任务(GLM 对话补全异步方案): submit-async(POST /async/chat/completions)→ query-async-result / await-async-result(GET /async-result/{id},PROCESSING|SUCCESS|FAIL)

对话补全文档字段(经 config 透传,存在才发送): :temperature :top-p :max-tokens :stop :thinking :do-sample :tool-stream :request-id :user-id :response-format :tool-choice; tools 支持简单定义(自动包装为 function)与预置类型透传 ({:type "web_search"/"retrieval"/"mcp" ...})。 finish_reason 的 sensitive/network_error/model_context_window_exceeded 已归一化(:content-filter/:error/:context-window-exceeded)。

模型:glm-5.1、glm-5-turbo、glm-5、glm-4.7、glm-4.7-flash、glm-4.6 等。 需要 ZHIPU_API_KEY 或显式 :api-key。

(require '[im.ttalk.agent.provider.zhipu :as zhipu]) (def p (zhipu/create-provider {:api-key "..."})) ;; OpenAI 协议 (def pa (zhipu/create-anthropic-provider {:api-key "..."})) ;; Anthropic 协议 ;; 异步: (let [{:keys [id]} (zhipu/submit-async {:model "glm-4.7"} msgs nil)] (zhipu/await-async-result {} id))

智谱 GLM Provider —— 双协议支持。

1. OpenAI 兼容(默认,create-provider):
   https://open.bigmodel.cn/api/paas/v4/chat/completions(Bearer 鉴权)
   - 思考开关:config 传 :thinking {:type "enabled"|"disabled"
     :clear_thinking true}(GLM-4.5+ 思考系列)
   - 思维链经 message.reasoning_content 返回,已由统一响应层归一化到
     :reasoning 字段;流式推理 token 走回调 :reasoning-token

2. Anthropic 兼容(create-anthropic-provider,官方推荐 coding/agent 场景,
   Claude Code 同款端点):
   https://open.bigmodel.cn/api/anthropic/v1/messages(Bearer 鉴权)
   - 完整复用 anthropic provider 的请求/响应/流式/工具调用/缓存/重试机制
   - 思考内容为 thinking 内容块,自动归一化到 :reasoning

3. 异步任务(GLM 对话补全异步方案):
   submit-async(POST /async/chat/completions)→ query-async-result /
   await-async-result(GET /async-result/{id},PROCESSING|SUCCESS|FAIL)

对话补全文档字段(经 config 透传,存在才发送):
:temperature :top-p :max-tokens :stop :thinking :do-sample :tool-stream
:request-id :user-id :response-format :tool-choice;
tools 支持简单定义(自动包装为 function)与预置类型透传
({:type "web_search"/"retrieval"/"mcp" ...})。
finish_reason 的 sensitive/network_error/model_context_window_exceeded
已归一化(:content-filter/:error/:context-window-exceeded)。

模型:glm-5.1、glm-5-turbo、glm-5、glm-4.7、glm-4.7-flash、glm-4.6 等。
需要 ZHIPU_API_KEY 或显式 :api-key。

(require '[im.ttalk.agent.provider.zhipu :as zhipu])
(def p (zhipu/create-provider {:api-key "..."}))            ;; OpenAI 协议
(def pa (zhipu/create-anthropic-provider {:api-key "..."})) ;; Anthropic 协议
;; 异步:
(let [{:keys [id]} (zhipu/submit-async {:model "glm-4.7"} msgs nil)]
  (zhipu/await-async-result {} id))
raw docstring

await-async-resultclj

(await-async-result config
                    task-id
                    &
                    {:keys [poll-interval-ms timeout-ms]
                     :or {poll-interval-ms 2000 timeout-ms 300000}})

轮询异步任务直至完成

选项:

  • :poll-interval-ms 轮询间隔(默认 2000)
  • :timeout-ms 总超时(默认 300000,5 分钟)

返回:SUCCESS 时的完整结果。 抛出:task_status=FAIL 或超时时抛 ex-info。

轮询异步任务直至完成

选项:
- :poll-interval-ms 轮询间隔(默认 2000)
- :timeout-ms       总超时(默认 300000,5 分钟)

返回:SUCCESS 时的完整结果。
抛出:task_status=FAIL 或超时时抛 ex-info。
sourceraw docstring

call-zhipuclj

(call-zhipu config__10075__auto__ messages__10076__auto__ tools__10077__auto__)

调用 zhipu API(同步)

调用 zhipu API(同步)
sourceraw docstring

call-zhipu-asyncclj

(call-zhipu-async config__10075__auto__
                  messages__10076__auto__
                  tools__10077__auto__)

异步调用 zhipu API(返回 deferred<响应体>)

异步调用 zhipu API(返回 deferred<响应体>)
sourceraw docstring

call-zhipu-streamclj

(call-zhipu-stream config__10075__auto__
                   messages__10076__auto__
                   tools__10077__auto__
                   on-token__10078__auto__)

流式调用 zhipu API

流式调用 zhipu API
sourceraw docstring

call-zhipu-stream-asyncclj

(call-zhipu-stream-async config__10075__auto__
                         messages__10076__auto__
                         tools__10077__auto__
                         on-token__10078__auto__)

异步流式调用 zhipu API(返回 deferred<最终响应>)

异步流式调用 zhipu API(返回 deferred<最终响应>)
sourceraw docstring

create-anthropic-providerclj

(create-anthropic-provider)
(create-anthropic-provider opts)

创建智谱 GLM Provider(Anthropic 兼容协议)。

适用 GLM-4.6/4.7/5 系列的 coding/agent 场景(与 Claude Code 接入同一端点)。 thinking 内容块、prompt-cache 策略、重试等能力与 anthropic provider 一致。

参数:

  • opts: 可选 {:api-key "..." :base-url "..." ...},作为调用 config 默认值。 缺省从 ZHIPU_API_KEY 读取 api-key。

返回:AnthropicProvider 实例(provider-name 为 :zhipu)。 api-key 缺失(空白)时抛 ExceptionInfo。

创建智谱 GLM Provider(Anthropic 兼容协议)。

适用 GLM-4.6/4.7/5 系列的 coding/agent 场景(与 Claude Code 接入同一端点)。
thinking 内容块、prompt-cache 策略、重试等能力与 anthropic provider 一致。

参数:
- opts: 可选 {:api-key "..." :base-url "..." ...},作为调用 config 默认值。
        缺省从 ZHIPU_API_KEY 读取 api-key。

返回:AnthropicProvider 实例(provider-name 为 :zhipu)。
api-key 缺失(空白)时抛 ExceptionInfo。
sourceraw docstring

create-providerclj

(create-provider)
(create-provider opts10720)

创建 zhipu Provider

创建 zhipu Provider
sourceraw docstring

default-configclj

默认 zhipu 配置

默认 zhipu 配置
sourceraw docstring

default-modelclj

source

query-async-resultclj

(query-async-result config task-id)

查询异步任务结果(GET {base}/async-result/{id})

返回:

  • PROCESSING -> {:task_status "PROCESSING" ...}
  • SUCCESS -> 含 :choices/:usage 的完整结果(与同步响应同构, 可直接走 extract-text / normalize-response)
  • FAIL -> {:task_status "FAIL" ...}

HTTP 层失败抛 ex-info。

查询异步任务结果(GET {base}/async-result/{id})

返回:
- PROCESSING -> {:task_status "PROCESSING" ...}
- SUCCESS    -> 含 :choices/:usage 的完整结果(与同步响应同构,
                可直接走 extract-text / normalize-response)
- FAIL       -> {:task_status "FAIL" ...}

HTTP 层失败抛 ex-info。
sourceraw docstring

submit-asyncclj

(submit-async config messages tools)

提交异步对话补全任务(POST {base}/async/chat/completions)

参数与同步 call-zhipu 一致(model/messages/thinking/tools 等全部字段可用, 不支持 :stream)。

返回任务回执: {:id "..." :request_id "..." :model "..." :task_status "PROCESSING"}

提交异步对话补全任务(POST {base}/async/chat/completions)

参数与同步 call-zhipu 一致(model/messages/thinking/tools 等全部字段可用,
不支持 :stream)。

返回任务回执:
{:id "..." :request_id "..." :model "..." :task_status "PROCESSING"}
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close