OpenAI
Chat with the OpenAI model about your local images in Python
Learn how to use local images with OpenAI's Chat Completions API in Python. This recipe covers encoding images, crafting a payload with both text and image data, making the API request, and printing the response. Follow these steps to integrate local images into your chat completions seamlessly.
Required packages
You need below packages to use the code generated by recipe. All packages are automatically installed in MLJAR Studio.
openai>=1.35.14
requests>=2.31.0
Interactive recipe
You can use below interactive recipe to generate code. This recipe is available in MLJAR Studio.
In the below recipe, we assume that you have following variables available in your notebook:
- client (type OpenAI)
Python code
# Python code will be here
Code explanation
- Choose the image and set its path.
- Create the image encode function and call it.
- Defines the headers for the HTTP request.
- Constructs the JSON payload for the request.
- Make the API request and print the response.
Example Python notebooks
Please find inspiration in example notebooks
OpenAI cookbook
Code recipes from OpenAI cookbook.
- « Previous
- Text to speech
- Next »
- Vision with URL images