跳转到主要内容
三方模型

Unisound-千问AI平台

本文档介绍如何调用千问AI平台部署的云知声 U2 系列模型推理服务。

模型体验:您可以前往模型市场体验云知声模型效果。

服务接入地址

SDK 调用配置的 base_urlhttps://dashscope.aliyuncs.com/compatible-mode/v1 HTTP 请求地址:POST https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions 前提条件 您需要已开通千问AI平台服务并完成 API Key 的创建。如果通过 SDK 调用,需要安装对应 SDK。

快速开始

unisound/unisound-u2 是云知声直供的推理模型,默认开启思考模式。通过 thinking 参数控制是否开启思考模式:传入 {"type": "enabled"} 开启,传入 {"type": "disabled"} 关闭;通过 reasoning_effort 控制思考强度。
thinkingreasoning_effort 非 OpenAI 标准参数,OpenAI Python SDK 通过 extra_body 传入,Node.js SDK 作为顶层参数传入。
  • Python
  • Node.js
  • HTTP
from openai import OpenAI
import os

client = OpenAI(
  api_key=os.getenv("DASHSCOPE_API_KEY"),
  base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)

messages = [{"role": "user", "content": "9.9和9.11哪个大?"}]
completion = client.chat.completions.create(
  model="unisound/unisound-u2",
  messages=messages,
  stream=True,
  stream_options={
    "include_usage": True
  },
  extra_body={
    "thinking": {"type": "enabled"},
    "reasoning_effort": "xhigh"
  }
)

reasoning_content = ""
answer_content = ""
is_answering = False
print("\n" + "=" * 20 + "思考过程" + "=" * 20 + "\n")

for chunk in completion:
  if not chunk.choices:
    print("\n" + "=" * 20 + "Token 消耗" + "=" * 20 + "\n")
    print(chunk.usage)
    continue

  delta = chunk.choices[0].delta

  if hasattr(delta, "reasoning_content") and delta.reasoning_content is not None:
    if not is_answering:
      print(delta.reasoning_content, end="", flush=True)
    reasoning_content += delta.reasoning_content

  if hasattr(delta, "content") and delta.content:
    if not is_answering:
      print("\n" + "=" * 20 + "完整回复" + "=" * 20 + "\n")
      is_answering = True
    print(delta.content, end="", flush=True)
    answer_content += delta.content

返回结果

====================思考过程====================

用户想比较 9.9 和 9.11 的大小。
把两个数对齐小数位:9.9 = 9.90,9.11 = 9.11。
比较小数部分:0.90 > 0.11,所以 9.9 更大。
====================完整回复====================

9.9 更大。

将两个数对齐小数位后比较:9.9 = 9.90,9.11 = 9.11。小数部分 0.90 > 0.11,因此 9.9 > 9.11。
====================Token 消耗====================

CompletionUsage(completion_tokens=96, prompt_tokens=10, total_tokens=106, prompt_tokens_details={'cached_tokens': 0})

功能支持

功能

支持情况

备注

多轮对话

支持

-

Function Calling

支持

不支持通过 tool_stream 以流式方式返回工具入参

结构化输出

支持

response_format 仅支持 {"type": "text"}{"type": "json_object"},不支持 json_schema

联网搜索

不支持

-

多模态输入

不支持

仅支持文本输入

参数差异

unisound/unisound-u2 不支持以下参数:nstoppreserve_thinkingthinking_budgettool_streamenable_code_interpreterenable_searchsearch_optionsskill 支持的参数中,部分参数取值范围与功能存在差异:

参数

千问AI平台

U2

temperature

取值范围 [0, 2)

取值范围 [0, 2),默认 1.0

top_k

取值为大于或等于 0 的整数;设为 null 或大于 100 时禁用 top_k 策略

取值必须为大于或等于 1 的整数,默认 40

thinking

通过 enable_thinking 控制是否开启思考模式

默认开启思考模式;通过 thinking(取值 {"type": "enabled"}{"type": "disabled"})控制是否开启思考模式,并通过 reasoning_effort 控制思考强度

错误码

如果模型调用失败并返回报错信息,请参见错误码进行解决。