-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanual_hierarchical_participant.py
64 lines (59 loc) · 2.76 KB
/
manual_hierarchical_participant.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import typer
from dotenv import load_dotenv
from halo import Halo
from chatflock.backing_stores import InMemoryChatDataBackingStore
from chatflock.base import Chat
from chatflock.conductors import LangChainBasedAIChatConductor, RoundRobinChatConductor
from chatflock.participants.group import GroupBasedChatParticipant
from chatflock.participants.langchain import LangChainBasedAIChatParticipant
from chatflock.participants.user import UserChatParticipant
from chatflock.renderers import TerminalChatRenderer
from examples.common import create_chat_model
def manual_hierarchical_participant(model: str = "gpt-4-1106-preview", temperature: float = 0.0) -> None:
chat_model = create_chat_model(model=model, temperature=temperature)
spinner = Halo(spinner="dots")
comedy_team = GroupBasedChatParticipant(
group_name="Comedy Team",
mission="Collaborate on funny humour-filled responses based on the original request for the user",
chat=Chat(
backing_store=InMemoryChatDataBackingStore(),
renderer=TerminalChatRenderer(),
initial_participants=[
LangChainBasedAIChatParticipant(
name="Bob",
role="Chief Comedian",
personal_mission="Take questions from the user and collaborate with "
"Tom to come up with a succinct funny (yet realistic) "
"response. Short responses are preferred.",
chat_model=chat_model,
spinner=spinner,
),
LangChainBasedAIChatParticipant(
name="Tom",
role="Junior Comedian",
personal_mission="Collaborate with Bob to come up with a succinct "
"funny (yet realistic) response to the user. Short responses are preferred",
chat_model=chat_model,
spinner=spinner,
),
],
),
chat_conductor=LangChainBasedAIChatConductor(
chat_model=chat_model,
goal="Come up with a funny succinct response to the user.",
interaction_schema="Bob should collaborate with Tom to come up with a great funny and succinct response. "
"When one is agreed upon, the chat should end",
spinner=spinner,
),
spinner=spinner,
)
user = UserChatParticipant(name="User")
participants = [user, comedy_team]
chat = Chat(
backing_store=InMemoryChatDataBackingStore(), renderer=TerminalChatRenderer(), initial_participants=participants
)
chat_conductor = RoundRobinChatConductor()
chat_conductor.initiate_dialog(chat=chat)
if __name__ == "__main__":
load_dotenv()
typer.run(manual_hierarchical_participant)