Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
doodledood committed Nov 15, 2023
1 parent 5015555 commit 84c12f8
Show file tree
Hide file tree
Showing 13 changed files with 151 additions and 611 deletions.
8 changes: 2 additions & 6 deletions chatflock/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,25 +209,23 @@ def render_new_chat_message(self, chat: "Chat", message: ChatMessage) -> None:
class GeneratedChatComposition:
participants: Sequence[ChatParticipant]
participants_interaction_schema: str
termination_condition: str


class ChatCompositionGenerator(abc.ABC):
@abc.abstractmethod
def generate_composition_for_chat(
self,
chat: "Chat",
goal: str,
composition_suggestion: Optional[str] = None,
participants_interaction_schema: Optional[str] = None,
termination_condition: Optional[str] = None,
interaction_schema: Optional[str] = None,
) -> GeneratedChatComposition:
raise NotImplementedError()


class Chat:
backing_store: ChatDataBackingStore
renderer: ChatRenderer
goal: str
name: Optional[str] = None
max_total_messages: Optional[int] = None
hide_messages: bool = False
Expand All @@ -238,7 +236,6 @@ def __init__(
renderer: ChatRenderer,
initial_participants: Optional[Sequence[ChatParticipant]] = None,
name: Optional[str] = None,
goal: str = "This is a regular chatroom, the goal is to just have a conversation.",
max_total_messages: Optional[int] = None,
hide_messages: bool = False,
):
Expand All @@ -247,7 +244,6 @@ def __init__(

self.backing_store = backing_store
self.renderer = renderer
self.goal = goal
self.name = name
self.hide_messages = hide_messages
self.max_total_messages = max_total_messages
Expand Down
55 changes: 13 additions & 42 deletions chatflock/composition_generators/__init__.py
Original file line number Diff line number Diff line change
@@ -1,69 +1,40 @@
from typing import List, Literal, Optional, Union
from typing import List, Literal, Optional

from pydantic import BaseModel, Field


class IndividualParticipantToAddSchema(BaseModel):
type: Literal["individual"]
name: str = Field(
description="Name of the participant to add. Generate a creative name that fits the role and mission. You can "
description="Name of the individual to add. Generate a creative name that fits the role and mission. You can "
"use play on words, stereotypes, or any other way you want to be original."
)
role: str = Field(description='Role of the participant to add. Title like "CEO" or "CTO", for example.')
mission: str = Field(
description="Personal mission of the participant to add. Should be a detailed " "mission statement."
description="Personal mission of the individual to add. Should be a detailed mission statement."
)
symbol: str = Field(
description="A unicode symbol of the participant to add (for presentation in chat). This "
description="A unicode symbol of the individual to add (for presentation in chat). This "
"needs to reflect the role."
)
tools: Optional[List[str]] = Field(
description="List of useful tools that the participant should have access to in order to achieve their goal. "
"Must be one of the available tools given as input. Do not give tools if you think the participant "
description="List of useful tools that an individual should have access to in order to achieve their goal. "
"Must be one of the available tools given as input. Do not give tools if you think the individual "
"should not have access to any tools or non of the available tools are useful for the goal."
)

def __str__(self):
return f"{self.symbol} {self.name} ({self.role})"


class TeamParticipantToAddSchema(BaseModel):
type: Literal["team"]
name: str = Field(description="Name of the team to add.")
mission: str = Field(description="Mission of the team to add. Should be a detailed mission statement.")
composition_suggestion: str = Field(
description="List of roles of individual participants or names of sub-teams that are suggested to achieve the "
"sub-mission set."
class CreateTeamCompositionForGoalOutputSchema(BaseModel):
team_composition: List[IndividualParticipantToAddSchema] = Field(
description="List of members that make up the team. Must include the fixed members."
)
symbol: str = Field(description="A unicode symbol of the team to add (for presentation in chat).")

def __str__(self):
return f"{self.symbol} {self.name}"


class ManageParticipantsOutputSchema(BaseModel):
participants_to_remove: List[str] = Field(description="List of participants to be removed.")
participants_to_add: List[Union[IndividualParticipantToAddSchema, TeamParticipantToAddSchema]] = Field(
description="List of participants (individuals and teams) to be added. DO NOT include individual participants "
"that are a part of a sub-team. The sub-team will handle the composition based on the suggestion. "
'For example, if the sub-team "Development Team" is suggested to be added, do not include '
"individual participants within that team even if they are mentioned. Instead, suggest the team "
"composition within the team definition.",
examples=[
'[{"type": "individual", "name": "John Doe", "role": "CEO", "mission": "Lead the company.", "symbol": "🤵"},'
'{"type": "team", "name": "Development Team", "mission": "Develop the product.", '
'"composition_suggestion": "The team should include a Team Leader, Software Engineer, QA Engineer, '
'and a Software Architect", "symbol": "🛠️"}]'
],
)
updated_speaker_interaction_schema: str = Field(
description="An updated (or new) version of the original interaction schema to better reflect how to achieve "
"the goal."
)
updated_termination_condition: str = Field(
description="An updated (or new) version of the termination condition to better reflect the achievement of the "
"goal."
interaction_schema: str = Field(
description="A member interaction schema that includes the phases, "
"how members should interact with each other to achieve the goal, etc."
)


__all__ = ["IndividualParticipantToAddSchema", "TeamParticipantToAddSchema", "ManageParticipantsOutputSchema"]
__all__ = ["IndividualParticipantToAddSchema", "CreateTeamCompositionForGoalOutputSchema"]
Loading

0 comments on commit 84c12f8

Please sign in to comment.