阿里云 DashScope Provider 实现
实现 ILLMProvider 协议,使用原生 DashScope API。
API 文档:https://help.aliyun.com/zh/model-studio/dashscope-api-reference/
支持的模型:
使用示例:
(require '[im.ttalk.agent.provider.dashscope :as dashscope])
(def provider (dashscope/create-provider))
;; 同步调用 (dashscope/call-dashscope config messages tools)
阿里云 DashScope Provider 实现 实现 ILLMProvider 协议,使用原生 DashScope API。 API 文档:https://help.aliyun.com/zh/model-studio/dashscope-api-reference/ 支持的模型: - Qwen Max 系列: qwen3-max, qwen-max, qwen-max-latest - Qwen Plus 系列: qwen-plus, qwen-plus-latest - Qwen Turbo 系列: qwen-turbo, qwen-turbo-latest - Qwen Coder 系列: qwen3-coder-plus, qwen-coder-plus - QwQ 系列: qwq-plus 使用示例: (require '[im.ttalk.agent.provider.dashscope :as dashscope]) (def provider (dashscope/create-provider)) ;; 同步调用 (dashscope/call-dashscope config messages tools)
(call-dashscope config messages tools)(call-dashscope config messages tools opts)调用DashScope API(同步)
参数:
返回: 统一格式响应(OpenAI 兼容格式)
示例: (call-dashscope {:model "qwen-plus" :max-tokens 4096} [{:role "user" :content "你好"}] [])
调用DashScope API(同步)
参数:
- config: 配置 map {:model "qwen-plus" :max-tokens 4096 ...}
- messages: 消息列表 [{:role "user" :content "..."}]
- tools: 工具列表
返回:
统一格式响应(OpenAI 兼容格式)
示例:
(call-dashscope
{:model "qwen-plus" :max-tokens 4096}
[{:role "user" :content "你好"}]
[])(call-dashscope-async config messages tools callback)(call-dashscope-async config messages tools callback opts)异步调用DashScope API
参数:
返回: nil(结果通过 callback 返回)
异步调用DashScope API 参数: - config: 配置 map - messages: 消息列表 - tools: 工具列表 - callback: 回调函数 (fn [response] ...) - opts: 选项 map 返回: nil(结果通过 callback 返回)
(call-dashscope-stream config messages tools on-token opts)调用 DashScope API(原生流式 SSE)。on-token 随每个增量实时触发,返回最终响应 (与同步 call-dashscope 同形的 OpenAI 兼容 map)。
走 java.net.http 真增量传输(stream-client);登记在途 cancel 供 chat-stream 取消。
调用 DashScope API(原生流式 SSE)。on-token 随每个增量实时触发,返回最终响应 (与同步 call-dashscope 同形的 OpenAI 兼容 map)。 走 java.net.http 真增量传输(stream-client);登记在途 cancel 供 chat-stream 取消。
(create-provider)(create-provider opts)创建 DashScope Provider 实例
参数:
环境变量:DASHSCOPE_API_KEY
返回: DashScopeProvider record
示例: (def provider (create-provider)) (def provider (create-provider {:api-key "sk-..."}))
创建 DashScope Provider 实例
参数:
- opts: API 选项(可选)
{:api-key "..." ;; 覆盖环境变量
:base-url "..." ;; 覆盖默认 URL}
环境变量:DASHSCOPE_API_KEY
返回:
DashScopeProvider record
示例:
(def provider (create-provider))
(def provider (create-provider {:api-key "sk-..."}))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 |