-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting.py
More file actions
79 lines (55 loc) · 2.01 KB
/
Copy pathtesting.py
File metadata and controls
79 lines (55 loc) · 2.01 KB
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
# Copyright (c) 2019-2020, INESC TEC (https://www.inesctec.pt)
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import json
from llm_utils import call_llm
# --------------------------
# LOAD PROMPT
# --------------------------
def load_prompt(path):
with open(path, "r", encoding="utf-8") as f:
return f.read()
# --------------------------
# ACTOR (INFERENCE)
# --------------------------
def run_actor(actor_prompt, snapshot):
prompt = f"""
{actor_prompt}
### OPF Snapshot
{json.dumps(snapshot, indent=2)}
### Explanation
"""
return call_llm(prompt, role="Actor", temperature=0.2)
# --------------------------
# TEST PIPELINE
# --------------------------
def run_test(
actor_prompt_path,
output_path,
test_dataset_path="test_snapshots_case39_cf2.json",
):
print("Loading actor prompt...")
actor_prompt = load_prompt(actor_prompt_path)
print("Loading test dataset...")
with open(test_dataset_path, "r", encoding="utf-8") as f:
data = json.load(f)
explanations = {}
for snapshot_id, item in data.items():
snapshot = item["opf_summary"]
print("\n=========================")
print(f"Snapshot {snapshot_id}")
print("=========================")
explanation = run_actor(actor_prompt, snapshot)
print("\nActor Explanation:\n", explanation)
explanations[snapshot_id] = explanation
# Save explanations
with open(output_path, "w", encoding="utf-8") as f:
json.dump(explanations, f, indent=2, ensure_ascii=False)
print(f"\n✅ Explanations saved to: {output_path}")
# --------------------------
# RUN
# --------------------------
if __name__ == "__main__":
design=1
run_test(f"actor_prompt_base.txt", f"test_actor_explanations_base.json") #"actor_prompt_{design}.txt"