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)


相关推荐
reasonsummer1 天前
【教学类-160-11】20260419 AI视频培训-练习011“豆包AI视频《佛源植语》+豆包图片风格:无(关键词:藏传唐卡)”
数据库·音视频·豆包
彷徨而立1 天前
音频编码格式 G.729 和 G.729A 的区别
音视频
EasyDSS1 天前
私有化视频会议平台/视频直播点播/高清点播/音视频点播EasyDSS“直播+点播+会议”全场景融合解锁视频协作新体验
音视频
EasyDSS1 天前
企业级融媒体生产管理平台/私有化音视频系统EasyDSS一体化架构打造全流程应急指挥视频会议体系
架构·音视频·媒体
视频技术分享1 天前
音视频SDK深度解析:技术演进、核心要点与发展前景
音视频
大蚂蚁2号1 天前
本地视频转文字|video2text
python·音视频·视频转文本
肖爱Kun1 天前
wvp-GB28181服务器网页报错调试
音视频
byte轻骑兵1 天前
【LE Audio】BASS精讲[4]: 控制点解析,广播接收指令交互全流程
人工智能·音视频·语音识别·le audio·低功耗音频
ai产品老杨1 天前
告别协议碎片化:基于 GB28181 与 RTSP 的统一 AI 视频中台架构实现(附 Docker 源码交付方案)
人工智能·架构·音视频
code 小楊1 天前
最新快乐马视频模型深度解析:特性、对比测试与完整使用教程
大数据·人工智能·音视频