You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.7 KiB

3 weeks ago
import json
3 weeks ago
import requests
url = "https://api.siliconflow.cn/v1/chat/completions"
headers = {
"Authorization": "Bearer sk-pbqibyjwhrgmnlsmdygplahextfaclgnedetybccknxojlyl",
"Content-Type": "application/json"
}
data = {
"model": "THUDM/GLM-4.1V-9B-Thinking",
"messages": [
{
"role": "user",
3 weeks ago
# "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"
}
}
]
3 weeks ago
}
3 weeks ago
],
"stream": True # 启用流式调用
3 weeks ago
}
3 weeks ago
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('data: [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)