Remove runtime arg from group chat manager (#106)

This commit is contained in:
Jack Gerrits 2024-06-22 14:51:30 -04:00 committed by GitHub
parent 2d74fa9caf
commit 0d697037a1
7 changed files with 8 additions and 16 deletions

View File

@ -25,7 +25,6 @@ from agnext.chat.memory import BufferedChatMemory
from agnext.chat.patterns import GroupChatManager
from agnext.chat.types import TextMessage
from agnext.components.models import OpenAI, SystemMessage
from agnext.core import AgentRuntime
```
Next, let's create the runtime:
@ -85,7 +84,6 @@ runtime.register(
"Manager",
lambda: GroupChatManager(
description="A manager that orchestrates a back-and-forth converation between a coder and a reviewer.",
runtime=runtime,
participants=[coder.id, reviewer.id], # The order of the participants indicates the order of speaking.
memory=BufferedChatMemory(buffer_size=10),
termination_word="APPROVE",
@ -121,7 +119,7 @@ Below is the output of a run of the group chat example:
````none
--------------------------------------------------------------------------------
Human: Write a Python script that find near-duplicate paragraphs in a directory of many text files. Output the file names, line numbers and the similarity score of the near-duplicate paragraphs.
Human: Write a Python script that find near-duplicate paragraphs in a directory of many text files. Output the file names, line numbers and the similarity score of the near-duplicate paragraphs.
--------------------------------------------------------------------------------
Coder: To achieve the task of finding near-duplicate paragraphs in a directory with many text files and outputting the file names, line numbers, and the similarity score, we can use the following approach:
@ -167,15 +165,15 @@ def find_near_duplicates(directory, similarity_threshold=0.8):
paragraphs = read_araaphs_from_file(file_path)
processed_paragraphs = [preprocess_text(para) for para in paragraphs]
files_data.append((f, paragraphs, processed_paragraphs))
# Vectorizing text data
all_processed_paras = [data for _, _, processed_paras in files_data for data in processed_paras]
vectorizer = TfidfVectorizer()
tfidf_matrix = vectorizer.fit_transform(all_processed_paras)
# Compute cosine similarity
cos_similarity_matrix = cosine_similarity(tfidf_matrix)
# Checking for near-duplicates based on threshold
for i, (file_i, paragraphs_i, _) in enumerate(fileElot_data):
for j in range(i + 1, len(files_data)):
@ -189,7 +187,7 @@ def find_near_duplicates(directory, similarity_threshold=0.8):
)
if __name__ == '__main__':
DIRECTORY_PATH = 'path/to/directory'
find_nearduplmany czup costsD etgt*tyn dup examineyemitour EgoreOtyp als
find_nearduplmany czup costsD etgt*tyn dup examineyemitour EgoreOtyp als
```
This script accomplishes the task as outlined. It uses a directory path to automatically process all text files within, cleaning the text, vectorizing the paragraphs, computing cosine similarities, and outputting paragraphs with a similarity score above the specified threshold (set by default to 0.8, but can be adjusted). Adjust paths, thresholds, and other configurations as necessary for your specific use case
@ -281,7 +279,7 @@ def find_near_duplicates(directory, similarity_threshold=0.8):
# Checking for near-duplicates based on threshold
n = sum(len(paras) for _, paras, _ in files_data) # Total number of paragraphs
idx = 0
idx = 0
for i, (file_i, paragraphs_i, _) in enumerate(files_data):
for index_i, para_i in enumerate(paragraphs_i):
global_idx_i = idx + index_i

View File

@ -198,7 +198,6 @@ def assistant_chat(runtime: AgentRuntime) -> AgentId:
"GroupChatManager",
lambda: GroupChatManager(
description="A group chat manager.",
runtime=runtime,
memory=BufferedChatMemory(buffer_size=10),
participants=[assistant, user],
),

View File

@ -190,7 +190,6 @@ def chess_game(runtime: AgentRuntime) -> None: # type: ignore
"ChessGame",
lambda: GroupChatManager(
description="A chess game between two agents.",
runtime=runtime,
memory=BufferedChatMemory(buffer_size=10),
participants=[white, black], # white goes first
),

View File

@ -63,7 +63,6 @@ def coder_reviewer(runtime: AgentRuntime, app: TextualChatApp) -> None:
"Manager",
lambda: GroupChatManager(
description="A manager that orchestrates a back-and-forth converation between a coder and a reviewer.",
runtime=runtime,
participants=[coder.id, reviewer.id], # The order of the participants indicates the order of speaking.
memory=BufferedChatMemory(buffer_size=10),
termination_word="APPROVE",

View File

@ -76,7 +76,6 @@ def illustrator_critics(runtime: AgentRuntime, app: TextualChatApp) -> None:
"GroupChatManager",
lambda: GroupChatManager(
description="A chat manager that handles group chat.",
runtime=runtime,
memory=BufferedChatMemory(buffer_size=5),
participants=[illustrator.id, critic.id, descriptor.id],
termination_word="APPROVE",

View File

@ -242,7 +242,6 @@ def software_consultancy(runtime: AgentRuntime, app: TextualChatApp) -> None: #
"GroupChatManager",
lambda: GroupChatManager(
description="A group chat manager.",
runtime=runtime,
memory=HeadAndTailChatMemory(head_size=1, tail_size=10),
model_client=OpenAI(model="gpt-4-turbo"),
participants=[developer, product_manager, ux_designer, illustrator, user_agent],

View File

@ -4,7 +4,7 @@ from typing import Any, Callable, List, Mapping
from ...components import TypeRoutedAgent, message_handler
from ...components.memory import ChatMemory
from ...components.models import ChatCompletionClient
from ...core import AgentId, AgentProxy, AgentRuntime, CancellationToken
from ...core import AgentId, AgentProxy, CancellationToken
from ..types import (
Message,
MultiModalMessage,
@ -43,7 +43,6 @@ class GroupChatManager(TypeRoutedAgent):
def __init__(
self,
description: str,
runtime: AgentRuntime,
participants: List[AgentId],
memory: ChatMemory[Message],
model_client: ChatCompletionClient | None = None,
@ -55,7 +54,7 @@ class GroupChatManager(TypeRoutedAgent):
self._memory = memory
self._client = model_client
self._participants = participants
self._participant_proxies = dict((p, AgentProxy(p, runtime)) for p in participants)
self._participant_proxies = dict((p, AgentProxy(p, self.runtime)) for p in participants)
self._termination_word = termination_word
for key, value in transitions.items():
if not value: