开始使用
POST
https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions
前提条件
使用方法
response_format
为{"type": "json_object"}
。'messages' must contain the word 'json' in some form, to use 'response_format' of type 'json_object'.
建议您在提示词中说明每个属性的数据类型,并提供样例给大模型参考。
请求示例请求示例
Shell
JavaScript
Java
Swift
curl --location --request POST 'https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions' \
--header 'Authorization: Bearer {{DASHSCOPE_API_KEY}}' \
--header 'Content-Type: application/json' \
--data-raw '{
"model": "qwen-plus",
"messages": [
{
"role": "system",
"content": "你需要提取出name(名字,为string类型)、age(年龄,为string类型)与email(邮箱,为string类型),请输出JSON 字符串,不要输出其它无关内容。\n示例:\nQ:我叫张三,今年25岁,邮箱是zhangsan@example.com\nA:{\"name\":\"张三\",\"age\":\"25岁\",\"email\":\"zhangsan@example.com\"}\nQ:我叫李四,今年30岁,我的邮箱是lisi@example.com\nA:{\"name\":\"李四\",\"age\":\"30岁\",\"email\":\"lisi@example.com\"}\nQ:我叫王五,我的邮箱是wangwu@example.com,今年40岁\nA:{\"name\":\"王五\",\"age\":\"40岁\",\"email\":\"wangwu@example.com\""
},
{
"role": "user",
"content": "大家好,我叫刘五,今年34岁,邮箱是liuwu@example.com"
}
],
"response_format": {
"type": "json_object"
}
}'
响应示例响应示例
{
"choices": [
{
"message": {
"role": "string",
"content": "string"
},
"finish_reason": "string",
"index": 0,
"logprobs": null
}
],
"object": "string",
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0,
"prompt_tokens_details": {
"cached_tokens": 0
}
},
"created": 0,
"system_fingerprint": null,
"model": "string",
"id": "string"
}
请求参数
Header 参数
Authorization
string
必需
示例值:
Bearer {{DASHSCOPE_API_KEY}}
Content-Type
string
必需
示例值:
application/json
Body 参数application/json
返回响应
修改于 2025-02-28 10:57:00