Meet NGpt - OpenAI GPT C# client library that will make your conversations with ChatGPT a breeze!
Have you ever been struggling building your own smart AI application in C#? Well, now you can use ChatGpt inside your application! Introducing NGpt, the powerful .NET library that lets you integrate ChatGPT seamlessly into your C# applications. No more nigts spent on building your own AI solitions, no more convoluted logic and building complex business rules - just pure AI bliss. In this blog post, we'll dive into the wonderful world of NGpt and show you how easy it is to use. You might even find a few laughs along the way.
The Magic of NGpt
NGpt is a transient fault-tolerant .NET 6 OpenAI client that simplifies ChatGPT integration for C# developers. It's like your friendly neighborhood Spider-Man - always there to help you out when you need it most. With just your OpenAI API key, you can start coding AI applications in C# faster than you can say "Peter Parker." Let's start. Like any good superhero, NGpt - OpenAI GPT C# client library comes with its own set of amazing features: - Install one nuget package called NGpt and you're ready to code AI solutions - Simplicity of use. We created easy to use classes like Chat or Edit. You can use them instead of struggling with old-school manual HTTP calls. - Supports retry policies like 350-million-downloads Polly retry library. Quite popular one! - You can generate multiple completion options in a single response - it's all configurable in your C# code! - Exceed the request limit? No worries, NGpt has your back! It uses retry in such cases with exponential backoff strategy. Installing NGpt Installing NGpt is as easy as pie, and we all know how much Scott Hanselman loves pie. Head over to NuGet and run Install-Package NGpt. That's it! You're now ready to rock and roll with ChatGPT. The Simplest Example: To get started, let's create a basic chat using NGpt. All you need is to initialize the client with your API key and ask ChatGPT to say hello:using NGpt; // Initialize the client with your API key. var chat = new Chat("Run the code and watch in awe as ChatGPT says hello to you through your C# application. Congratulations! You've just created OpenAI supported C# application!"); // Get a response from ChatGPT var responseFromOpenAI = chat.Complete("Say hello"); Console.WriteLine(responseFromOpenAI);
More Complex Example
NGpt - OpenAI GPT C# client library is perfect for the beginners, but you can achieve much more. Now let's ramp it up a notch with a more complex example, where we can tweak some configuration settings:using NGpt; var chat = new Chat("Notice how we've added a bit more configuration? We've set the temperature to 0.7 for added creativity and specified the model to use GPT-3.5 Turbo. The possibilities are endless! For example, you can write a science-fiction book with temperature equal to maximum level - 2. Or you your app can be cold as ice business analyst when you choose temperature at the minimum level of 0. As a software developer, you choose your application temper:)"); var completionRequest = new ChatRequest() { Messages = new ChatMessage[] { new ChatMessage() { Role = Role.User, Content = "Say this is a test!", } }, Temperature = 0.7f, Model = ChatModel.GPT3_5Turbo }; var response = chat.Complete(completionRequest); var content = response.Choices[0].Message.Content; Console.WriteLine(content);
Generate Multiple Response Options
Let's say you're feeling indecisive and want ChatGPT to come up with three different ways to write a C# program that checks if a given number is a prime number. NGpt can do that too. Just use N parameter. My quess is that N stands for Number of options to generate.using NGpt.ChatCompletion; using NGpt; var chat = new Chat("Just like that, you have three different ways to check for prime numbers! Never had so many choices? Me too. It's like having a team of AI developers working for you."); var completionRequest = new ChatRequest() { Messages = new ChatMessage[] { new ChatMessage() { Role = Role.User, Content = "Create C# program that checks if a given number is prime number", }, }, Temperature = 0f, Model = ChatModel.GPT3_5Turbo, N = 3 }; var response = chat.Complete(completionRequest); foreach(var choice in response.Choices) { var content = choice.Message.Content; Console.WriteLine(content); }
Editing text or code with ChatGPT (and of course NGpt)
NGpt's Edit class allows you to modify text or code easily. (Note: OpenAI GPT has special feature to write and refactor code. OpenAI must love software developers!) For example, let's say you want ChatGPT to fix a spelling error in the phrase "To bee or not to be. You can do it easily:using NGpt.Domain.Edit; var edit = new Edit("Can you imagine potential business cases where you can use it? Text editors, Spelling prompt in email clients, software to prepare documents free of mistakes. In such a tool in your hands, your software development climb up to Mont Everest (8849 m). Hard to breath at this level? Keep reading! But the most important to coders. How to improve our code quality or maybe make automatic code review suggestions? I believe Visual Studio Copilot could do it (When Microsoft publish it. At the moment Copilot X does not exist in real life - you can see it in Copilot X Scott Hanselman youtube video) So, the", " "); var response = edit.EditText("To bee or not to be.", "fix spelling"); Console.WriteLine(response); // "To be or not to be.\n"
using NGpt.Domain.Edit; var edit = new Edit("It's like having a spellchecker and a code reviewer all in one!", " "); var response = edit.EditCode("Console.WriteLine(\"Test\");", "Change it to display text: \"aaa\""); Console.WriteLine(response); // "Console.WriteLine(\"aaa\");\n"
Komentarze
Prześlij komentarz