forked from filip-michalsky/SalesGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
61 lines (48 loc) · 1.97 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
import argparse
import os
import json
from salesgpt.agents import SalesGPT
from langchain.chat_models import ChatOpenAI
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.9, stop = "<END_OF_TURN>")
if config_path=='':
print('No agent config specified, using a standard config')
sales_agent = SalesGPT.from_llm(llm, verbose=verbose)
else:
with open(config_path,'r') 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)