srcnalt / OpenAI-Unity

An unofficial OpenAI Unity Package that aims to help you use OpenAI API directly in Unity Game engine.
MIT License
648 stars 144 forks source link

Meeting error with JsonSerializationException when trying the ChatCompletion #99

Closed jhinpan closed 7 months ago

jhinpan commented 7 months ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. Go to the sample
  2. Click on ChatGPT.cs
  3. Just try to normally make conversation with ChatGPT

Expected behavior It reports error: 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) OpenAI.MicrophoneCapture.SendReplyToCopilot () (at Assets/Scripts/ChatGPT/MicrophoneCapture.cs:438) System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__7_0 (System.Object state) (at <88e4733ac7bc4ae1b496735e6b83bbd3>:0) UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at :0) UnityEngine.UnitySynchronizationContext.Exec () (at :0) UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at :0)

Screenshots 0c4ab95b45147e92468ce5d4796ecc3

Environment (please complete the following information):

Edmonds39 commented 7 months ago

I met the same problem, but it didn't happen yesterday."

alchemyharmony commented 7 months ago

Same situation for me! I haven't managed to resolve it yet, but I found a helpful starting point at https://platform.openai.com/docs/guides/text-generation. The issue seems to be related to how the API is being invoked.

TGM4939 commented 7 months ago

I managed to temporarily solve the issue. Not sure if its effecting anything internally, but when you double click the error, the line of code the error is being shown from, just remove this part ", jsonSerializerSettings". So the adjusted line will be as follows: data = JsonConvert.DeserializeObject(request.downloadHandler.text);

Again, I am not sure if this'll cause any other problems but it seems to be a temporary fix.

Alan-Grech295 commented 7 months ago

I think the issue is that a system_fingerprint field is being sent in the response. I solved this by adding public int? System_fingerprint { get; set; } to the CreateChatCompletionResponse struct.

omaratcygnus commented 7 months ago

Came across this issue and found that there is a new variable added in response coming from GPT, that is "system_fingerprint". I just updated DataTypes.cs with updated string variable and it worked.

jhinpan commented 7 months ago

Thank you for your guys' help!!! Yeah, I think updating DataTypes.cs will temporarily solve this problem. Hope everyone does well through it.