PawanOsman / ChatGPT.Net

C# library for ChatGPT using official OpenAI API

Home Page:https://www.nuget.org/packages/ChatGPT.Net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Non JSON data in the response stream

Caulm opened this issue · comments

commented

An exception is thrown when I call ChatGptUnofficial.Ask.
The Message:

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<T> 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 stack trace:

在 Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureArrayContract(JsonReader reader, Type objectType, JsonContract contract)
在 Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
在 Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
在 Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
在 Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
在 Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
在 Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
在 ChatGPT.Net.ChatGptUnofficial.<SendMessage>d__33.MoveNext() 在 E:\Mirai-console\livebot\source\ChatGPT.Net\ChatGPTUnofficial.cs 中: 第 271 行
在 ChatGPT.Net.ChatGptUnofficial.<SendMessage>d__33.MoveNext() 在 E:\Mirai-console\livebot\source\ChatGPT.Net\ChatGPTUnofficial.cs 中: 第 267 行
在 ChatGPT.Net.ChatGptUnofficial.<Ask>d__30.MoveNext() 在 E:\Mirai-console\livebot\source\ChatGPT.Net\ChatGPTUnofficial.cs 中: 第 147 行

I debugged and get the following response stream in ChatGptUnofficialOptions.SendMessage:

data: {"message": {"id": "ee672280-8484-4f3b-a22e-6e8aa220f872", "author": {"role": "system", "name": null, "metadata": {}}, "create_time": 1680774850.515529, "update_time": null, "content": {"content_type": "text", "parts": [""]}, "end_turn": true, "weight": 1.0, "metadata": {}, "recipient": "all"}, "conversation_id": "ed88bf93-65ef-4967-b92a-2aa018be10e5", "error": null}
data: {"message": {"id": "6ee04278-ae06-4dc6-9a23-b4ac5d3558f9", "author": {"role": "user", "name": null, "metadata": {}}, "create_time": 1680774850.522996, "update_time": null, "content": {"content_type": "text", "parts": ["Hi, chatgpt."]}, "end_turn": null, "weight": 1.0, "metadata": {"timestamp_": "absolute", "message_type": null}, "recipient": "all"}, "conversation_id": "ed88bf93-65ef-4967-b92a-2aa018be10e5", "error": null}
data: {"message": {"id": "65cc4ca3-d84a-4e89-81b4-cdce9e13de5f", "author": {"role": "assistant", "name": null, "metadata": {}}, "create_time": 1680774850.882099, "update_time": null, "content": {"content_type": "text", "parts": [""]}, "end_turn": null, "weight": 1.0, "metadata": {"message_type": "next", "model_slug": "text-davinci-002-render-sha"}, "recipient": "all"}, "conversation_id": "ed88bf93-65ef-4967-b92a-2aa018be10e5", "error": null}
data: {"message": {"id": "65cc4ca3-d84a-4e89-81b4-cdce9e13de5f", "author": {"role": "assistant", "name": null, "metadata": {}}, "create_time": 1680774850.882099, "update_time": null, "content": {"content_type": "text", "parts": ["Hello"]}, "end_turn": null, "weight": 1.0, "metadata": {"message_type": "next", "model_slug": "text-davinci-002-render-sha"}, "recipient": "all"}, "conversation_id": "ed88bf93-65ef-4967-b92a-2aa018be10e5", "error": null}
data: {"message": {"id": "65cc4ca3-d84a-4e89-81b4-cdce9e13de5f", "author": {"role": "assistant", "name": null, "metadata": {}}, "create_time": 1680774850.882099, "update_time": null, "content": {"content_type": "text", "parts": ["Hello!"]}, "end_turn": null, "weight": 1.0, "metadata": {"message_type": "next", "model_slug": "text-davinci-002-render-sha"}, "recipient": "all"}, "conversation_id": "ed88bf93-65ef-4967-b92a-2aa018be10e5", "error": null}
......
data: {"message": {"id": "65cc4ca3-d84a-4e89-81b4-cdce9e13de5f", "author": {"role": "assistant", "name": null, "metadata": {}}, "create_time": 1680774850.882099, "update_time": null, "content": {"content_type": "text", "parts": ["Hello! How can I assist you today?"]}, "end_turn": true, "weight": 1.0, "metadata": {"message_type": "next", "model_slug": "text-davinci-002-render-sha", "finish_details": {"type": "stop", "stop": "<|im_end|>"}}, "recipient": "all"}, "conversation_id": "ed88bf93-65ef-4967-b92a-2aa018be10e5", "error": null}
data: [DONE]

There is a [Done] tag at the end which cannot be deserialized to JSON.

I'm struggling with the same problem, so I decided to downgrade the NuGet package in my project.