Files
dsProject/dsLightRag/Test/S1_GLM41V.py

51 lines
1.7 KiB
Python
Raw Normal View History

2025-08-14 15:45:08 +08:00
import json
import requests
from Config.Config import GLM_API_KEY, GLM_MODEL_NAME, GLM_BASE_URL
url = GLM_BASE_URL
headers = {
"Authorization": "Bearer " + GLM_API_KEY,
"Content-Type": "application/json"
}
data = {
"model": GLM_MODEL_NAME,
"messages": [
{
"role": "user",
# "content": "做水煮鱼一般用什么鱼"
"content":
[
{
"type": "text",
"text": "请帮我解决这个题目给出详细过程和答案。第4问请注意F可能在三角形内部也可能出现在BC的外侧即F在三角形外两种情况需要分类讨论作答。"
},
{
"type": "image_url",
"image_url": {
"url": "https://dsideal.obs.cn-north-1.myhuaweicloud.com/HuangHai/Backup/23.jpg"
}
}
]
}
],
"stream": True # 启用流式调用
}
with requests.post(url, headers=headers, json=data, stream=True) as response:
for chunk in response.iter_lines():
if chunk:
decoded = chunk.decode('utf-8')
if decoded.startswith('[DONE]'):
print("完成!")
break
try:
decoded = decoded[5:]
json_data = json.loads(decoded)
content = json_data["choices"][0]["delta"]['content']
if content and len(content) > 0:
print(content, end="")
except Exception as e:
print(e)