Skip to content
This repository has been archived by the owner on Jul 14, 2024. It is now read-only.

can Chat-to-api support image input #340

Open
zwbx opened this issue Nov 27, 2023 · 5 comments
Open

can Chat-to-api support image input #340

zwbx opened this issue Nov 27, 2023 · 5 comments

Comments

@zwbx
Copy link

zwbx commented Nov 27, 2023

import base64
import requests

# OpenAI API Key
api_key = "****"

# Function to encode the image
def encode_image(image_path):
  with open(image_path, "rb") as image_file:
    return base64.b64encode(image_file.read()).decode('utf-8')

# Path to your image
image_path = "00000000_img_front.png"

# Getting the base64 string
base64_image = encode_image(image_path)

headers = {
  "Content-Type": "application/json",
  "Authorization": f"Bearer {api_key}"
}

payload = {
  "model": "gpt-4-vision-preview",
  "messages": [
    {
      "role": "user",
      "content": 
      [
        {
          "type": "text",
          "text": "What’s in this image?"
        },
        {
          "type": "image_url",
          "image_url": {
            "url": f"data:image/jpeg;base64,{base64_image}"
          }
        }
      ]
    }
  ],
  "max_tokens": 300
}

response = requests.post("http://0.0.0.0:7999/v1/chat/completions", headers=headers, json=payload)

print(response.json())

Thanks for the great work, I have successfully deployed Chat-to-api.
But it seems to encounter bugs when call Chat-to-api by the image input mode.
Response is "{'code': '500', 'msg': 'invalid type: sequence, expected a string at line 1 column 75'}"
Could that be supported?

@0x676e67
Copy link
Owner

Currently, I have not adapted to support image models.

@Dooy
Copy link

Dooy commented Jan 28, 2024

自己实现下 不难 file 接口都有了

@spacex-3
Copy link

spacex-3 commented Mar 1, 2024

推荐个:https://github.com/Ink-Osier/PandoraToV1Api

可以把画图接口转出来

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants
@Dooy @zwbx @0x676e67 @spacex-3 and others