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.
|
|
|
import json
|
|
|
|
|
|
|
|
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",
|
|
|
|
#"content": "做水煮鱼一般用什么鱼"
|
|
|
|
"content":"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('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)
|