Consuming the ChatGPT API with C#
Utilizing the ChatGPT API, is a straightforward process, though the configuration does require attention to detail.
Prerequisites
C# Implementation
try
{
OpenAIAPI api = new OpenAIAPI(apiKey: "[Your API Key]");
var completion = api.Completions.CreateCompletionAsync(
prompt: "What is your model?",
model: "text-davinci-002",
maxTokens: 100,
temperature: 0.5F
).Result;
var result = completion.Choices[0].Text.Trim();
Console.WriteLine(result);
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
Console.ReadLine();
Parameter Explanation
Usage Limitations
Keep in mind that usage limits are imposed on a monthly basis. You'll encounter an exception if you exceed this limit.
To increase your quota:
Happy coding! and stay curious
#csharpprogramming
领英推荐
#csharpdotnet
#csharp
#csharpdeveloper
#dotnetcore
#dotnetdevelopers
#dotnetdeveloper
#dotnetdevelopers
#dotnetcoredeveloper
#dotnet
#dotnetdevelopment
#dotnetframework
#dotnet7
#ai
#artificialintelligence
#chatgpt
#bezeq