srcnalt / OpenAI-Unity

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

I got a problem with Json not reading properly on 0.1.11 version #40

Closed RubenFreireAndrade closed 1 year ago

RubenFreireAndrade commented 1 year ago

This is what's been thrown at me:

JsonReaderException: Invalid property identifier character: “. Path '', line 2, position 1. Newtonsoft.Json.JsonTextReader.ParseProperty () (at /root/repo/Src/Newtonsoft.Json/JsonTextReader.cs:1600) Newtonsoft.Json.JsonTextReader.ParseObject () (at /root/repo/Src/Newtonsoft.Json/JsonTextReader.cs:1571) Newtonsoft.Json.JsonTextReader.Read () (at /root/repo/Src/Newtonsoft.Json/JsonTextReader.cs:432) Newtonsoft.Json.JsonReader.ReadAndAssert () (at /root/repo/Src/Newtonsoft.Json/JsonReader.cs:1169) 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 /root/repo/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs:464) 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 /root/repo/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs:309) Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent) (at /root/repo/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs:202) Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) (at /root/repo/Src/Newtonsoft.Json/JsonSerializer.cs:904) Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType) (at /root/repo/Src/Newtonsoft.Json/JsonSerializer.cs:883) Newtonsoft.Json.JsonConvert.DeserializeObject (System.String value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings) (at /root/repo/Src/Newtonsoft.Json/JsonConvert.cs:831) Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value, Newtonsoft.Json.JsonSerializerSettings settings) (at /root/repo/Src/Newtonsoft.Json/JsonConvert.cs:787) OpenAI.Configuration..ctor (System.String apiKey, System.String organization) (at Library/PackageCache/com.srcnalt.openai-unity@5924018f2c/Runtime/Configuration.cs:33) OpenAI.OpenAIApi.get_Configuration () (at Library/PackageCache/com.srcnalt.openai-unity@5924018f2c/Runtime/OpenAIApi.cs:28) OpenAI.OpenAIApi.DispatchRequest[T] (System.String path, System.String method, System.Byte[] payload) (at Library/PackageCache/com.srcnalt.openai-unity@5924018f2c/Runtime/OpenAIApi.cs:73) OpenAI.OpenAIApi.CreateChatCompletion (OpenAI.CreateChatCompletionRequest request) (at Library/PackageCache/com.srcnalt.openai-unity@5924018f2c/Runtime/OpenAIApi.cs:179) OpenAI.ChatGPT.SendReply () (at Assets/Samples/OpenAI Unity/0.1.11/ChatGPT/ChatGPT.cs:59) System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__7_0 (System.Object state) (at :0) UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <4a31731933e0419ca5a995305014ad37>:0) UnityEngine.UnitySynchronizationContext.Exec () (at <4a31731933e0419ca5a995305014ad37>:0) UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at <4a31731933e0419ca5a995305014ad37>:0)

RubenFreireAndrade commented 1 year ago

Any idea what could be the problem?

I tried 1 or 2 releases ago and seemed fine. Now running into this with the latest version.

srcnalt commented 1 year ago

The issue originated from Newtonsoft with IL2CPP, it works fine with the Mono scripting backend. Meanwhile, a new version of NewtonsoftJSON is available I will see if the issue is fixed there.

RubenFreireAndrade commented 1 year ago

If you are referring to Project settings > Player. Its currently running Mono scripting backend. image_2023-04-22_181742490

Maybe I'm missing something? Like a Json package in my project?

srcnalt commented 1 year ago

With the new Newtonsoft Json release this issue is now fixed for me on android for IL2CPP builds, can you check with v0.1.12 if it works as expected?

RubenFreireAndrade commented 1 year ago

Still the same issue. I tried on a clean project just in case something was interfering and tried on both Mono & IL2CPP settings.

RubenFreireAndrade commented 1 year ago

ok my fault. Dont do any more changes.

RubenFreireAndrade commented 1 year ago

There was an issue on my json file, using quotation marks wrongly. Sorry in advance for taking time off your weekend.

srcnalt commented 1 year ago

No worries, closing the issue.