Query @azure/openai with images?

题意 :使用图像与@azure/openai进行交互或查询

问题背景:

On chat.openai.com I can upload an image and ask chatgpt a question about it, with the existing openai and @azure/openai api however there doesn't seem to be a way to do this? The ChatCompletion object in both cases only take text prompts.

在chat.openai.com上,我可以上传一张图片并就它向ChatGPT提问,但是使用现有的openai和@azure/openai API时,似乎没有办法做到这一点?在这两种情况下,ChatCompletion对象都只接受文本提示。

Is this feautre supported at an api level?

这个特性在API级别上得到支持吗?

问题解决:

With OpenAI you just include your image as part of the message that you supply. Here is a piece from the code I use, which works whether you have an image or not:

在使用OpenAI时,你只需要将你的图像作为你提供消息的一部分包含进来。下面是我使用的一段代码,无论你是否有图像,它都能正常工作。

cs 复制代码
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})

And then 然后

cs 复制代码
payload = {
    "model": model_name,
    "temperature": temperature,
    "max_tokens": tokens,
    "messages": messages
}

where encode_image() is defined: encode_image() 函数是在哪里定义的?

cs 复制代码
def encode_image(image_path):
    with open(image_path, "rb") as image_file:
        return base64.b64encode(image_file.read()).decode('utf-8')

Currently you need to target OpenAI model gpt-4-vision-preview. Update: As @Michael suggests, it also works with gpt-4o.

目前你需要将目标设定为OpenAI的模型gpt-4-vision-preview。更新:如@Michael所建议的,它也适用于gpt-4o

相关推荐
deephub4 小时前
2026 RAG 选型指南:Vector、Graph、Vectorless 该怎么挑
人工智能·python·大语言模型·rag
视觉&物联智能5 小时前
【杂谈】-当人工智能能力增速凌驾于安全管控模型之上
人工智能·安全·ai·chatgpt·agi·deepseek
AiTop1005 小时前
Claude Code 推出 Agent View:命令行编程正式进入“多线程并发“时代
开发语言·人工智能·ai·aigc
AiTop1006 小时前
商汤发布SenseNova 6.7 Flash-Lite:原生多模态架构打破“视觉转文本“瓶颈,Token消耗直降 60%
人工智能·ai·架构
狐狐生风6 小时前
使用 UV 创建并运行 Python 项目(完整步骤)
python·uv
噜噜噜阿鲁~6 小时前
python学习笔记 | 9.2、模块-安装第三方模块
笔记·python·学习
现代野蛮人6 小时前
【深度学习】 —— VGG-16 网络实现猫狗识别
网络·人工智能·python·深度学习·tensorflow
一个小猴子`6 小时前
Pytorch快速复习
人工智能·pytorch·python
老王谈企服7 小时前
2026制造业供应链韧性提升,智能化将成为核心解决方案吗?基于实在Agent的端到端自动化实践
运维·人工智能·ai·自动化
wang3zc7 小时前
mysql如何提升InnoDB写入性能_对比MyISAM的写入锁机制
jvm·数据库·python