OpenAI-API-dotnet
OpenAI-API-dotnet copied to clipboard
Logprobs results in Newtonsoft SerializationException
Adding logProbs: n, to a CompletionRequest object, results in a serialization error "One or more errors occurred. (Error converting value {null} to type 'System.Double'. Path 'choices[0].logprobs.token_logprobs[0]', line 1, position 418.)"
I have tried using logProbs with both CreateCompletionAsync and CreateCompletionsAsync and I recieve the same error. I wonder whether the JSON being returned from OpenAI has changed slightly?
@isaacwalkercox I have tried to reproduce your error and it seems to work for various cases (example):
var completionRequest = new CompletionRequest
{
Prompt = "one two three",
MaxTokens = 5,
Temperature = 0,
TopP = 1,
PresencePenalty = 0,
FrequencyPenalty = 0,
Logprobs = 10,
StopSequence = "###"
};
var result = await api.Completions.CreateCompletionAsync(completionRequest);
Indeed token_logprobs
maps to an IList<double>
which cannot accept null values, but I cannot figure out a case when the OpenAI returns a null prob value.
Can you provide the code that did not work for you?
I have managed to reproduce this by mistake with the following code:
private OpenAIAPI GetApi => new OpenAIAPI(engine: Engine.Ada);
var api = GetApi;
var completionReq = new CompletionRequest
{
Prompt = "three four five",
Temperature = 0,
MaxTokens = 5,
Echo = true,
StopSequence = "eight"
};
var results = await api.Completions.CreateCompletionsAsync(completionReq);
By replacing List<double>
should be replaced with List<double?>
, it works as expected. If this solution is acceptable, I will create a PR with this minor fix.
Note: After a while, it no longer reproduces. It might be some throttling or similar that makes OpenAI not return those values sometimes.
i know this is old, i'm trying to check on some of these...
i ran your test code and seems to execute without error.
is this still an issue?
@gotmike Yes. This issue was resolved. Thank you for double checking.