Maplemx / Agently

[AI Agent Application Development Framework] - 🚀 Build AI agent native application in very few code 💬 Easy to interact with AI agent in code using structure data and chained-calls syntax 🧩 Enhance AI Agent using plugins instead of rebuild a whole new agent
http://agently.tech
Apache License 2.0
1.07k stars 122 forks source link

请问gpt4v请求如何加载本地的图片而不是url的方式? #144

Closed laolongboy closed 1 month ago

sevenold commented 1 month ago
{
    "type": "image_url",
    "image_url": {
        image_to_base64(image_path),
    },
},

def image_to_base64(image_path: str) -> str:
  with open(image_path, "rb") as image_file:
      image_data = image_file.read()
      base64_encoded = base64.b64encode(image_data).decode("utf-8")
  mime_type = Image.open(image_path).get_format_mimetype()
  return f"data:{mime_type};base64,{base64_encoded}"