ChatGptNet Project Overview
ChatGptNet is an innovative integration library designed for .NET applications, enabling users to harness the powerful capabilities of OpenAI’s ChatGPT. It supports integrations with OpenAI as well as the Azure OpenAI Service, making it a versatile solution for developers aiming to incorporate advanced conversational AI into their software.
Installation
The installation process is straightforward, with the library available via NuGet, a popular package manager for .NET. To install ChatGptNet, a user can search for "ChatGptNet" in the NuGet Package Manager GUI or simply run the following command in the .NET CLI:
dotnet add package ChatGptNet
Configuration
When setting up ChatGptNet, it's essential to register the ChatGPT service at the application's startup. Users can configure the library to connect with either OpenAI or the Azure OpenAI Service. Here's a brief overview of how each option can be set up:
OpenAI Configuration
- ApiKey: A required parameter that is found on the user settings page of the OpenAI account.
- Organization: Optional, for users belonging to multiple organizations, where specifying the organization determines which subscription quota the API requests will affect.
Azure OpenAI Service Configuration
- ResourceName: Required parameter specifying the name of the Azure OpenAI Resource.
- ApiKey: Azure OpenAI requires an API Key or Azure Active Directory token for authentication.
- ApiVersion: Optionally specifies the API version to use.
- AuthenticationType: Determines if the key is an API Key or an Azure Active Directory token. Defaults to "ApiKey".
Default Models
ChatGptNet allows configuration of default models used for generating responses and embeddings. Users can specify these defaults at setup or override them for individual requests. The available models for OpenAI include gpt-3.5 and gpt-4 variants, among others.
Caching and Conversation Management
The library supports features vital for maintaining conversational state, such as message caching. Developers can manage how long messages are retained and customize the cache handling if needed through the IChatGptCache
interface. This feature allows for consistent interactions without having to repeat the context continually.
Advanced Configuration
Users have the flexibility to configure ChatGptNet dynamically using external sources like an appsettings.json
file or injecting configuration via services such as IServiceProvider
. This flexibility is beneficial for scenarios where configurations need to adapt dynamically, for instance, when individual users have different API Keys.
HTTP Client Customization
For developers needing custom HTTP configurations, such as implementing retry policies, ChatGptNet supports this through the integration of third-party libraries like Polly. This setup is essential for increasing the resilience of applications against network issues.
Usage
ChatGptNet can be employed in various .NET applications built with .NET 6.0 or later. It provides methods such as AskAsync
and AskStreamAsync
for querying the language model, supporting both synchronous and streaming response patterns. This can be particularly useful in web applications needing real-time interaction capabilities.
Enhancements in Interaction
ChatGptNet allows for intelligent conversation management and customization of the assistant's behavior. Through system messages set via the SetupAsync
method, developers can mold the personality of the conversational agent.
Conclusion
In essence, ChatGptNet is a robust solution for .NET developers aiming to integrate conversational AI into their applications. With its comprehensive configuration options, caching capabilities, and support for both OpenAI and Azure OpenAI services, it caters to a wide range of development scenarios, making it an invaluable tool for enhancing user interaction through dialogue.