深色模式
预置多模态大模型服务接口说明
接口地址:https://platform.wair.ac.cn/maas/v1/chat/completions
请求方式:post 请求
多模态大模型 Taichu-VL
请求说明
Header 参数说明
字段 | 类型 | 必选 | 描述 | 示例值 |
Content-Type | string | 是 | 请求类型 | application/json |
Authorization | string | 是 | API Key,格式为 Bearer $API_KEY | Bearer ayvs***vufp |
Body 参数说明
参数名称 | 类型 | 是否必填 | 说明 |
model | string | 是 | 模型 code,此处为 taichu_vl |
messages | list | 是 | 一个由历史消息组成的列表,详细说明,参照 messages 信息说明 |
stream | bool | 否 | 使用同步调用时,此参数应当设置为 false。表示模型生成完所有内容后一次性返回所有内容。如果设置为 true,模型将通过标准 Event Stream ,逐块返回模型生成内容。Event Stream 结束时会返回一条 data: [DONE]消息。默认值为 true |
temperature | float | 否 | 生成过程中的温度值,取值范围[0.01,1.00] 闭区间,默认值为 1.0,调节最小细粒度为 0.01 |
top_p | float | 否 | 生成过程中的 token 几率阈值取值范围是:(0.0, 1.0) 开区间,默认值为 0.9,调节最小细粒度为 0.1 |
repetition_penalty | float | 否 | 生成过程中的惩罚值取值范围是:(1.0, 2.0) 开区间,默认值为 1.0,调节最小细粒度为 0.1 |
messages 参数说明
参数名称 | 类型 | 是否必填 | 说明 |
role | string | 是 | system:系统,user:用户,assistant:模型,tool:工具调用 |
content | string | 是 | type 为 text 时为用户提问信息,type 为 image_url 时为上传图片地址; |
curl 请求示例
json
curl --location 'https://platform.wair.ac.cn/maas/v1/chat/completions' \
--header 'Authorization: Bearer $API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"stream": true,
"model": "taichu_vl",
"messages": [
{
"content": [
{
"type": "text",
"text": "图片中的人口总量是多少?男性多还是女性多?"
},
{
"type": "image_url",
"image_url": {
"url": "https://zdtc-cdn.wair.ac.cn/assets/caption_2_file_1.jpeg"
}
}
],
"role": "user"
}
]
}'
Python 调用示例
非流式调用
python
import requests
if __name__ == '__main__':
params = {
"stream": False,
"model": "taichu_vl",
"messages": [
{
"content": [
{
"type": "text",
"text": "图片中的人口总量是多少?男性多还是女性多?"
},
{
"type": "image_url",
"image_url": {
"url": "https://zdtc-cdn.wair.ac.cn/assets/caption_2_file_1.jpeg"
}
}
],
"role": "user"
}
]
}
api = 'https://platform.wair.ac.cn/maas/v1/chat/completions'
headers = {'Authorization': 'Bearer $API_KEY'}
response = requests.post(api, json=params, headers=headers)
if response.status_code == 200:
print(response.json())
else:
body = response.content.decode('utf-8')
print(f'request failed,status_code:{response.status_code},body:{body}')
流式调用
python
import requests
if __name__ == '__main__':
params = {
"stream": True,
"model": "taichu_vl",
"messages": [
{
"content": [
{
"type": "text",
"text": "图片中的人口总量是多少?男性多还是女性多?"
},
{
"type": "image_url",
"image_url": {
"url": "https://zdtc-cdn.wair.ac.cn/assets/caption_2_file_1.jpeg"
}
}
],
"role": "user"
}
]
}
api = 'https://platform.wair.ac.cn/maas/v1/chat/completions'
headers = {'Authorization': 'Bearer $API_KEY'}
response = requests.post(api, json=params, headers=headers, stream=True)
if response.status_code == 200:
response.encoding = 'utf-8'
for line in response.iter_lines(decode_unicode=True):
print(line)
else:
body = response.content.decode('utf-8')
print(f'request failed,status_code:{response.status_code},body:{body}')
返回说明
Body 参数说明
参数名称 | 类型 | 说明 |
id | string | 本次请求唯一标识 |
model | string | 本次使用的模型名称 |
choices | list | 本次请求模型服务返回的信息 |
+messages | object | 同步响应时,返回该字段,详细说明见 messages |
+index | int | 当前可选路径序列号 |
+finish_reason | string | stop: 表示模型输出结束 length: 表示模型输出长度达到 max_tokens tool_calls: 表示模型命中函数 content_filter: 表示模型输出被安全审核拦截,针对此类内容,请用户自行判断并决定是否撤回已公开的内容。 |
usage | object | token 使用数量 |
+completion_tokens | int | 内容生成的 tokens 数量 |
+prompt_tokens | int | prompt 使用的 tokens 数量 |
+total_tokens | int | 总 tokens 用量 |
object | string | 生成的聊天响应 ID |
created | timestamp | 生成聊天响应时的 Unix 时间戳 |
messages 参数说明
参数名称 | 类型 | 是否必填 | 说明 |
role | string | 是 | system:系统,user:用户,assistant:模型,tool:工具调用 |
content | string | 是 | role 为 system 时为系统人设信息,role 为 user 时为用户输入信息,role 为 assistant 时为模型返回信息,role 为 tool 时为工具调用返回信息 |
返回示例
json
{
"id": "79e523f6-58e9-9257-b4ad-7e6c5ce912f6",
"object": "chat.completion",
"created": 1736507515,
"model": "taichu_vl",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "图片中的人口总量是141175万人。男性比女性多,总性别比为104.69。"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 3385,
"total_tokens": 3408,
"completion_tokens": 23
}
}