-
Notifications
You must be signed in to change notification settings - Fork 168
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
OpenAI library doesn't work with Gemini's OpenAI compat endpoint #289
Comments
after adding the new role to the Serializer seems to be working fine. i assume this library is generated automatically. but i couldnt find instructions on how to fix the generation code. havent tested anything complex, but this patch seems to work: --- a/src/Generated/Models/ChatMessageRole.Serialization.cs
+++ b/src/Generated/Models/ChatMessageRole.Serialization.cs
@@ -15,6 +15,7 @@ namespace OpenAI.Chat
ChatMessageRole.Assistant => "assistant",
ChatMessageRole.Tool => "tool",
ChatMessageRole.Function => "function",
+ ChatMessageRole.Model => "model",
_ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown ChatMessageRole value.")
};
@@ -23,6 +24,7 @@ namespace OpenAI.Chat
if (StringComparer.OrdinalIgnoreCase.Equals(value, "system")) return ChatMessageRole.System;
if (StringComparer.OrdinalIgnoreCase.Equals(value, "user")) return ChatMessageRole.User;
if (StringComparer.OrdinalIgnoreCase.Equals(value, "assistant")) return ChatMessageRole.Assistant;
+ if (StringComparer.OrdinalIgnoreCase.Equals(value, "model")) return ChatMessageRole.Model;
if (StringComparer.OrdinalIgnoreCase.Equals(value, "tool")) return ChatMessageRole.Tool;
if (StringComparer.OrdinalIgnoreCase.Equals(value, "function")) return ChatMessageRole.Function;
throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown ChatMessageRole value."); |
Hi, I ran into the same issue after a Googler pointed me to a Colab gist using Python. https://discuss.ai.google.dev/t/new-endpoints-chat-embedding-and-openai/49954/6 The Gemini API returns a role of Anyone? |
And here's the source code I used to reproduce this issue.
|
Maybe as an idea, here's the mapping I implemented in my Gemini client for
The incoming value of |
Hello However, giving it a second thought. The Gemini API claims to be compatible to the OpenAI library. Given the current situation I would rather say that the returned value of role is wrong, and should be Kind regards, JoKi |
the api will be compatible but a lot of applications won't work if the model role is needed. |
You are probably right. Just my thoughts on that. |
The API response has been updated and returns the expected role of |
thanks! i will check i out! |
Service
OpenAI
Describe the bug
Google blogged about how they now expose an OpenAI-compatible endpoint for gemini:
https://developers.googleblog.com/en/gemini-is-now-accessible-from-the-openai-library/
but the .NET OpenAI library doesn't work with it. Gemini is sending back a role of "model" as part of the response, but the OpenAI library is trying to validate that any role is one of only five hardcoded values, and anything else causes the request to fail:
openai-dotnet/src/Generated/Models/ChatMessageRole.Serialization.cs
Lines 21 to 29 in 539172f
Steps to reproduce
Run the .NET equivalent to the code in that blog post:
It fails with:
Code snippets
OS
any
.NET version
.NET 8
Library version
2.1.0-beta.2
The text was updated successfully, but these errors were encountered: