构建LangChain应用程序的示例代码:49、如何使用 OpenAI 的 GPT-4 和 LangChain 库实现多模态问答系统

! pip install "openai>=1" "langchain>=0.0.331rc2" matplotlib pillow

加载图像

我们将图像编码为 base64 字符串,如 OpenAI GPT-4V 文档中所述。

import base64
import io
import os

import numpy as np
from IPython.display import HTML, display
from PIL import Image

def encode_image(image_path):
    """获取图像的 base64 字符串"""

    with open(image_path, "rb") as image_file:
        return base64.b64encode(image_file.read()).decode("utf-8")

def plt_img_base64(img_base64):
    """显示 base64 图像"""

    # 使用 base64 字符串创建 HTML img 标签
    image_html = 

你可能感兴趣的:(langchain,人工智能,AI编程)