TypeChat.NET Project Introduction
Overview
TypeChat.NET is an innovative project that brings the concepts of TypeChat into the .NET ecosystem. It offers cross-platform libraries that enable developers to create powerful natural language interfaces utilizing language models. By focusing on strong types and type validation, TypeChat.NET aims to make software that interacts with language models more reliable and predictable.
How It Works
To illustrate how TypeChat.NET functions, consider the task of translating user intent into actions. Here's a simple example:
// Translate user intent into strongly typed Calendar Actions
var model = new LanguageModel(Config.LoadOpenAI());
var translator = new JsonTranslator<CalendarActions>(model);
// Translate natural language request
CalendarActions actions = await translator.TranslateAsync(requestText);
In this code snippet, a language model is set up to convert natural language requests into strongly typed calendar actions in a seamless manner.
Assemblies
TypeChat.NET consists of several key assemblies, each designed to handle specific tasks:
-
Microsoft.TypeChat: Focuses on translating user intent into well-defined objects that are strongly typed and validated.
-
Microsoft.TypeChat.Program: Responsible for synthesizing, validating, and executing JSON-based programs or "plans."
-
Microsoft.TypeChat.SemanticKernel: Integrates with Microsoft Semantic Kernel, extending capabilities like model integration and plugin usage.
Microsoft.TypeChat
This assembly leverages language models to transform user requests into JSON objects that conform to specific schemas. These JSON objects are then validated and translated into typed objects, ensuring error correction whenever necessary.
Key Features:
- Translation, validation, and repair of JSON data.
- Interfaces for schema customization and extensibility.
- Support for generating schemas for translation using Typescript.
Microsoft.TypeChat.Program
This assembly translates language requests into simple JSON-based programs. These programs, echoing the form of a domain-specific language, are type-checked and can be executed or compiled into .NET code.
Components:
- Program Translator for converting intent into JSON programs.
- Program Interpreter using an interpreter to run these programs.
- Program Compiler for type-checking and compiling with the dynamic language runtime.
Microsoft.TypeChat.SemanticKernel
This assembly uses Semantic Kernel 1.0 to provide advanced features such as transforming registered plugins into APIs that JSON programs can target.
Getting Started
Prerequisites
To get started with TypeChat.NET, one needs access to OpenAI language models. Models like gpt-35-turbo, gpt-4, and ada-002 are supported, with some examples working best with gpt-4.
Building and Running
The project can be built using Visual Studio 2022 or via the command line using dotnet build
. NuGet packages are available for quick integration into projects:
- Microsoft.TypeChat
- Microsoft.TypeChat.Program
- Microsoft.TypeChat.SemanticKernel
Examples
TypeChat.NET provides a variety of example projects demonstrating different aspects of its functionality, from simple sentiment analysis to interactive agents.
Example Highlights:
- Hello World: Introductory examples like Sentiment example showcase the basic usage of JsonTranslator.
- Json Programs: Examples demonstrate translating user requests into programmatic plans like simple calculator operations.
- Interactive Agents: Illustrate how interactive bots can collect user information or interact using a history-enabled dialogue.
Configuration
To utilize TypeChat.NET, you need to configure an API key for your OpenAI service or set up an Azure identity if using Azure OpenAI. Configuration details are stored in appSettings.json
.
Customization
Developers can also use their custom client by implementing the ILanguageModel
interface. This flexibility ensures that developers can cater TypeChat.NET to meet diverse and specific needs.
Conclusion
TypeChat.NET stands out as a robust framework for integrating natural language processing with .NET applications. Through strong typing and validation, it offers developers a reliable base to build applications that seamlessly interpret and act upon human language. Whether you're new to AI-driven development or looking to enhance existing projects, TypeChat.NET delivers essential tools to create sophisticated, language-aware applications.