Multimodale Bilderkennung (Vision)
GLM-4V Serien-Multimodalmodell mit Unterstützung für Bildverständnis und visuelle Fragebeantwortung.
API-Endpunkte
POST
/chat/completionsMultimodaler Dialog
Anfrageparameter
| Parameter | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
model | string | Erforderlich | Modellname: GLM-4V, GLM-4V-Plus |
messages | array | Erforderlich | Nachrichtenliste, Inhalt kann Text und image_url enthalten |
temperature | number | Optional | Sampling-Temperatur, Standard 0,7 |
max_tokens | integer | Optional | Maximale Anzahl der zu generierenden Tokens |
Anfrage-Beispiel
Anfrage-Beispiel
{
"model": "GLM-4V-Plus",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "这张图片里有什么?"
},
{
"type": "image_url",
"image_url": {
"url": "https://example.com/image.jpg"
}
}
]
}
]
}Antwort-Beispiel
Antwort-Beispiel
{
"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
}
}Code-Beispiele
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"}
}
]
}
]
}'