openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

Image Example - `base64` and URL pair incomplete code snippet

Open CNX-Inc opened this issue 1 year ago • 0 comments

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • [X] This is an issue with the Python library

Describe the bug

NOTE: This is an issue with the _documentation_ of the python library not the *functionality*

It seems like one of the example code snippets is incomplete/incorrect

More specifically, the example states: The Chat Completions API is capable of taking in and processing multiple image inputs in both base64 encoded format or as an image URL.

However, the code itself shows only the image URL reference (twice):

    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "What are in these images? Is there any difference between them?",
        },
        {
          "type": "image_url",
          "image_url": {
            "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg",
          },
        },
        {
          "type": "image_url",
          "image_url": {
            "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg",
          },
        },
      ],
    }
  ],```

### To Reproduce

Read the python documentation at: https://platform.openai.com/docs/guides/vision/multiple-image-inputs

### Code snippets

```Python
I suspect the code example should be something like:

=[
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "What are in these images? Is there any difference between them?",
        },
        {
          "type": "image_url",
          "image_url": {
            "url": f"data:image/jpeg;base64,{base64_image}",
          },
        },
        {
          "type": "image_url",
          "image_url": {
            "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg",
          },
        },
      ],
    }
  ],

Note the change of one of the Wikimedia URLS to: `"url": f"data:image/jpeg;base64,{base64_image}"`

OS

Any

Python version

Any

Library version

Any

CNX-Inc avatar Sep 03 '24 14:09 CNX-Inc