-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[.Net] add SendAsync api to iterate group chat step by step (#3214)
* add SendAsync api and tests * update example to use new sendAsync API
- Loading branch information
1 parent
cf29a2f
commit 2cfaf73
Showing
5 changed files
with
140 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// GroupChatTests.cs | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace AutoGen.Tests; | ||
|
||
public class GroupChatTests | ||
{ | ||
[Fact] | ||
public async Task ItSendMessageTestAsync() | ||
{ | ||
var alice = new DefaultReplyAgent("Alice", "I am alice"); | ||
var bob = new DefaultReplyAgent("Bob", "I am bob"); | ||
|
||
var groupChat = new GroupChat([alice, bob]); | ||
|
||
var chatHistory = new List<IMessage>(); | ||
|
||
var maxRound = 10; | ||
await foreach (var message in groupChat.SendAsync(chatHistory, maxRound)) | ||
{ | ||
chatHistory.Add(message); | ||
} | ||
|
||
chatHistory.Count().Should().Be(10); | ||
} | ||
|
||
[Fact] | ||
public async Task ItTerminateConversationWhenAgentReturnTerminateKeyWord() | ||
{ | ||
var alice = new DefaultReplyAgent("Alice", "I am alice"); | ||
var bob = new DefaultReplyAgent("Bob", "I am bob"); | ||
var cathy = new DefaultReplyAgent("Cathy", $"I am cathy, {GroupChatExtension.TERMINATE}"); | ||
|
||
var groupChat = new GroupChat([alice, bob, cathy]); | ||
|
||
var chatHistory = new List<IMessage>(); | ||
|
||
var maxRound = 10; | ||
await foreach (var message in groupChat.SendAsync(chatHistory, maxRound)) | ||
{ | ||
chatHistory.Add(message); | ||
} | ||
|
||
chatHistory.Count().Should().Be(3); | ||
chatHistory.Last().From.Should().Be("Cathy"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters