跳转到主要内容
三方模型

Unisound-千问AI平台

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

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

服务接入地址

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

快速开始

unisound/unisound-u2 是云知声直供的推理模型,默认开启思考模式。通过 thinking 参数控制是否开启思考模式:传入 {"type": "enabled"} 开启,传入 {"type": "disabled"} 关闭;通过 reasoning_effort 控制思考强度。
thinking 与 reasoning_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://maas.qianwenaiapi.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 不支持以下参数:n、stop、preserve_thinking、thinking_budget、tool_stream、enable_code_interpreter、enable_search、search_options、skill。 支持的参数中,部分参数取值范围与功能存在差异:
参数千问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 控制思考强度

错误码

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