每天会自动补充Token,可以选择的模型非常多
https://www.modelscope.cn/register?inviteCode=freetoken2208&invitorName=AIDever
魔塔的优势在于长期免费,模型选择多
from openai import OpenAI
client = OpenAI(
base_url='https://api-inference.modelscope.cn/v1',
api_key='密钥', # ModelScope Token
)
response = client.chat.completions.create(
model='ZhipuAI/GLM-5.3:Zhipu-Coding', # ModelScope Model-Id, required
messages=[{
'role':
'user',
'content': [{
'type': 'text',
'text': '描述这幅图',
}, {
'type': 'image_url',
'image_url': {
'url':
'https://modelscope.oss-cn-beijing.aliyuncs.com/demo/images/audrey_hepburn.jpg',
},
}],
}],
stream=True
)
done_reasoning = False
for chunk in response:
if chunk.choices:
reasoning_chunk = chunk.choices[0].delta.reasoning_content
answer_chunk = chunk.choices[0].delta.content
if reasoning_chunk != '':
print(reasoning_chunk, end='', flush=True)
elif answer_chunk != '':
if not done_reasoning:
print('\n\n === Final Answer ===\n')
done_reasoning = True
print(answer_chunk, end='', flush=True)
发表回复
要发表评论,您必须先登录。