OpenAI-API-dotnet icon indicating copy to clipboard operation
OpenAI-API-dotnet copied to clipboard

A Task Was cancelled

Open kikores opened this issue 2 years ago • 3 comments

I raises when I call, CreateCompletionAsync It began when I exceded the free plan, but I set a payment method and still the same,

System.Threading.Tasks.TaskCanceledException: A task was canceled

Any Ideas?

kikores avatar Jun 06 '23 09:06 kikores

@kikores , can you show the relavant section of code, how you are using CreateCompletionAsync, for example.

zeecorleone avatar Jun 10 '23 09:06 zeecorleone

Hi, Here is some code, and Yes, I am using CreateCompletionAsync(),

                int promptTokens = completion.Prompt.Trim().Split().Length;
                completion.MaxTokens = 4096 - (promptTokens + 200);
                var result = openAI.Completions.CreateCompletionAsync(completion).GetAwaiter().GetResult(); 

                if (result != null && result.Completions.Count > 0)
                {
                    return result.Completions.FirstOrDefault()?.Text;
                }
                return null;

Sometimes it works... but other times I have the error...

kikores avatar Jun 19 '23 08:06 kikores