Closed caster-Q closed 1 month ago
安官方文档API构造的demo:
from openai import OpenAI import base64 def encode_image(image_path): with open(image_path, "rb") as image_file: return base64.b64encode(image_file.read()).decode('utf-8') def get_response(image_path): base64_image = encode_image(image_path) print(base64_image) client = OpenAI( api_key="sk-xxxxxx", base_url="https://xxxxxx.cn/v1", ) completion = client.chat.completions.create( model="qwen-vl-plus", messages=[ { "role": "user", "content": [ { "type": "image_url", "image_url": { "url": f"data:image/jpeg;base64,{base64_image}" } }, { "type": "text", "text": "这是什么" } ] } ] ) print(completion.model_dump_json()) # completion = client.chat.completions.create( # model="qwen-vl-max", # messages=[ # {"role": "user", "content": [ # {"type": "image_url", # "image_url": {"url": "https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg"}}, # {"type": "text", "text": "这是什么"} # ]} # ] # ) # print(completion.model_dump_json()) if __name__=='__main__': get_response("/Users/caster/Desktop/dog_and_girl.jpeg")
使用http方式没有问题,使用本地文件base64报错如下: openai.BadRequestError: Error code: 400 - {'error': {'code': 'InvalidParameter', 'message': 'Provider API error: <400> InternalError.Algo.InvalidParameter: The input content is not a valid URL (request id: 20240925145547824256729Gmo1MF1U)', 'param': '528c602f-acac-9997-b5e7-c6dadc4ab500', 'type': 'InvalidParameter'}}
@caster-Q 您好,请问您是调用本地部署的模型还是官方的qwen-vl-plus?
qwen-vl-plus
@caster-Q 您好,请问您是调用本地部署的模型还是官方的qwen-vl-plus? 本地的网关转发到的官方的qwen-vl-plus
是我们这面网关的问题
安官方文档API构造的demo:
使用http方式没有问题,使用本地文件base64报错如下: openai.BadRequestError: Error code: 400 - {'error': {'code': 'InvalidParameter', 'message': 'Provider API error: <400> InternalError.Algo.InvalidParameter: The input content is not a valid URL (request id: 20240925145547824256729Gmo1MF1U)', 'param': '528c602f-acac-9997-b5e7-c6dadc4ab500', 'type': 'InvalidParameter'}}