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.
from openai import OpenAI
from WxMini . Milvus . Config . MulvusConfig import *
client = OpenAI (
# 若没有配置环境变量, 请用百炼API Key将下行替换为: api_key="sk-xxx"
api_key = MODEL_API_KEY ,
base_url = " https://dashscope.aliyuncs.com/compatible-mode/v1 "
)
messages = [
{
" role " : " system " ,
" content " : [ { " type " : " text " , " text " : " You are a helpful assistant. " } ] } ,
{
" role " : " user " ,
" content " : [
{
" type " : " image_url " ,
" image_url " : {
" url " : " https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg "
} ,
} ,
{ " type " : " text " , " text " : " 图中描绘的是什么景象? " } ,
] ,
}
]
completion = client . chat . completions . create (
model = " qwen-vl-max-latest " ,
messages = messages ,
)
print ( f " 第一轮输出: { completion . choices [ 0 ] . message . content } " )
assistant_message = completion . choices [ 0 ] . message
messages . append ( assistant_message . model_dump ( ) )
messages . append ( {
" role " : " user " ,
" content " : [
{
" type " : " text " ,
" text " : " 做一首诗描述这个场景 "
}
]
} )
completion = client . chat . completions . create (
model = " qwen-vl-max-latest " ,
messages = messages ,
)
print ( f " 第二轮输出: { completion . choices [ 0 ] . message . content } " )