forked from filip-michalsky/SalesGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
79 lines (68 loc) · 2.45 KB
/
run.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import argparse
import json
import os
from langchain.chat_models import ChatOpenAI
from salesgpt.agents import SalesGPT
if __name__ == "__main__":
# import your OpenAI key (put in your .env file)
with open(".env", "r") as f:
env_file = f.readlines()
envs_dict = {
key.strip("'"): value.strip("\n")
for key, value in [(i.split("=")) for i in env_file]
}
os.environ["OPENAI_API_KEY"] = envs_dict["OPENAI_API_KEY"]
# Initialize argparse
parser = argparse.ArgumentParser(description="Description of your program")
# Add arguments
parser.add_argument(
"--config", type=str, help="Path to agent config file", default=""
)
parser.add_argument("--verbose", type=bool, help="Verbosity", default=False)
parser.add_argument(
"--max_num_turns",
type=int,
help="Maximum number of turns in the sales conversation",
default=10,
)
# Parse arguments
args = parser.parse_args()
# Access arguments
config_path = args.config
verbose = args.verbose
max_num_turns = args.max_num_turns
llm = ChatOpenAI(temperature=0.2)
if config_path == "":
print("No agent config specified, using a standard config")
USE_TOOLS = "True" # keep boolean as string to be consistent with JSON configs.
if USE_TOOLS == "True":
sales_agent = SalesGPT.from_llm(
llm,
use_tools=USE_TOOLS,
product_catalog="examples/sample_product_catalog.txt",
salesperson_name="Ted Lasso",
verbose=verbose,
)
else:
sales_agent = SalesGPT.from_llm(llm, verbose=verbose)
else:
with open(config_path, "r", encoding="UTF-8") as f:
config = json.load(f)
print(f"Agent config {config}")
sales_agent = SalesGPT.from_llm(llm, verbose=verbose, **config)
sales_agent.seed_agent()
print("=" * 10)
cnt = 0
while cnt != max_num_turns:
cnt += 1
if cnt == max_num_turns:
print("Maximum number of turns reached - ending the conversation.")
break
sales_agent.step()
# end conversation
if "<END_OF_CALL>" in sales_agent.conversation_history[-1]:
print("Sales Agent determined it is time to end the conversation.")
break
human_input = input("Your response: ")
sales_agent.human_step(human_input)
print("=" * 10)