멀티모달 이해 (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"}
}
]
}
]
}'