dylanshine / openai-kit

A community Swift package used to interact with the OpenAI API
https://platform.openai.com/docs/api-reference
MIT License
712 stars 113 forks source link

Update chat message to include image content as well as text #71

Closed mpdifran closed 2 weeks ago

mpdifran commented 2 weeks ago

This updates the chat message to allow including image content with text, as per OpenAI documentation.

If there's only 1 content, and it's a text, the chat message will be encoded as so:

{
    "role": "user",
    "content": "The text."
}

If there's multiple contents in a message, it will be encoded like so:

{
    "role": "user",
    "content": [
        {
            "type": "text",
            "text": "The text."
        },
        {
            "type": "image_url",
            "image_url": {
                "url": "https://image.com/my-image.jpg"
            }
        }
    ]
}