mirror of
https://github.com/microsoft/autogen.git
synced 2025-06-26 22:30:10 +00:00

<!-- Thank you for your contribution! Please review https://microsoft.github.io/autogen/docs/Contribute before opening a pull request. --> <!-- Please add a reviewer to the assignee section when you create a PR. If you don't have the access to it, we will shortly find a reviewer and assign them to your PR. --> ## Why are these changes needed? <!-- Please give a short summary of the change and the problem this solves. --> ## Related issue number <!-- For example: "Closes #1234" --> ## Checks - [ ] I've included any doc changes needed for https://microsoft.github.io/autogen/. See https://microsoft.github.io/autogen/docs/Contribute#documentation to build and test documentation locally. - [ ] I've added tests (if relevant) corresponding to the changes introduced in this PR. - [ ] I've made sure all auto checks have passed.
46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Program.cs
|
|
|
|
using System.Runtime.CompilerServices;
|
|
using AutoGen.Core;
|
|
using AutoGen.WebAPI;
|
|
|
|
var alice = new DummyAgent("alice");
|
|
var bob = new DummyAgent("bob");
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
// Add services to the container.
|
|
|
|
// run endpoint at port 5000
|
|
builder.WebHost.UseUrls("http://localhost:5000");
|
|
var app = builder.Build();
|
|
|
|
app.UseAgentAsOpenAIChatCompletionEndpoint(alice);
|
|
app.UseAgentAsOpenAIChatCompletionEndpoint(bob);
|
|
|
|
app.Run();
|
|
|
|
public class DummyAgent : IStreamingAgent
|
|
{
|
|
public DummyAgent(string name = "dummy")
|
|
{
|
|
Name = name;
|
|
}
|
|
|
|
public string Name { get; }
|
|
|
|
public async Task<IMessage> GenerateReplyAsync(IEnumerable<IMessage> messages, GenerateReplyOptions? options = null, CancellationToken cancellationToken = default)
|
|
{
|
|
return new TextMessage(Role.Assistant, $"I am dummy {this.Name}", this.Name);
|
|
}
|
|
|
|
public async IAsyncEnumerable<IMessage> GenerateStreamingReplyAsync(IEnumerable<IMessage> messages, GenerateReplyOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
|
|
{
|
|
var reply = $"I am dummy {this.Name}";
|
|
foreach (var c in reply)
|
|
{
|
|
yield return new TextMessageUpdate(Role.Assistant, c.ToString(), this.Name);
|
|
}
|
|
}
|
|
}
|