使用图像查询@azure/openai?

问题描述 投票:0回答:1

在chat.openai.com上,我可以使用现有的openai和@azure/openai api上传图像并向chatgpt询问有关它的问题,但是似乎没有办法做到这一点?两种情况下的 ChatCompletion 对象仅接受文本提示。

此功能在 API 级别受支持吗?

openai-api azure-openai
1个回答
0
投票

使用 openai,您只需将您的图像作为您提供的消息的一部分即可。这是我使用的代码中的一段,无论您是否有图像,它都可以工作:

if image != '':
    # Get base64 string
    base64_image = encode_image(image)
    content = [
        {
            "type": "text",
            "text": your_prompt
        },
        {
            "type": "image_url",
            "image_url": {
                "url": f"data:image/jpeg;base64,{base64_image}"
            }
        }
    ]
else:
    content = your_prompt
messages.append({"role": "user", "content": content})

然后

payload = {
    "model": model_name,
    "temperature": temperature,
    "max_tokens": tokens,
    "messages": messages
}
© www.soinside.com 2019 - 2024. All rights reserved.