Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: text field in MultiContent chat message is required #846

Closed
wants to merge 2 commits into from

Conversation

daulet
Copy link

@daulet daulet commented Sep 9, 2024

Describe the change
Can't omit text field in in multi content chat message, see the example below.

Provide OpenAI documentation link
Try

curl "https://api.openai.com/v1/chat/completions" \
  -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
         "messages": [
           {
             "role": "user",
             "content": [
               {
                 "type": "text"
               },
               {
                 "type": "image_url",
                 "image_url": {
                   "url": "https://shellsamurai.com/wp-content/uploads/2023/04/tux.jpg"
                 }
               }
             ]
           }
         ],
         "model": "gpt-4o",
         "temperature": 0,
         "max_tokens": 1024,
         "top_p": 1,
         "stream": false
       }'

You'll get:

{
  "error": {
    "message": "Invalid chat format. Expected 'text' field in text type content part to be a string.",
    "type": "invalid_request_error",
    "param": null,
    "code": null
  }
}

Describe your solution
Don't emit the Text field.

Tests
Successful request to OpenAI endpoint.

Additional context

Issue: #XXXX

Copy link

codecov bot commented Sep 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.01%. Comparing base (774fc9d) to head (f616ab6).
Report is 60 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #846      +/-   ##
==========================================
+ Coverage   98.46%   99.01%   +0.55%     
==========================================
  Files          24       26       +2     
  Lines        1364     1418      +54     
==========================================
+ Hits         1343     1404      +61     
+ Misses         15        8       -7     
  Partials        6        6              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sashabaranov
Copy link
Owner

Hey @daulet, thank you for the PR!

I'm curious of how the API would handle the messages of image_url type with non-ommited text?

For example

{
    "type": "image_url",
    "text": "",
    "image_url": {
        "url": "https://shellsamurai.com/wp-content/uploads/2023/04/tux.jpg"
    }
}

We might want to go with a custom MarshalJSON() in this case.

@daulet daulet closed this by deleting the head repository Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants