In Unity, encountering JsonSerializationException while using ChatGPT API

I’m following a tutorial on YouTube, attempting to integrate ChatGPT’s API into Unity to create a virtual character that responds to me. Everything was working fine a few weeks ago; I could receive responses within Unity without any issues. However, today, when I tried to use ChatGPT within Unity, I didn’t receive any response, and I encountered an error: “JsonSerializationException: Could not find member ‘system_fingerprint’ on object of type ‘CreateChatCompletionResponse’. Path ‘system_fingerprint’, line 21, position 23…” Initially, I thought it might be related to my credit card limit, so I recharged it on the official website, but I’m still getting the same error. I checked the API usage history, and it confirms usage today. I’ve pasted the specific error message below. I’m wondering if anyone skilled could help me. Thank you for reading!

JsonSerializationException: Could not find member ‘system_fingerprint’ on object of type ‘CreateChatCompletionResponse’. Path ‘system_fingerprint’, line 21, position 23.
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject (System.Object newObject, Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty member, System.String id) (at <761cf2a144514d2291a678c334d49e9b>:0)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) (at <761cf2a144514d2291a678c334d49e9b>:0)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) (at <761cf2a144514d2291a678c334d49e9b>:0)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent) (at <761cf2a144514d2291a678c334d49e9b>:0)
Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) (at <761cf2a144514d2291a678c334d49e9b>:0)
Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType) (at <761cf2a144514d2291a678c334d49e9b>:0)
Newtonsoft.Json.JsonConvert.DeserializeObject (System.String value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings) (at <761cf2a144514d2291a678c334d49e9b>:0)
Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value, Newtonsoft.Json.JsonSerializerSettings settings) (at <761cf2a144514d2291a678c334d49e9b>:0)
OpenAI.OpenAIApi.DispatchRequest[T] (System.String path, System.String method, System.Byte payload) (at Library/PackageCache/com.srcnalt.openai-unity@1928201773/Runtime/OpenAIApi.cs:82)
OpenAI.OpenAIApi.CreateChatCompletion (OpenAI.CreateChatCompletionRequest request) (at Library/PackageCache/com.srcnalt.openai-unity@1928201773/Runtime/OpenAIApi.cs:259)
ChatGPTManager.AskChatGPT (System.String newText) (at Assets/ChatGPTManager.cs:21)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__7_0 (System.Object state) (at :0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at :0)
UnityEngine.UnitySynchronizationContext.Exec () (at :0)
UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at :0)

1 Like

Got the same issue,mybe something update for the api?

It’s repeating itself like crazy at the moment for me. Getting lots of malformed json and errors in responses as well, but that could be me. Like you say, though, this is all stuff that worked fine a week ago.

The repeating thing is crazy, it’s been happening even in copilot! I was reading through some code and while it sat idle it did that thing where it guesses what’s next from the context and starts writing stuff, normally a few operations or a line or two. This time was epic, it wrote a whole long series of string assignments that got longer and longer (‘I’ ‘I was’ ‘I was walking’ etc etc) until it started writing a story/poem! Half of the screen was a greyed poem that was hilarious and each line assigned to a variable. I’ve been experimenting with some fine tuning and one of them definitely had a problem in the dataset as it would always just repeat everything, often forever. It would alternate between the response and then the exact same words but in quotes. I forgot to clean out a section of my training dataset and there was a ton of stuff that had quotes around it so that makes sense, but it also seemed to kick off the repeat thing and in weird ways.

Nothing more to see other than your structure is (rightfully) expecting a property that wasn’t included in the response.

Do you have any error handling? Can you post what was actually received?

I also face the same issues just now and I also follow the tutorial on YouTube(Sarge). I am also curious and do not know the solution for it before.

Now I finally found a solution. Try these step, maybe is OpenAI update ther API recently

  1. Packages → OpenAIUnity → Runtime → DataTypes
  2. Find CreateChatCompletion Response struct
  3. Add public string SystemFingerprint {get;set]

Thanks AlexOng, you are right
public struct CreateChatCompletionResponse : IResponse
{
public string SystemFingerprint { get; set; }

Also thanks to @AlexOng for that fix you saved me some headache :+1:

Thank you for fixing my problem too!

Cristian Hunt via OpenAI Developer Forum <notifications@openai1.discoursemail.com> 于2023年12月4日周一 00:10写道:


please help me in this


any help me

You need to start ignoring / defining new values in your type definitions (I’m not familiar with Unity)

ChatCompletions recently started providing logprobs. Your current type definition “ChatChoice” needs to be updated. This is the exact same situation with system_fingerprint.

You can go YouTube find sarge who teach intergration of ChatGPT into unity and he has github link for implementing OpenAI unity. Click it and you will see the issue part. In the issues part, there have some solutions to fix the OpenAI error so you can go to have a look. Good luck.

Has fixed the issue you have for their unity C# library for using openai api. They are not officially linked to openai but openai do link to them from a page on the openai website. Imo the library is excellent, the dev is quick to respond, the package is easy to install. It supports the newer features like Assistants and image creation too.