Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'ChatGPT.Net.DTO.ChatGPTUnofficial.ChatGptUnofficialMessageResponse' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
hopto-dot opened this issue · comments
I use a snippet from the example code for the ChatGptUnofficial class
var bot = new ChatGptUnofficial("I put my session ID here");
// get response
var response = await bot.Ask("What is the weather like today?"); // <- this line gives the exception
Console.WriteLine(response);
// stream response
await bot.AskStream(response => {
Console.WriteLine(response);
}, "What is the weather like today?");
Exception:
Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'ChatGPT.Net.DTO.ChatGPTUnofficial.ChatGptUnofficialMessageResponse' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
Path '', line 1, position 1.'
The program tries running the line for a good few sessions then gives the exception.
Fixed