qwen3.5 文字、图像、视频多模态openai接口案例

参考:

https://qwen.ai/blog?id=qwen3.5

文本

bash 复制代码
from openai import OpenAI
import os


client = OpenAI(
    api_key="sk-",
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",

)

messages = [{"role": "user", "content": "Introduce Qwen3.5."}]

model = os.environ.get(
    "DASHSCOPE_MODEL",
    "qwen3.5-plus",
)
completion = client.chat.completions.create(
    model=model,
    messages=messages,
    extra_body={
        "enable_thinking": True,
        "enable_search": False
    },
    stream=True
)

reasoning_content = ""  # Full reasoning trace
answer_content = ""  # Full response
is_answering = False  # Whether we have entered the answer phase
print("\n" + "=" * 20 + "Reasoning" + "=" * 20 + "\n")

for chunk in completion:
    if not chunk.choices:
        print("\nUsage:")
        print(chunk.usage)
        continue

    delta = chunk.choices[0].delta

    # Collect reasoning content only
    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

    # Received content, start answer phase
    if hasattr(delta, "content") and delta.content:
        if not is_answering:
            print("\n" + "=" * 20 + "Answer" + "=" * 20 + "\n")
            is_answering = True
        print(delta.content, end="", flush=True)
        answer_content += delta.content

图像、视频

bash 复制代码
messages = [
    {
        "role": "user",
        "content": [
            {
                "type": "image_url",
                "image_url": {
                    "url": "https://qianwen-res.oss-accelerate.aliyuncs.com/Qwen3.5/demo/CI_Demo/mathv-1327.jpg"
                }
            },
            {
                "type": "text",
                "text": "The centres of the four illustrated circles are in the corners of the square. The two big circles touch each other and also the two little circles. With which factor do you have to multiply the radii of the little circles to obtain the radius of the big circles?\nChoices:\n(A) $\\frac{2}{9}$\n(B) $\\sqrt{5}$\n(C) $0.8 \\cdot \\pi$\n(D) 2.5\n(E) $1+\\sqrt{2}$"
            }
        ]
    }
]

chat_response = client.chat.completions.create(
    model="qwen3.5-plus",
    messages=messages,
    max_tokens=65536,
    temperature=0.6,
    top_p=0.95,
    extra_body={
        "top_k": 20,
    }, 
)
print("Chat response:", chat_response)


bash 复制代码
messages = [
    {
        "role": "user",
        "content": [
            {
                "type": "video_url",
                "video_url": {
                    "url": "https://qianwen-res.oss-accelerate.aliyuncs.com/Qwen3.5/demo/video/N1cdUjctpG8.mp4"
                }
            },
            {
                "type": "text",
                "text": "How many porcelain jars were discovered in the niches located in the primary chamber of the tomb?"
            }
        ]
    }
]

# When vLLM is launched with `--media-io-kwargs '{"video": {"num_frames": -1}}'`,
# video frame sampling can be configured via `extra_body` (e.g., by setting `fps`).
# This feature is currently supported only in vLLM.
#
# By default, `fps=2` and `do_sample_frames=True`.
# With `do_sample_frames=True`, you can customize the `fps` value to set your desired video sampling rate.
chat_response = client.chat.completions.create(
    model="qwen3.5-plus",
    messages=messages,
    max_tokens=65536,
    temperature=0.6,
    top_p=0.95,
    extra_body={
        "top_k": 20,
        "mm_processor_kwargs": {"fps": 2, "do_sample_frames": True},
    }, 
)

print("Chat response:", chat_response)


相关推荐
_李小白20 小时前
【AI大模型学习笔记之平台篇】第二篇:Gemini
人工智能·音视频
Smoothcloud润云1 天前
Seedance 2.0深度解析:从“抽卡地狱”到工业化视频创作的革命
大数据·人工智能·计算机视觉·语言模型·ai作画·音视频·语音识别
凉拌菜1 天前
术野摄像机在手术影像系统中的位置与系统架构分析
音视频·医疗视频·4k视频·术野摄像机·手术影像系统·手术头灯摄像
gujunge1 天前
Spring with AI (3): 定制对话——Prompt模板引入
ai·大模型·llm·openai·qwen·rag·spring ai·deepseek
Be for thing1 天前
Android 音频硬件(Codec / 喇叭 / 麦克风)原理 + 功耗与问题定位实战(手机 / 手表通用)
android·学习·智能手机·音视频
ai产品老杨1 天前
终结协议孤岛:基于GB28181/RTSP融合网关的多品牌设备统一接入与边缘推流方案
人工智能·docker·架构·kubernetes·音视频
于先生吖1 天前
JAVA国际版图文短视频交友系统源码:多语言适配,短视频+图文双形态可商用
java·音视频·交友
唯创知音1 天前
WT2003H4系列:从芯片到模块,音频方案一站式解决
音视频·mp3解码芯片·音频解码芯片·语音播报芯片·wt2003h4
村中少年1 天前
本地模型工具ollama配置使用openclaw指南
llm·nodejs·虚拟机·qwen·ollama·openclaw
AF_INET61 天前
RV1126B开发板学习篇(一)MPP的编译和基础使用
经验分享·音视频·嵌入式·视频编解码·rv1126·mpp编解码·rockchipmpp