Skip to content

Commit e8c4e3c

Browse files
Merge pull request #207 from callanwu/master
refactor: update relative file paths
2 parents c7ed3da + f6fd0b6 commit e8c4e3c

26 files changed

+139
-183
lines changed

examples/creative_writing/configs/SOP.json

+32-28
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22
"nodes": {
33
"node_write": {
44
"node_name": "node_write",
5+
"node_description": "Compose a coherent and fluent passage based on provided questions. Ensure each paragraph ends with a specific concluding sentence to maintain narrative consistency and emphasize key points.",
6+
"node_roles_description": {
7+
"role_write": "Compose a fluent and coherent passage based on the given questions. Ensure that each paragraph concludes with the specified sentence to reinforce key ideas and provide a smooth narrative flow."
8+
},
9+
"begin_role": "role_write",
10+
"begin_query": null,
511
"controller": {
6-
"route_type": "order",
7-
"transit_type": "order",
812
"max_chat_nums": 20,
13+
"transit_type": "order",
914
"transit_system_prompt": "",
1015
"transit_last_prompt": "",
1116
"transit_extract_word": "end",
17+
"route_type": "order",
1218
"route_system_prompt": "",
1319
"route_last_prompt": "",
1420
"route_extract_word": "end"
1521
},
16-
"begin_role": "role_write",
17-
"node_description": "Write a fluent passage based on the questions given, in which the closing part of each paragraph ends with the sentence given",
18-
"tools": "",
19-
"node_roles_description": {
20-
"role_write": "Write a fluent passage based on the questions given, in which the closing part of each paragraph ends with the sentence given"
21-
},
2222
"node_prompt_templates": {
23-
"step_write": "A creative writing task where the input is 4 random sentences and the output should be a coherent passage with 4 paragraphs that end in the 4 input sentences respectively. Such a task is open-ended and exploratory, and challenges creative thinking as well as high-level planning. Here is the four sentences: 1. The sun was shining brightly. 2. The birds were chirping. 3. The flowers were blooming. 4. The children were playing in the park. Please write a passage that ends with each of the four sentences: {text}"
23+
"step_write": "Compose a creative passage of four paragraphs, adhering to the following guidelines: \n1. Each paragraph should conclude with one of these sentences in the given order \n2. The narrative should be coherent, logically consistent, and maintain a consistent tone and setting throughout. \n3. Avoid introducing characters or elements without context. \n4. Ensure smooth transitions between paragraphs. \nUse these sentences respectively to conclude each of the four paragraphs: {text}."
2424
},
2525
"node_prompt_paddings": {
2626
"role_write": {
@@ -29,50 +29,54 @@
2929
"value": "input_data"
3030
}
3131
}
32-
}
32+
},
33+
"kb": null
3334
},
34-
"node_check": {
35-
"node_name": "node_check",
35+
"node_edit": {
36+
"node_name": "node_edit",
37+
"node_description": "Review the passage written by 'role_write'. The node should correct errors, improve logical flow, and enhance readability.",
38+
"node_roles_description": {
39+
"role_edit": "The role of 'role_edit' is to review the passage written by 'role_write', correcting grammatical errors, improving logical flow, and enhancing readability. The final result should be free of major errors and optimized for fluency."
40+
},
41+
"begin_role": "role_edit",
42+
"begin_query": null,
3643
"controller": {
37-
"route_type": "order",
38-
"transit_type": "order",
3944
"max_chat_nums": 20,
45+
"transit_type": "order",
4046
"transit_system_prompt": "",
4147
"transit_last_prompt": "",
4248
"transit_extract_word": "end",
49+
"route_type": "order",
4350
"route_system_prompt": "",
4451
"route_last_prompt": "",
4552
"route_extract_word": "end"
4653
},
47-
"begin_role": "role_check",
48-
"node_description": "Check that the written text is correct and fluent, and modify the text appropriately to make it fluent",
49-
"tools": "",
50-
"node_roles_description": {
51-
"role_check": "Check the text written by the previous person, analyze it, and optimize it to make it more fluent"
52-
},
5354
"node_prompt_templates": {
54-
"step_check": "Check the text written by the previous person, analyze it, and optimize it to make it more fluent. Please enclose the optimized text in <result>[put the optimized text here]</result>."
55+
"step_role_edit": "Review and refine the passage written by 'role_write' for coherence, grammar, and style. Ensure the final passage flows smoothly and meets the required standards. Specifically, the last sentence of the paragraph should sequentially come from the following sentences: {text}. Please use <result>[the passage you refined]</result> to wrap the result."
5556
},
5657
"node_prompt_paddings": {
57-
"role_check": {
58-
"step_check": {
58+
"role_edit": {
59+
"step_role_edit": {
5960
"value_source": "case",
6061
"value": "input_data"
6162
}
6263
}
63-
}
64+
},
65+
"kb": null
6466
}
67+
6568
},
6669
"edges": {
6770
"node_write": [
6871
"node_write",
69-
"node_check"
72+
"node_edit"
7073
],
71-
"node_check": [
72-
"node_check",
74+
"node_edit": [
75+
"node_edit",
7376
"end_node"
7477
]
7578
},
7679
"root": "node_write",
77-
"end": "end_node"
80+
"end": "end_node",
81+
"global_kb": null
7882
}
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,53 @@
11
{
22
"agents": {
3-
"agent_write": {
4-
"agent_name": "agent_write",
3+
"Alice": {
4+
"agent_name": "Alice",
55
"agent_roles": {
66
"node_write": "role_write"
77
},
8+
"agent_style": null,
9+
"agent_description": null,
810
"LLM_config": {
911
"LLM_type": "OpenAI",
10-
"OPENAI_API_KEY": "",
11-
"OPENAI_BASE_URL": "",
12+
"model": "gpt-3.5-turbo-0125",
1213
"temperature": 0.3,
13-
"model": "gpt-4-turbo-2024-04-09",
14-
"SAVE_LOGS": false,
15-
"log_path": "logs/creative_writing/AgentWrite"
14+
"log_path": "logs/Alice",
15+
"API_KEY": "",
16+
"API_BASE": "",
17+
"MAX_CHAT_MESSAGES": 10,
18+
"ACTIVE_MODE": false,
19+
"SAVE_LOGS": false
1620
},
17-
"toolkit": {},
18-
"memory": {
19-
"short_term_memory": {},
20-
"long_term_memory": {}
21-
}
21+
"toolkit": null,
22+
"memory": null,
23+
"is_user": false
2224
},
23-
"agent_check": {
24-
"agent_name": "agent_check",
25+
"Bob": {
26+
"agent_name": "Bob",
2527
"agent_roles": {
26-
"node_check": "role_check"
28+
"node_edit": "role_edit"
2729
},
30+
"agent_style": null,
31+
"agent_description": null,
2832
"LLM_config": {
2933
"LLM_type": "OpenAI",
30-
"OPENAI_API_KEY": "",
31-
"OPENAI_BASE_URL": "",
34+
"model": "gpt-3.5-turbo-0125",
3235
"temperature": 0.3,
33-
"model": "gpt-4-turbo-2024-04-09",
34-
"SAVE_LOGS": false,
35-
"log_path": "logs/creative_writing/AgentCheck"
36+
"log_path": "logs/Bob",
37+
"API_KEY": "",
38+
"API_BASE": "",
39+
"MAX_CHAT_MESSAGES": 10,
40+
"ACTIVE_MODE": false,
41+
"SAVE_LOGS": false
3642
},
37-
"toolkit": {},
38-
"memory": {
39-
"short_term_memory": {},
40-
"long_term_memory": {}
41-
}
43+
"toolkit": null,
44+
"memory": null,
45+
"is_user": false
4246
}
4347
},
4448
"environment": {
45-
"shared_memory": {
46-
"short_term_memory": {},
47-
"long_term_memory": {}
48-
},
49-
"shared_toolkit": {},
50-
"environment_type": "cooperative"
49+
"environment_type": "cooperative",
50+
"shared_memory": null,
51+
"shared_toolkit": null
5152
}
5253
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"task": "examples/cteative_writing/configs/task.json",
3-
"agent_team": "examples/cteative_writing/configs/agent_team.json",
4-
"sop": "examples/cteative_writing/configs/SOP.json"
2+
"task": "configs/task.json",
3+
"agent_team": "configs/agent_team.json",
4+
"sop": "configs/SOP.json"
55
}

examples/creative_writing/configs/task.json

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"task_id": "CreativeWriting",
32
"task_name": "CreativeWriting",
43
"task_type": "",
54
"task_description": "A creative writing task where the input is 4 random sentences and the output should be a coherent passage with 4 paragraphs that end in the 4 input sentences respectively. Such a task is open-ended and exploratory, and challenges creative thinking as well as high-level planning."

examples/creative_writing/configs/trainer_config.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"batch_size": 4,
33
"max_step": 4,
4-
"log_path": "examples/creative_writing/new_logs",
4+
"log_path": "new_logs",
55

66
"sample_kind": "random",
77
"allow_duplicate_samples": false,
@@ -19,8 +19,8 @@
1919
"parallel": true,
2020
"parallel_max_num": 8,
2121

22-
"initial_solution_path": "examples/creative_writing/configs/solution.json",
23-
"optimizer_config_path": "examples/creative_writing/configs/optimizer_config.json",
22+
"initial_solution_path": "configs/solution.json",
23+
"optimizer_config_path": "configs/optimizer_config.json",
2424
"optim_order": "order",
2525
"optimizers": [
2626
"prompt", "node"

examples/creative_writing/run_eval.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@
1414
os.environ["OPENAI_BASE_URL"] = ""
1515

1616
time_path = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
17-
save_path = f"examples/ceative_writing/eval/{time_path}_creative_writing"
17+
save_path = f"eval/{time_path}_creative_writing"
1818

1919

20-
def get_score():
20+
def get_score(dir_list):
2121
"""
2222
case跑完了之后加载保存下来的case获取分数
2323
Returns:
2424
2525
"""
26-
save_result_path = "examples/creative_writing/eval/final_result.json"
27-
dir_list = ["examples/creative_writing/eval/2024-05-23_00-19-18_creative_writing_GPT35"]
26+
save_result_path = "eval/final_result.json"
2827

2928
scores = []
3029
count = 0
3130
for dir in dir_list:
3231
print(f"\n\nthe dir is: {dir}")
3332
files_and_folders = os.listdir(dir)
34-
files = [f for f in files_and_folders if os.path.isfile(os.path.join(dir, f))]
33+
files = [f for f in files_and_folders if os.path.isfile(
34+
os.path.join(dir, f))]
3535
for file_name in files:
3636
if file_name == "result.json":
3737
continue
@@ -57,7 +57,7 @@ def run_eval():
5757
dataset = CreativeWritingDataset(split="all")
5858

5959
# 跑实验用的就是examples\creative_writing\logs\2024-05-22_13-47-02\step_5\solution.json
60-
solution_config_path = r"examples\creative_writing\logs\2024-05-22_13-47-02\step_5\solution.json"
60+
solution_config_path = "configs/solution.json"
6161

6262
solution = Solution(SolutionConfig(solution_config_path))
6363
case_list = []
@@ -69,7 +69,8 @@ def run_eval():
6969
# for i in used_idx:
7070
# case_list.append(Case(dataset.get_case_dict(i)))
7171

72-
OptimUtils.parallel_case_forward(case_list, solution, 8, save_path, dataset.evaluate)
72+
OptimUtils.parallel_case_forward(
73+
case_list, solution, 8, save_path, dataset.evaluate)
7374

7475
scores = []
7576
for case in case_list:

examples/creative_writing/run_train.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
dataset = CreativeWritingDataset(split="train")
1515

1616
# Trainer训练
17-
trainer_config_path = "examples/creative_writing/configs/trainer_config.json"
18-
trainer = Trainer(config=TrainerConfig(trainer_config_path), dataset=dataset)
17+
trainer_config_path = "/configs/trainer_config.json"
18+
trainer = Trainer(config=TrainerConfig(
19+
trainer_config_path), dataset=dataset)
1920
trainer.train()
20-
21-

examples/debate/run.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
os.environ["OPENAI_BASE_URL"] = ""
88

99
if __name__ == "__main__":
10-
solution = Solution(config=SolutionConfig("examples/debate/generated_config.json"))
10+
solution = Solution(config=SolutionConfig("generated_config.json"))
1111
solution.run()

examples/hotpotqa/configs/optimizer_config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"has_result": true,
55
"sample_kind": "order"
66
},
7-
"log_path": "examples/hotpotqa/logs",
7+
"log_path": "logs",
88
"loss": {
99
"llm_config": {
1010
"LLM_type": "OpenAI",
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"task": "examples/hotpotqa/configs/task.json",
3-
"agent_team": "examples/hotpotqa/configs/agent_team.json",
4-
"sop": "examples/hotpotqa/configs/SOP.json"
2+
"task": "configs/task.json",
3+
"agent_team": "configs/agent_team.json",
4+
"sop": "configs/SOP.json"
55
}

examples/hotpotqa/configs/trainer_config.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"batch_size": 2,
33
"max_step": 10,
4-
"log_path": "examples/hotpotqa/logs",
4+
"log_path": "logs",
55

66
"sample_kind": "random",
77
"allow_duplicate_samples": false,
@@ -19,8 +19,8 @@
1919
"parallel": true,
2020
"parallel_max_num": 8,
2121

22-
"initial_solution_path": "examples/hotpotqa/eval/accepted_solution/solution.json",
23-
"optimizer_config_path": "examples/hotpotqa/configs/optimizer_config.json",
22+
"initial_solution_path": "eval/accepted_solution/solution.json",
23+
"optimizer_config_path": "configs/optimizer_config.json",
2424
"optim_order": "order",
2525
"optimizers": [
2626
"sop"
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"task": "examples/hotpotqa/eval/accepted_solution/task.json",
3-
"agent_team": "examples/hotpotqa/eval/accepted_solution/agent_team.json",
4-
"sop": "examples/hotpotqa/eval/accepted_solution/sop.json"
2+
"task": "eval/accepted_solution/task.json",
3+
"agent_team": "eval/accepted_solution/agent_team.json",
4+
"sop": "eval/accepted_solution/sop.json"
55
}

examples/hotpotqa/run_eval.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@
1515

1616
split = "hard"
1717
time_path = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
18-
save_path = f"examples/hotpotqa/eval/{time_path}_hotpotqa_{split}"
18+
save_path = f"eval/{time_path}_hotpotqa_{split}"
1919

2020

2121
def run_eval():
2222
# !需要根据情况配置split
2323
dataset = HotpotQADataset(split)
2424

2525
# !需要根据情况配置
26-
solution_config_path = r"examples/hotpotqa/eval/accepted_solution/solution.json"
27-
solution_config_path = r"examples/hotpotqa/logs/2024-05-22_16-55-55/step_9/solution.json"
26+
solution_config_path = "eval/accepted_solution/solution.json"
2827
solution = Solution(SolutionConfig(solution_config_path))
2928

3029
case_list = []
3130
for i in range(len(dataset)):
3231
case_list.append(Case(dataset.get_case_dict(i)))
3332

34-
OptimUtils.parallel_case_forward(case_list, solution, 8, save_path, dataset.evaluate)
33+
OptimUtils.parallel_case_forward(
34+
case_list, solution, 8, save_path, dataset.evaluate)
3535

3636
ems = []
3737
f1s = []
@@ -49,9 +49,9 @@ def run_eval():
4949
json.dump(result, f, ensure_ascii=False, indent=4)
5050

5151
for case in case_list:
52-
print(f"case_id: {case.case_id}, f1: {case.dataset_eval.standard_eval_result['f1']}, ground_truth: {case.ground_truth}, prediction: {case.result}")
52+
print(f"case_id: {case.case_id}, f1: {case.dataset_eval.standard_eval_result['f1']}, ground_truth: {
53+
case.ground_truth}, prediction: {case.result}")
5354

5455

5556
if __name__ == "__main__":
5657
run_eval()
57-

examples/hotpotqa/run_train.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
dataset = HotpotQADataset(split=split)
1616

1717
# Trainer训练
18-
trainer_config_path = "examples/hotpotqa/configs/trainer_config.json"
19-
trainer = Trainer(config=TrainerConfig(trainer_config_path), dataset=dataset)
18+
trainer_config_path = "configs/trainer_config.json"
19+
trainer = Trainer(config=TrainerConfig(
20+
trainer_config_path), dataset=dataset)
2021
trainer.train()

0 commit comments

Comments
 (0)