forked from modelscope/agentscope
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request modelscope#5 from FredericW/dev_copilot_zitao
copilot dialog agents update
- Loading branch information
Showing
5 changed files
with
71 additions
and
84 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- coding: utf-8 -*- | ||
""" Group chat utils.""" | ||
import re | ||
from typing import Sequence | ||
|
||
|
||
def select_next_one(agents: Sequence, rnd: int) -> Sequence: | ||
""" | ||
Select next agent. | ||
""" | ||
return agents[rnd % len(agents)] | ||
|
||
|
||
def filter_agents(string: str, agents: Sequence) -> Sequence: | ||
""" | ||
This function filters the input string for occurrences of the given names | ||
prefixed with '@' and returns a list of the found names. | ||
""" | ||
if len(agents) == 0: | ||
return [] | ||
|
||
# Create a pattern that matches @ followed by any of the candidate names | ||
pattern = ( | ||
r"@(" + "|".join(re.escape(agent.name) for agent in agents) + r")\b" | ||
) | ||
|
||
# Find all occurrences of the pattern in the string | ||
matches = re.findall(pattern, string) | ||
|
||
# Create a dictionary mapping agent names to agent objects for quick lookup | ||
agent_dict = {agent.name: agent for agent in agents} | ||
|
||
# Return the list of matched agent objects preserving the order | ||
ordered_agents = [ | ||
agent_dict[name] for name in matches if name in agent_dict | ||
] | ||
return ordered_agents |
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