Files
QingLong/AI/WxMini/Test/X1_ReadImage.py

29 lines
1009 B
Python
Raw Normal View History

2025-08-15 09:13:13 +08:00
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 秒