NGpt 1.7.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package NGpt --version 1.7.0                
NuGet\Install-Package NGpt -Version 1.7.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NGpt" Version="1.7.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NGpt --version 1.7.0                
#r "nuget: NGpt, 1.7.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install NGpt as a Cake Addin
#addin nuget:?package=NGpt&version=1.7.0

// Install NGpt as a Cake Tool
#tool nuget:?package=NGpt&version=1.7.0                

NGpt - OpenAI ChatGPT C# client

Unlock the full power of AI in your C# projects with NGpt, your ultimate OpenAI ChatGPT client. Designed with the needs of C# developers in mind, NGpt combines simplicity with comprehensive functionality for a seamless AI integration experience. Dive into rapid AI development with the advanced DALL-E 2 model, generating vibrant images from simple textual descriptions. With NGpt, you're not just coding, you're orchestrating AI power with the finesse of a maestro. Handle multiple response options, manage request delays, and take command of AI with ease. NGpt is more than a tool, it's your AI development partner in the fast-paced world of C#.

NuGet NuGet Downloads


Table of Contents

  1. Introduction
  2. Features
  3. Installation
  4. Quickstart Examples
  5. Code Examples
  6. Support
  7. License

Introduction

Thanks for downloading NGpt, OpenAI ChatGPT client for C# developers! We hope this library will help you to create amazing AI applications in C#.

NGpt is a powerful transient fault-tolerant .NET 6 OpenAI client that helps C# developers to use OpenAPI ChatGPT in their applications in seconds. All you need to know is your OpenAI apiKey. Download this package and start coding AI applications in C# today!

Features

  • Easy integration with ChatGPT in OpenAI in your .NET applications
  • Simplified API usage - Just use the Chat class and Completion method.
  • Built specifically for C# developers
  • Generate more than 1 completion option in a single response
  • You can send more reqests than allowed, NGpt will handle it for you and send it with a proper delay. Transient HTTP errors handling with rety logic and exponential backoff.
  • All methods are asynchronous, so you can build faster and more responsive application.

Installation

Install the package from NuGet: Install-Package NGpt

Before you start

How to get API key and organization?

  1. Go to: https://platform.openai.com/signup/
  2. Sign in with your Google account
  3. Go to https://platform.openai.com/account/api-keys

This is a QUICKSTART for C# DEVELOPERS to use OPENAI ChatGPT:

  1. Replace the <API_KEY> and optionally <ORGANIZATION> with your own values that you can find on OpenAI website.
  2. Copy the example code and paste it into your C# program in Visual Studio.
  3. Run the application
  4. Congratulations! You made your first call to OpenAI ChatGPT!
  5. Experiment with your own requests and responses.

CHAT 1

using NGpt;

// Initialize the client with your API key.
var chat = new Chat("<API_KEY>");
// Get a response from ChatGPT
var responseFromOpenAI = await chat.CompleteAsync("Say hello");

Console.WriteLine(responseFromOpenAI);

CHAT 2

More Complex Example - use it when you need more configuration flexibility

using NGpt;

// Initialize the client.
// Optionally you can pass the organization id as a second parameter.
var chat = new Chat("<API_KEY>");

// Create a completion request
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
};

// Get the response
var response = await chat.CompleteAsync(completionRequest);

// Extract the content
var content = response.Choices[0].Message.Content;

Console.WriteLine(content);

CHAT 3

Generate 3 response options in a single OpenAPI request

using NGpt.ChatCompletion;
using NGpt;

// Optionally you can pass the organization id as a second parameter.
var chat = new Chat("<API_KEY>");

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 = await chat.CompleteAsync(completionRequest);

foreach(var choice in response.Choices)
{
    var content = choice.Message.Content;
    Console.WriteLine(content);
}

EDIT Text

Ask GPT to modify specified text

using NGpt.Domain.Edit;

//Organization is optional parameter - you can skip it
var edit = new Edit("<API_KEY>", "<Organization>");

var response = await edit.EditTextAsync("To bee or not to be.", "fix spelling");

//Displays: "To be or not to be.\n"
Console.WriteLine(response);

EDIT Code

Ask GPT to modify specified Code in C#

using NGpt.Domain.Edit;

var edit = new Edit("<API_KEY>", "<Organization>");

var response = await edit.EditCodeAsync("Console.WriteLine(\"Test\");", "Change it to dispay text: \"aaa\"");

//Displays: "Console.WriteLine(\"aaa\");\n"
Console.WriteLine(response);

EDIT

Useful when you need a flexibility (for example you want to increase temperature to get more random results, or you want to increase N parameter to generate more alternative results)

using NGpt.Domain.Edit;

var edit = new Edit("<API_KEY>", "<Organization>");

var request = new EditRequest(EditModel.TextDavinciEdit001, "Change it to dispay text: \"aaa\"")
{
    Input = "Console.WriteLine(\"Test\");",
    Temperature = 0,
    N = 1,
    Top_p = 1
};

var response = await edit.EditAsync(request);

//Displays: "Console.WriteLine(\"aaa\");\n"
Console.WriteLine(response);

DALLE 2 Generate Image

Ask GPT to create an image based on a given prompt using DALL-E 2 model. This method is extremely fast in comparison to Midjourney image generation.

// Create an instance of the Image class with the API key and organization.
var image = new Image("<API_KEY>", "<Organization>");

// Create a new ImageRequest object with a prompt, "Little Labrador dog",
// and set the properties for the number of images, response format, size, and user.
var imageRequest = new ImageRequest("Little Labrador dog")
{
    NumberOfImages = 1,
    ResponseFormat = ResponseFormatType.Url,
    Size = ImageSize.Size512x512,
    User = "Dariusz Kacban"
};

// Call the Generate method of the image object to request image generation
// based on the properties set in the imageRequest object.
var response = await image.GenerateAsync(imageRequest);

// Extract the first URL from the response's Data property.
var url = response.Data.First().Url;

DALLE 2 Edit Image

You can ask DALL-E 2 model to edit your image. You can specify the prompt and the image file name. Then your image will be processed and prompt will be applied to the image.

var image = new Image("<API_KEY>", "<Organization>");

var imageRequest = new ImageEditRequest("image.png", "Add light blue background")
{
    NumberOfImages = 1,
    ResponseFormat = ResponseFormatType.Url,
    Size = ImageSize.Size512x512,
    User = "Dariusz Kacban"
};

var response = await image.EditAsync(imageRequest);

var url = response.Data.First().Url;

Support

If you have any issues or need help, please contact us: kontakt@pilsoft.platform

License

This project is licensed under the MIT License. See the LICENSE file for more information.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.7.4 359 7/18/2023
1.7.3 172 7/10/2023
1.7.2 166 7/6/2023
1.7.1 158 7/6/2023
1.7.0 158 5/12/2023
1.6.1 173 5/11/2023
1.6.0 151 5/10/2023
1.5.0 169 5/7/2023
1.4.5 157 5/5/2023
1.4.4 154 5/5/2023
1.4.3 172 4/30/2023
1.4.2 183 4/30/2023
1.4.1 171 4/30/2023
1.4.0 172 4/29/2023
1.3.0 165 4/28/2023

- Add image edition with DALL-E 2 model
- Make all methods asynchronous to improve performance and responsiveness