-
-
Notifications
You must be signed in to change notification settings - Fork 541
Description
Describe the bug
I use the api as normal, but it shows System.Text.Json.JsonException
The JSON value could not be converted to System.String. Path: $.error.code | LineNumber: 0 | BytePositionInLine: 20.
Your code piece
ChatCompletionCreateRequest chatCompletionCreateRequest = new ChatCompletionCreateRequest {
Messages = new List<ChatMessage>(),
Model = Model,
};
ChatCompletionCreateResponse chatCompletionCreateResponse;
try {
chatCompletionCreateResponse = await openAiService.ChatCompletion.CreateCompletion(chatCompletionCreateRequest);
} catch (Exception ex) {
Console.WriteLine($"{ex.GetType().FullName}<br>{ex.Message}");
throw;
}
Result
System.Text.Json.JsonException
The JSON value could not be converted to System.String. Path: $.error.code | LineNumber: 0 | BytePositionInLine: 20.
InvalidOperationException: Cannot get the value of a token type 'Number' as a string.
at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, Utf8JsonReader& reader, Exception ex)
at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
at System.Text.Json.JsonSerializer.ContinueDeserialize[TValue](ReadBufferState& bufferState, JsonReaderState& jsonReaderState, ReadStack& readStack, JsonTypeInfo jsonTypeInfo)
at System.Text.Json.JsonSerializer.ReadFromStreamAsync[TValue](Stream utf8Json, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken)
at System.Net.Http.Json.HttpContentJsonExtensions.ReadFromJsonAsyncCore[T](HttpContent content, Encoding sourceEncoding, JsonSerializerOptions options, CancellationToken cancellationToken)
at OpenAI.Extensions.HttpClientExtensions.PostAndReadAsAsync[TResponse](HttpClient client, String uri, Object requestModel, CancellationToken cancellationToken)
at OpenAI.Managers.OpenAIService.CreateCompletion(ChatCompletionCreateRequest chatCompletionCreateRequest, String modelId, CancellationToken cancellationToken)
at 【MyCode】
Expected behavior
API returns ChatGPT's reply
Desktop (please complete the following information):
- OS: Windows 11
- Language C#
