A member with the name 'name' already exists on 'OpenAI.Chat.Message' #171
-
Bug ReportThe following error message occurs when attempting ChatEndpoint.GetCompletionAsync(): JsonSerializationException: A member with the name 'name' already exists on 'OpenAI.Chat.Message'. Use the JsonPropertyAttribute to specify another name. I apologize if this is not the proper space to bring this up, I could not start a discussion in the Q&A section of the Discussions tab. OverviewUpon looking through the source I see that in Message.cs there is a serialized field "name" as well as using the JsonPropertyAttribute to specify the public "Name" field to serialize as "name". This might be causing the issue. To ReproduceThe following code reproduces this problem on the "await api.ChatEndpoint.GetCompletionAsync(chatRequest);" line. private async Task<string> SendMessage(string message)
{
var api = new OpenAIClient(GPT_API_KEY);
var messages = new List<Message>
{
new Message(Role.System, GPT_SYSTEM_ROLE),
new Message(Role.User, message)
};
var chatRequest = new ChatRequest(messages, GPT_MODEL_ID);
var response = await api.ChatEndpoint.GetCompletionAsync(chatRequest);
var choice = response.FirstChoice;
return choice.Message.Content.ToString();
} Expected behaviorI would expect that error to not occur and for the GetCompletionAsync() to complete as expected. Additional contextI am using this package in Unity 2022.3.10f1. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 6 replies
-
Worth noting when I modified the local package cache version of Message.cs to test a fix, I got the same problem for "role" and "content" and some others once "name" was fixed. |
Beta Was this translation helpful? Give feedback.
-
Yeah this is strange, did you somehow modify the json serialization settings? This should not be possible. |
Beta Was this translation helpful? Give feedback.
-
My project is using Newtonsoft Json, could that be causing collisions? |
Beta Was this translation helpful? Give feedback.
-
Test installing this in a new project with the same editor version. If it works, then you have another package that is modifying the serialization settings. |
Beta Was this translation helpful? Give feedback.
It looks like this is the package in question in case it's helpful for future reference: https://github.com/applejag/Newtonsoft.Json-for-Unity.Converters/
OpenAI stuff works when I modify some of those settings.