多模態輸入與理解
使用圖片或檔案作為模型輸入,並讀取文字分析結果。
概述
多模態理解將圖片或檔案作為輸入,讓模型回答問題、比較內容或擷取資訊。它與圖片、影片和音訊生成不同:理解任務讀取媒體,生成任務建立媒體。
適用任務
| 任務 | 範例 |
|---|---|
| 圖片問答 | 描述畫面並回答與圖片有關的問題 |
| 多圖比較 | 比較多張圖片的內容或差異 |
| 圖片資訊擷取 | 擷取圖片中的文字、欄位或結構化資訊 |
| 文件理解 | 總結檔案內容或根據檔案回答問題 |
協議表達
不同協議使用不同的輸入容器和內容區塊。內容區塊可由協議表達,但實際輸入能力仍取決於所選模型。
| 協議 | 輸入容器 | 圖片與檔案內容區塊 |
|---|---|---|
| OpenAI Chat | messages[].content | image_url、file |
| OpenAI Responses | input[].content | input_image、input_file |
| Anthropic Messages | messages[].content | image、document |
| Gemini Generate Content | contents[].parts | inlineData、fileData |
API 串接
Base URL
https://api.agtcloud.cn/v1圖片理解
以下範例透過 Chat Completions 提交同一張圖片。
curl 'https://api.agtcloud.cn/v1/chat/completions' \
-H 'Authorization: Bearer your-api-key' \
-H 'Content-Type: application/json' \
--data '{
"model": "MODEL_ID",
"messages": [
{
"role": "user",
"content": [
{"type": "text", "text": "請描述圖片中的主要內容。"},
{
"type": "image_url",
"image_url": {"url": "https://example.com/example.jpg"}
}
]
}
]
}'文字結果位於 choices[0].message.content。
檔案輸入
檔案輸入沒有跨協議通用的請求結構。OpenAI Chat 使用 file,Responses 使用 input_file,Anthropic Messages 使用 document,Gemini 使用 inlineData 或 fileData。請按所選協議的 API Reference 組合請求。