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.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
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 " :
[
{
" 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 ( ' 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 )