forked from filip-michalsky/SalesGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
103 lines (86 loc) · 3.12 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import argparse
import json
import logging
import os
import warnings
from dotenv import load_dotenv
from langchain_community.chat_models import ChatLiteLLM
from salesgpt.agents import SalesGPT
load_dotenv() # loads .env file
# Suppress warnings
warnings.filterwarnings("ignore")
# Suppress logging
logging.getLogger().setLevel(logging.CRITICAL)
# LangSmith settings section, set TRACING_V2 to "true" to enable it
# or leave it as it is, if you don't need tracing (more info in README)
os.environ["LANGCHAIN_TRACING_V2"] = "false"
os.environ["LANGCHAIN_ENDPOINT"] = "https://api.smith.langchain.com"
os.environ["LANGCHAIN_API_KEY"] = os.getenv("LANGCHAIN_SMITH_API_KEY", "")
os.environ["LANGCHAIN_PROJECT"] = "" # insert you project name here
if __name__ == "__main__":
# 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", action="store_true", 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 = ChatLiteLLM(temperature=0.2, model_name="gpt-3.5-turbo")
if config_path == "":
print("No agent config specified, using a standard config")
# keep boolean as string to be consistent with JSON configs.
USE_TOOLS = True
sales_agent_kwargs = {
"verbose": verbose,
"use_tools": USE_TOOLS,
}
if USE_TOOLS:
sales_agent_kwargs.update(
{
"product_catalog": "examples/sample_product_catalog.txt",
"salesperson_name": "Ted Lasso",
}
)
sales_agent = SalesGPT.from_llm(llm, **sales_agent_kwargs)
else:
try:
with open(config_path, "r", encoding="UTF-8") as f:
config = json.load(f)
except FileNotFoundError:
print(f"Config file {config_path} not found.")
exit(1)
except json.JSONDecodeError:
print(f"Error decoding JSON from the config file {config_path}.")
exit(1)
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)