创建聊天识图 (流式)
POST/v1/chat/completions 创建聊天识图(流式)
POST https://www.vortapapi.com/v1/chat/completions
通过 Chat Completions 接口提交对话消息,模型会根据输入内容生成回复。该接口兼容 OpenAI Chat Completions API,可用于文本对话,也可用于包含图片内容的多模态识图场景。
当启用流式输出时,服务会以增量事件的形式持续返回模型生成的内容,适合需要边生成边展示的应用。
参考接口规范:https://platform.openai.com/docs/api-reference/chat/create
请求头
| 名称 | 必填 | 说明 |
|---|---|---|
Content-Type | 是 | 请求体格式,通常为 application/json |
Accept | 是 | 响应格式;流式请求通常可使用 text/event-stream |
Authorization | 否 | API 鉴权信息,格式为 Bearer sk-*** |
请求示例
curl https://www.vortapapi.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
-H "Authorization: Bearer sk-***" \
-d '{
"model": "gpt-4o-mini",
"stream": true,
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "请描述这张图片中的内容。"
},
{
"type": "image_url",
"image_url": {
"url": "https://example.com/image.jpg"
}
}
]
}
]
}'
响应示例
非流式响应示例:
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "\n\nHello there, how may I assist you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 9,
"completion_tokens": 12,
"total_tokens": 21
}
}
流式响应示例:
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"choices":[{"index":0,"delta":{"content":"这张图片"},"finish_reason":null}]}
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"choices":[{"index":0,"delta":{"content":"展示了一个场景。"},"finish_reason":null}]}
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]