You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Program.cs 1.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // Program.cs
  3. using System.Runtime.CompilerServices;
  4. using AutoGen.Core;
  5. using AutoGen.WebAPI;
  6. var alice = new DummyAgent("alice");
  7. var bob = new DummyAgent("bob");
  8. var builder = WebApplication.CreateBuilder(args);
  9. // Add services to the container.
  10. // run endpoint at port 5000
  11. builder.WebHost.UseUrls("http://localhost:5000");
  12. var app = builder.Build();
  13. app.UseAgentAsOpenAIChatCompletionEndpoint(alice);
  14. app.UseAgentAsOpenAIChatCompletionEndpoint(bob);
  15. app.Run();
  16. public class DummyAgent : IStreamingAgent
  17. {
  18. public DummyAgent(string name = "dummy")
  19. {
  20. Name = name;
  21. }
  22. public string Name { get; }
  23. public async Task<IMessage> GenerateReplyAsync(IEnumerable<IMessage> messages, GenerateReplyOptions? options = null, CancellationToken cancellationToken = default)
  24. {
  25. return new TextMessage(Role.Assistant, $"I am dummy {this.Name}", this.Name);
  26. }
  27. public async IAsyncEnumerable<IMessage> GenerateStreamingReplyAsync(IEnumerable<IMessage> messages, GenerateReplyOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
  28. {
  29. var reply = $"I am dummy {this.Name}";
  30. foreach (var c in reply)
  31. {
  32. yield return new TextMessageUpdate(Role.Assistant, c.ToString(), this.Name);
  33. }
  34. }
  35. }