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

CreateImagePart overloads + implicit casts from string lead to confusion #246

Open
stephentoub opened this issue Oct 7, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@stephentoub
Copy link
Contributor

Service

OpenAI

Describe the bug

CreateImagePart has two overloads:

public static ChatMessageContentPart CreateImagePart(BinaryData imageBytes, string imageBytesMediaType, ChatImageDetailLevel? imageDetailLevel = null);
public static ChatMessageContentPart CreateImagePart(Uri imageUri, ChatImageDetailLevel? imageDetailLevel = null);

In general for .NET APIs we try to avoid situations where the same type of argument in the same position leads to different behaviors, however here that happens because of an implicit cast from string to ChatImageDetailLevel. I had a call to CreateImagePart(imageBytes, "image/jpeg") and I then changed it to CreateImagePart(imageUrl, "image/jpeg"). It compiled fine, but then it threw an exception at run-time, because the "image/jpeg" was no longer considered to be a media type and instead considered to be an image detail level.

Steps to reproduce

See description above.

These APIs are now stable, so I'm not sure much can be done about it.

Code snippets

No response

OS

Windows 11

.NET version

.NET 8

Library version

2.0.0

@stephentoub stephentoub added the bug Something isn't working label Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant