Skip to content
目录

预置多模态大模型服务接口说明

接口地址:https://platform.wair.ac.cn/maas/v1/chat/completions

请求方式:post 请求

多模态大模型 Taichu-VL

请求说明

Header 参数说明

字段类型必选描述示例值
Content-Typestring请求类型application/json
AuthorizationstringAPI Key,格式为 Bearer $API_KEYBearer ayvs***vufp

Body 参数说明

参数名称类型是否必填说明
modelstring模型 code,此处为 taichu_vl
messageslist一个由历史消息组成的列表,详细说明,参照 messages 信息说明
streambool使用同步调用时,此参数应当设置为 false。表示模型生成完所有内容后一次性返回所有内容。如果设置为 true,模型将通过标准 Event Stream ,逐块返回模型生成内容。Event Stream 结束时会返回一条 data: [DONE]消息。默认值为 true
temperaturefloat生成过程中的温度值,取值范围[0.01,1.00] 闭区间,默认值为 1.0,调节最小细粒度为 0.01
top_pfloat生成过程中的 token 几率阈值取值范围是:(0.0, 1.0) 开区间,默认值为 0.9,调节最小细粒度为 0.1
repetition_penaltyfloat生成过程中的惩罚值取值范围是:(1.0, 2.0) 开区间,默认值为 1.0,调节最小细粒度为 0.1

messages 参数说明

参数名称类型是否必填说明
rolestringsystem:系统,user:用户,assistant:模型,tool:工具调用
contentstringtype 为 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 参数说明

参数名称类型说明
idstring本次请求唯一标识
modelstring本次使用的模型名称
choiceslist本次请求模型服务返回的信息
+messagesobject同步响应时,返回该字段,详细说明见 messages
+indexint当前可选路径序列号
+finish_reasonstringstop: 表示模型输出结束 length: 表示模型输出长度达到 max_tokens tool_calls: 表示模型命中函数 content_filter: 表示模型输出被安全审核拦截,针对此类内容,请用户自行判断并决定是否撤回已公开的内容。
usageobjecttoken 使用数量
+completion_tokensint内容生成的 tokens 数量
+prompt_tokensintprompt 使用的 tokens 数量
+total_tokensint总 tokens 用量
objectstring生成的聊天响应 ID
createdtimestamp生成聊天响应时的 Unix 时间戳

messages 参数说明

参数名称类型是否必填说明
rolestringsystem:系统,user:用户,assistant:模型,tool:工具调用
contentstringrole 为 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
  }
}