mirror of
https://github.com/microsoft/autogen.git
synced 2025-10-09 06:56:34 +00:00

* create OpenAI tests project * update * update * add tests * add mroe tests: * update comment * Update dotnet/src/AutoGen.OpenAI/Middleware/OpenAIChatRequestMessageConnector.cs Co-authored-by: David Luong <davidluong98@gmail.com> * Update AutoGen.OpenAI.Tests.csproj * fix build --------- Co-authored-by: David Luong <davidluong98@gmail.com>
42 lines
1.2 KiB
C#
42 lines
1.2 KiB
C#
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// EchoAgent.cs
|
|
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AutoGen.Tests
|
|
{
|
|
public class EchoAgent : IStreamingAgent
|
|
{
|
|
public EchoAgent(string name)
|
|
{
|
|
Name = name;
|
|
}
|
|
public string Name { get; }
|
|
|
|
public Task<IMessage> GenerateReplyAsync(
|
|
IEnumerable<IMessage> conversation,
|
|
GenerateReplyOptions? options = null,
|
|
CancellationToken ct = default)
|
|
{
|
|
// return the most recent message
|
|
var lastMessage = conversation.Last();
|
|
lastMessage.From = this.Name;
|
|
|
|
return Task.FromResult(lastMessage);
|
|
}
|
|
|
|
public async IAsyncEnumerable<IStreamingMessage> GenerateStreamingReplyAsync(IEnumerable<IMessage> messages, GenerateReplyOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
|
|
{
|
|
foreach (var message in messages)
|
|
{
|
|
message.From = this.Name;
|
|
yield return message;
|
|
}
|
|
}
|
|
}
|
|
}
|