-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconv-standup.py
More file actions
76 lines (59 loc) · 1.75 KB
/
Copy pathconv-standup.py
File metadata and controls
76 lines (59 loc) · 1.75 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
import os
from dotenv import load_dotenv
def get_openai_api_key():
"""
Loads the OpenAI API key from the environment or a .env file.
Raises an error if not found.
"""
load_dotenv() # Load environment variables from .env if present
api_key = os.getenv("OPENAI_API_KEY")
if not api_key:
raise ValueError("OPENAI_API_KEY not found. Please set it in your environment or .env file.")
return api_key
OPENAI_API_KEY = get_openai_api_key()
llm_config = {"model": "gpt-4"}
from autogen import ConversableAgent
agent = ConversableAgent(
name="chatbot",
llm_config=llm_config,
human_input_mode="NEVER",
)
reply = agent.generate_reply(
messages=[{"content": "Tell me 2 joke.", "role": "user"}]
)
print(reply)
reply = agent.generate_reply(
messages=[{"content": "teach me langchain.", "role": "user"}]
)
print(reply)
cathy = ConversableAgent(
name="cathy",
system_message=
"Your name is Cathy and you are a stand-up comedian.",
llm_config=llm_config,
human_input_mode="NEVER",
)
joe = ConversableAgent(
name="joe",
system_message=
"Your name is Joe and you are a stand-up comedian. "
"Start the next joke from the punchline of the previous joke.",
llm_config=llm_config,
human_input_mode="NEVER",
)
chat_result = joe.initiate_chat(
recipient=cathy,
message="I'm Joe. Cathy, let's keep the jokes rolling.",
max_turns=2,
)
import pprint
#pprint.pprint(chat_result.chat_history)
pprint.pprint(chat_result.cost)
#pprint.pprint(chat_result.summary)
chat_result = joe.initiate_chat(
cathy,
message="I'm Joe. Cathy, let's keep the jokes rolling.",
max_turns=2,
summary_method="reflection_with_llm",
summary_prompt="Summarize the conversation",
)