マルチモーダル理解 (Vision)
GLM-4Vシリーズマルチモーダルモデル。画像理解と視覚的質問応答をサポート。
APIエンドポイント
POST
/chat/completionsマルチモーダル対話
リクエストパラメータ
| パラメータ | 型 | 必須 | 説明 |
|---|---|---|---|
model | string | 必須 | モデル名:GLM-4V、GLM-4V-Plus |
messages | array | 必須 | メッセージリスト。contentにはテキストとimage_urlを含めることが可能 |
temperature | number | 任意 | サンプリング温度、デフォルト0.7 |
max_tokens | integer | 任意 | 生成するトークンの最大数 |
リクエスト例
リクエスト例
{
"model": "GLM-4V-Plus",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "这张图片里有什么?"
},
{
"type": "image_url",
"image_url": {
"url": "https://example.com/image.jpg"
}
}
]
}
]
}レスポンス例
レスポンス例
{
"id": "chatcmpl-456",
"object": "chat.completion",
"created": 1677652288,
"model": "GLM-4V-Plus",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "这张图片显示的是一只可爱的猫咪..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 1200,
"completion_tokens": 80,
"total_tokens": 1280
}
}コード例
Python
from openai import OpenAI
client = OpenAI(
api_key="your-api-key",
base_url="https://your-proxy-domain.com/v1"
)
response = client.chat.completions.create(
model="GLM-4V-Plus",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "这张图片里有什么?"},
{
"type": "image_url",
"image_url": {"url": "https://example.com/image.jpg"}
}
]
}
]
)
print(response.choices[0].message.content)JavaScript
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'your-api-key',
baseURL: 'https://your-proxy-domain.com/v1'
});
async function analyzeImage() {
const response = await client.chat.completions.create({
model: 'GLM-4V-Plus',
messages: [
{
role: 'user',
content: [
{ type: 'text', text: '这张图片里有什么?' },
{
type: 'image_url',
image_url: { url: 'https://example.com/image.jpg' }
}
]
}
]
});
console.log(response.choices[0].message.content);
}
analyzeImage();cURL
curl https://your-proxy-domain.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key" \
-d '{
"model": "GLM-4V-Plus",
"messages": [
{
"role": "user",
"content": [
{"type": "text", "text": "这张图片里有什么?"},
{
"type": "image_url",
"image_url": {"url": "https://example.com/image.jpg"}
}
]
}
]
}'