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 invalid message format when using OpenAIServerModel #584

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sijunhe
Copy link

@sijunhe sijunhe commented Feb 10, 2025

This PR fixes #583

The bug is the fact that due to OpenAI SDK uses flat message format without images but nested message format with image. The current code always use nested message, which results in this bug.

without image

client.chat.completions.create(
    messages=[
        {
            "role": "user",
            "content": "Say this is a test",
        }
    ],
    model="gpt-4o",
)

with image

client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": prompt},
                {
                    "type": "image_url",
                    "image_url": {"url": f"data:{img_type};base64,{img_b64_str}"},
                },
            ],
        }
    ],
)

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.

[BUG] invalid message format when using OpenAIServerModel
1 participant