Skip to content

Completions

Tolga Kayhan edited this page Feb 16, 2023 · 1 revision

Create a completion request

Sample 1

var completionResult = await openAiService.Completions.CreateCompletion(new CompletionCreateRequest()
{
    Prompt = "Once upon a time",
    Model = Models.TextDavinciV3
});

Sample 2

var completionResult = await sdk.Completions.CreateCompletion(new CompletionCreateRequest()
{
    Prompt = "Once upon a time"
}, Models.TextDavinciV3);

Handle Response

if (completionResult.Successful)
{
    Console.WriteLine(completionResult.Choices.FirstOrDefault());
}
else //handle errors
{
    if (completionResult.Error == null)
    {
        throw new Exception("Unknown Error");
    }
    Console.WriteLine($"{completionResult.Error.Code}: {completionResult.Error.Message}");
}
Clone this wiki locally