最近更新时间:2026-02-05 20:51:55
您在需要模型进行结构化输出时,需要在请求时配置response_format参数,来指定模型输出JSON格式内容。设置参数后,需要在提示词或系统提示词中做出明确要求,以JSON格式进行输出。已支持的输出形式为json_object。
request
curl --location 'https://kspmas.ksyun.com/v1/chat/completions' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer $KSC_API_KEY' \
-d '{
"model": "deepseek-v3.2",
"messages": [
{"role": "user", "content": "以JSON形式输出今天是星期几以及日期、月份、年份,进行联网搜索确定今天的日期"}
],
"response_format":{
"type": "json_object"
},
"tools": [
{"type": "web_search"}
]
}'response
{
"id": "as-nwqwd8z6ek",
"object": "chat.completion",
"created": 1770295599,
"model": "deepseek-v3.2",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "{\n \"weekday\": \"星期四\",\n \"date\": 5,\n \"month\": 2,\n \"year\": 2026\n}"
},
"finish_reason": "stop",
"flag": 0
}
],
"usage": {
"prompt_tokens": 5359,
"completion_tokens": 33,
"total_tokens": 5392,
"web_search_queries": 1
}
}
纯净模式
