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.
29 lines
1009 B
29 lines
1009 B
import time # 导入 time 模块
|
|
from openai import OpenAI
|
|
from WxMini.Milvus.Config.MulvusConfig import *
|
|
|
|
client = OpenAI(
|
|
api_key=MODEL_API_KEY,
|
|
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
|
|
)
|
|
|
|
# 图片 URL
|
|
image_url = 'https://ylt.oss-cn-hangzhou.aliyuncs.com/Temp/james.png'
|
|
|
|
# 创建流式请求
|
|
completion = client.chat.completions.create(
|
|
model="qwen-vl-plus", # 使用 qwen-vl-plus 模型
|
|
messages=[{"role": "user", "content": [
|
|
{"type": "text", "text": "这是什么"},
|
|
{"type": "image_url", "image_url": {"url": image_url}}
|
|
]}],
|
|
stream=True # 启用流式输出
|
|
)
|
|
|
|
# 流式输出结果
|
|
print("流式输出结果:")
|
|
for chunk in completion:
|
|
if chunk.choices[0].delta.content is not None:
|
|
for char in chunk.choices[0].delta.content: # 逐个字符输出
|
|
print(char, end="", flush=True) # 逐个字符输出,不换行
|
|
time.sleep(0.1) # 控制输出速度,延迟 0.1 秒 |