外观
Chats-多模态
约 489 字大约 2 分钟
2025-06-19
请求方式类似与其他对话模型, 仅请求参数稍有变化. 此处仅列出有变化的参数.
请求方式: POST
请求地址: /chat/completions
请求参数:
- model: 必选 , 模型名, 值为:
qwen2.5-vl:72b
- messages: 必选 , 推理请求消息结构, list类型, 可通过
url
或base64
两种方式传递图像:传入图像 URL, 举例如下:
curl -X POST 'https://uni-api.cstcloud.cn/v1/chat/completions' \ -H "Content-Type: application/json" \ -H "Authorization: Bearer {Token}" \ -d '{ "model": "qwen2.5-vl:72b", "messages": [ { "role":"system", "content":[ {"type": "text", "text": "You are a helpful assistant."} ] }, { "role": "user", "content": [ { "type": "image_url", "image_url": {"url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"} }, {"type": "text", "text": "图中描绘的是什么景象?"} ] } ] }'
传入图像 base64, 举例如下:
import OpenAI from "openai"; import { readFileSync } from 'fs'; const openai = new OpenAI( { // 若没有配置环境变量,请用API Key将下行替换为:apiKey: "xxx" apiKey: process.env.CSTCloud_API_KEY, baseURL: "https://uni-api.cstcloud.cn/v1/chat/completions" } ); const encodeImage = (imagePath) => { const imageFile = readFileSync(imagePath); return imageFile.toString('base64'); }; // 将xxx/eagle.png替换为你本地图像的绝对路径 const base64Image = encodeImage("xxx/eagle.png") async function main() { const completion = await openai.chat.completions.create({ model: "qwen2.5-vl:72b", messages: [ { "role": "system", "content": [{"type":"text","text": "You are a helpful assistant."}] }, { "role": "user", "content": [ { "type": "image_url", // 需要注意,传入Base64,图像格式(即image/{format})需要与支持的图片列表中的Content Type保持一致。 // PNG图像: data:image/png;base64,${base64Image} // JPEG图像: data:image/jpeg;base64,${base64Image} // WEBP图像: data:image/webp;base64,${base64Image} "image_url": {"url": `data:image/png;base64,${base64Image}`}, }, { "type": "text", "text": "图中描绘的是什么景象?" } ] } ] }); console.log(completion.choices[0].message.content); } main();
可在一次请求中同时输入多张图像, 模型会根据传入的全部图像进行回答, 传入方式为图像 URL
或base64
, 也支持二者组合传入, 下面例子为使用图像 URL
:
curl -X POST 'https://uni-api.cstcloud.cn/v1/chat/completions' \
-H "Content-Type: application/json" \
-H "Authorization: Bearer {Token}" \
-d '{
"model": "qwen2.5-vl:72b",
"messages": [
{
"role": "system",
"content": [{"type": "text", "text": "You are a helpful assistant."}]
},
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {
"url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"
}
},
{
"type": "image_url",
"image_url": {
"url": "https://dashscope.oss-cn-beijing.aliyuncs.com/images/tiger.png"
}
},
{
"type": "text",
"text": "这些图描绘了什么内容?"
}
]
}
]
}'