Giter VIP home page Giter VIP logo

agentchat's Introduction

An unofficial implementation of AutoGen for dotnet

This repo contains an unofficial implementation of AutoGen for dotnet. It is a library that allows you to build a group chat bot that can help you to resolve tasks by writing and running code.

CI nightly-build

Usage

First add the following package reference to your project file:

<ItemGroup>
    <PackageReference Include="AgentChat.Core" />
    <!-- Add AgentChat.OpenAI to connect to OpenAI chat models -->
    <PackageReference Include="AgentChat.OpenAI" />
</ItemGroup>

Nightly Build Feed: https://www.myget.org/F/agentchat/api/v3/index.json

Then you can using the following code to create an agent chat.

TwoAgent Chat

using AgentChat;
var gpt35 = GPT.CreateFromOpenAI(OPENAI_API_KEY, GPT_35_MODEL_ID);
var alice = gpt35.CreateAgent(
    name: "Alice",
    roleInformation: "You are a helpful AI assistant.");

var bob = gpt35.CreateAgent(
    name: "Bob",
    roleInformation: "You are a helpful AI assistant.");

var chatHistory = await alice.SendMessagesAsync(
    bob,
    "Hi, I am Alice.",
    maxRound: 1);

// chatHistory
// From Alice: Hi, I am Alice.
// From Bob: Hi, I am Bob.

Group Chat

using AgentChat;
var gpt35 = GPT.CreateFromOpenAI(OPENAI_API_KEY, GPT_35_MODEL_ID);
var alice = gpt35.CreateAgent(
    name: "Alice",
    roleInformation: "You are a helpful AI assistant.");

var bob = gpt35.CreateAgent(
    name: "Bob",
    roleInformation: "You are a helpful AI assistant.");

var carol = gpt35.CreateAgent(
    name: "Carol",
    roleInformation: "You are a helpful AI assistant.");

var group = new GroupChat(
    chatLLM: gpt35,
    admin: alice,
    agents: new[] { bob, carol });

var chatHistory = await alice.SendMessagesAsync(
    group,
    "Hi, I am Alice.",
    maxRound: 3);
// chatHistory
// From Alice: Hi, I am Alice.
// From Bob: Hi, I am Bob.
// From Carol: Hi, I am Carol.

Function call

You can augment agent chat with function call.

// file: SayNameFunction.cs

using AgentChat;
/// <summary>
/// Say name.
/// </summary>
/// <param name="name">name.</param>
[FunctionAttribution]
public async Task<string> SayName(string name)
{
    return $"Your name is {name}.";
}

// file: Program.cs
using AgentChat;
var sayNameFunction = new SayNameFunction();
var gpt35 = GPT.CreateFromOpenAI(OPENAI_API_KEY, GPT_35_MODEL_ID);
var heisenberg = gpt35.CreateAgent(
    name: "Heisenberg",
    roleInformation: "You are Heisenberg.");

var bob = gpt35.CreateAgent(
    name: "Bob",
    roleInformation: "You call SayName function.",
    functionMap: new new Dictionary<FunctionDefinition, Func<string, Task<string>>>{
        { sayNameFunction.SayNameFunction, sayNameFunction.SayNameWrapper }
    });

var chatHistory = await heisenberg.SendMessagesAsync(
    bob,
    "Say, My, Name.",
    maxRound: 1);

// chatHistory
// From Heisenberg: Say, My, Name.
// From Bob: Your name is Heisenberg.

AgentChat.OpenAI provides a source generator that generates FunctionDefition and wrapper caller according to the signature of a function. For more information, please check Facilitate Chat FunctionCall for GPT-series model.

Notebook Examples

You can find notebook examples from here.

More Examples

You can find more examples from below table.

Name Description
dotnet interpreter Using LLM to resolve task by writing and running csharp code.
coder + runner Group chat using coder-runner pattern. This example shows how to use a coder agent and a runner agent to find the most recent PR from ML.Net using github api and save it under pr.txt.
coder + runner + examplar Group chat using coder-runner-examplar pattern. This example shows how to use a mlnet examplar agent, a coder agent and a runner agent to train a lightgbm binary classifier on a dummy dataset and save the model as lgbm.mlnet.

To run the examples, you first need to configure the environment variables. See How to configure environment for GPT access for more information.

Group chat

check out our AutoGen library for more information over group chat.

How to configure environment for GPT access

In order to run examples under this repo, you need to provide the following environment variables:

OpenAI

  • OPENAI_API_KEY - your OpenAI API key

Azure OpenAI

  • AZURE_OPENAI_ENDPOINT - your Azure OpenAI endpoint
  • AZURE_OPENAI_API_KEY - your Azure OpenAI key
  • (Optional) AZURE_GPT_35_MODEL_ID - GPT-3.5 model name (default: gpt-35-turbo)
  • (Optional) AZURE_GPT_4_MODEL_ID - GPT-4 model name (default: gpt-4.0)

agentchat's People

Contributors

littlelittlecloud avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.