-
Notifications
You must be signed in to change notification settings - Fork 4
/
y_client.py
122 lines (104 loc) · 3.41 KB
/
y_client.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import os, sys, json, shutil
if __name__ == "__main__":
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.dirname(SCRIPT_DIR))
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument(
"-c",
"--config_file",
default="config_files/config.json",
help="JSON file describing the simulation configuration",
)
parser.add_argument(
"-f",
"--feeds",
default="config_files/feed_small.json",
help="JSON file containing rss feed categorized",
)
parser.add_argument(
"-p",
"--prompts",
default="config_files/prompts.json",
help="JSON file containing LLM prompts",
)
parser.add_argument(
"-a", "--agents", default=None, help="JSON file with pre-existing agents"
)
parser.add_argument(
"-o", "--owner", default="admin", help="Simulation owner username"
)
parser.add_argument(
"-r",
"--reset",
default=False,
help="Boolean. Whether to reset the experiment status. Default False",
)
parser.add_argument(
"-n",
"--news",
default=False,
help="Boolean. Whether to reload the rss feeds. Default False",
)
parser.add_argument(
"-x",
"--crecsys",
default="ReverseChronoFollowersPopularity",
help="Name of the content recsys to be used. Options: ...",
)
parser.add_argument(
"-y",
"--frecsys",
default="PreferentialAttachment",
help="Name of the follower recsys to be used. Options: ...",
)
parser.add_argument(
"-g",
"--graph",
default=None,
help="Name of the graph file (CSV format, number of nodes equal to the starting agents) "
"to be used for the simulation",
)
args = parser.parse_args()
agents_owner = args.owner
config_file = args.config_file
agents_file = args.agents
rss_feeds = args.feeds
prompts_file = args.prompts
graph_file = args.graph
# get simulation client and name
config = json.load(open(config_file, "r"))
client_name = config["simulation"]["client"]
simulation_name = config["simulation"]["name"]
# agent file output
output = f"experiments/{simulation_name}_agents.json"
# set the current config file (needed to generate the database)
shutil.copyfile(config_file, f"experiments/current_config.json")
import y_client.recsys
import y_client.clients
if not os.path.exists("./experiments"):
os.mkdir("./experiments")
# get recommender systems
content_recsys = getattr(y_client.recsys, args.crecsys)()
follow_recsys = getattr(y_client.recsys, args.frecsys)(leaning_bias=1.5)
# get and instantiate the client
experiment = getattr(y_client.clients, client_name)(
config_file,
prompts_file,
agents_filename=agents_file,
owner=agents_owner,
agents_output=output,
graph_file=graph_file,
)
if args.reset:
experiment.reset_experiment()
if args.news:
experiment.reset_news_db()
experiment.load_rrs_endpoints(rss_feeds)
experiment.set_recsys(content_recsys, follow_recsys)
if args.agents is None:
experiment.create_initial_population()
else:
experiment.load_existing_agents(args.agents)
experiment.save_agents()
experiment.run_simulation()