ZyphrZero
commited on
Commit
·
b89a724
1
Parent(s):
5f0cafd
✨ tests(model): 添加多模态功能测试用例,验证模型对图像和文本的处理能力
Browse files
tests/test_multimodal_quick.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
glm-4.5v 多模态功能测试
|
| 3 |
+
"""
|
| 4 |
+
import requests
|
| 5 |
+
import json
|
| 6 |
+
|
| 7 |
+
# 创建一个1x1像素的红色图片作为测试
|
| 8 |
+
tiny_red_image = (
|
| 9 |
+
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8DwHwAFBQIAX8jx0gAAAABJRU5ErkJggg=="
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
# API配置
|
| 13 |
+
api_url = "http://localhost:8080/v1/chat/completions"
|
| 14 |
+
api_key = "sk-your-api-key"
|
| 15 |
+
|
| 16 |
+
# 构建正确的多模态请求
|
| 17 |
+
request_data = {
|
| 18 |
+
"model": "glm-4.5v", # 使用多模态模型
|
| 19 |
+
"messages": [
|
| 20 |
+
{
|
| 21 |
+
"role": "user",
|
| 22 |
+
"content": [ # content必须是数组
|
| 23 |
+
{
|
| 24 |
+
"type": "text",
|
| 25 |
+
"text": "这是什么颜色的图片?"
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"type": "image_url",
|
| 29 |
+
"image_url": {
|
| 30 |
+
"url": tiny_red_image
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
]
|
| 34 |
+
}
|
| 35 |
+
],
|
| 36 |
+
"stream": False
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
print("发送的请求:")
|
| 40 |
+
print(json.dumps(request_data, indent=2, ensure_ascii=False))
|
| 41 |
+
print("\n" + "="*60)
|
| 42 |
+
|
| 43 |
+
# 发送请求
|
| 44 |
+
headers = {
|
| 45 |
+
"Authorization": f"Bearer {api_key}",
|
| 46 |
+
"Content-Type": "application/json"
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
try:
|
| 50 |
+
response = requests.post(api_url, json=request_data, headers=headers)
|
| 51 |
+
print(f"响应状态码: {response.status_code}")
|
| 52 |
+
|
| 53 |
+
if response.status_code == 200:
|
| 54 |
+
result = response.json()
|
| 55 |
+
print("\n模型回复:")
|
| 56 |
+
print(result["choices"][0]["message"]["content"])
|
| 57 |
+
else:
|
| 58 |
+
print("\n错误响应:")
|
| 59 |
+
print(response.text)
|
| 60 |
+
|
| 61 |
+
except Exception as e:
|
| 62 |
+
print(f"\n发生错误: {e}")
|