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)


相关推荐
YYDataV数据可视化2 小时前
【P2P音视频通信系统】之信令服务器详解
服务器·音视频·p2p·信令服务器
二十画~书生2 小时前
ESP32-S3音频板
经验分享·单片机·音视频·硬件工程·pcb工艺
zymill2 小时前
hysAnalyser和flvAnalyser对比
音视频·实时音视频·视频编解码·h.264·智能电视·视频分析·mpeg-2
野指针YZZ2 小时前
Gstreamer插入第三方plugins流程:rgaconvert
linux·音视频·rk3588
YYDataV数据可视化2 小时前
【P2P音视频通信系统】webrtc 之 SDP 详解
音视频·webrtc·sdp
YYDataV数据可视化20 小时前
音视频呼叫完整时序图
音视频
mseaspring21 小时前
35.7k Star的开源项目,用Claude Code 调用Remotion 以编程的方式自动生成视频
音视频
BryanGG1 天前
[教程]通用稳定器运镜技巧
音视频·稳定器·运镜
YYDataV数据可视化1 天前
【音视频通话系统】架构详解
音视频·webrtc·实时音视频