ChatGPT.Net 2.0.0

dotnet add package ChatGPT.Net --version 2.0.0
NuGet\Install-Package ChatGPT.Net -Version 2.0.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="ChatGPT.Net" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ChatGPT.Net --version 2.0.0
#r "nuget: ChatGPT.Net, 2.0.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 ChatGPT.Net as a Cake Addin
#addin nuget:?package=ChatGPT.Net&version=2.0.0

// Install ChatGPT.Net as a Cake Tool
#tool nuget:?package=ChatGPT.Net&version=2.0.0

ChatGPT.Net - .Net Library for ChatGPT [Discord]

Other versions [NodeJS Version]

Nuget Package Nuget Package GitHub issues GitHub forks GitHub stars GitHub license Discord server

Check the new Google Bard Chatbot!

The ChatGPT.Net is a C# library for ChatGPT using official OpenAI API that allows developers to access ChatGPT, a chat-based large language model. With this API, developers can send queries to ChatGPT and receive responses in real-time, making it easy to integrate ChatGPT into their own applications.

using ChatGPT.Net;

// ChatGPT Official API
var bot = new ChatGpt("<API_KEY>");

var response = await bot.Ask("What is the weather like today?");
Console.WriteLine(response);

Table of Contents

Features

  • Easy to use.
  • Using official OpenAI API.
  • Supports both free and pro accounts.
  • Supports multiple accounts, and multiple conversations.
  • Support response streaming, so you can get response while the model is still generating it.

Getting Started

To install ChatGPT.Net, run the following command in the Package Manager Console:

Install-Package ChatGPT.Net

Alternatively, you can install it using the .NET Core command-line interface:

dotnet add package ChatGPT.Net

Usage

ChatGPT Official API

Here is a sample code showing how to use ChatGPT.Net:

using ChatGPT.Net;

// ChatGPT Official API
var bot = new ChatGpt("<API_KEY>");

// get response
var response = await bot.Ask("What is the weather like today?");
Console.WriteLine(response);

// stream response
await bot.AskStream(response => {
    Console.WriteLine(response);
}, "What is the weather like today?");

// get response for a specific conversation
var response = await bot.Ask("What is the weather like today?", "conversation name");
Console.WriteLine(response);

// stream response for a specific conversation
await bot.AskStream(response => {
    Console.WriteLine(response);
}, "What is the weather like today?", "conversation name");

ChatGPT Unofficial API

Here is a sample code showing how to integrate (chat.openai.com) with your applications using ChatGPT.Net:

using ChatGPT.Net;

// ChatGPT Official API
var bot = new ChatGptUnofficial("<SESSION_TOKEN>");

// get response
var response = await bot.Ask("What is the weather like today?");
Console.WriteLine(response);

// stream response
await bot.AskStream(response => {
    Console.WriteLine(response);
}, "What is the weather like today?");

// get response for a specific conversation
var response = await bot.Ask("What is the weather like today?", "conversation name");
Console.WriteLine(response);

// stream response for a specific conversation
await bot.AskStream(response => {
    Console.WriteLine(response);
}, "What is the weather like today?", "conversation name");

Configuration options

ChatGPT Official API

ChatGptOptions
{
    string BaseUrl; // Default: https://api.openai.com
    string Model; // Default: gpt-3.5-turbo
    double Temperature; // Default: 0.9;
    double TopP; // Default: 1.0;
    long MaxTokens; // Default: 64;
    string[]? Stop; // Default: null;
    double PresencePenalty; // Default: 0.0;
    double FrequencyPenaltyl; // Default: 0.0;
}

ChatGPT Unofficial API

ChatGptUnofficialOptions
{
    string BaseUrl; // Default: https://api.pawan.krd
    string Model; // Default: text-davinci-002-render-sha
}

Examples

ChatGPT Console App

This is a simple console app that uses ChatGPT.Net to interact with ChatGPT.

using ChatGPT.Net;

// ChatGPT Official API
var bot = new ChatGpt("<API_KEY>");

var prompt = string.Empty;

while (true)
{
    Console.Write("You: ");
    prompt = Console.ReadLine();
    if (prompt is null) break;
    if (string.IsNullOrWhiteSpace(prompt)) break;
    if (prompt == "exit") break;
    Console.Write("ChatGPT: ");
    await bot.AskStream(Console.Write, prompt, "default");
    Console.WriteLine();
}

Use a different model

You can use a different model by passing the model name to the constructor.

var bot = new ChatGpt("<API_KEY>", new ChatGptOptions
{
    Model = "text-davinci-002-render-paid"
});

Using ChatGPT Official API For Free

you can use ChatGPT Official API by setting the base url to a free reverse proxy server like ChatGPT Free Reverse Proxy

var bot = new ChatGpt("<API_KEY>", new ChatGptOptions
{
    BaseUrl = "https://api.pawan.krd"
});

License

This project is licensed under the MIT License - see the LICENSE file for details

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 is compatible.  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
2.0.0 25,514 4/1/2023
1.1.5 4,553 1/28/2023
1.1.4 1,438 1/21/2023
1.1.3 1,374 1/16/2023
1.1.2 1,789 1/7/2023
1.1.1 1,081 1/6/2023
1.1.0 1,193 12/30/2022
1.0.3 1,146 12/21/2022
1.0.2 1,048 12/21/2022
1.0.1 1,093 12/21/2022
1.0.0 1,241 12/19/2022