-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.py
50 lines (40 loc) · 1.82 KB
/
main.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
import llm_ctf.mixtral_task as mixtral
import sys
import os
import json
from pathlib import Path
EXPERIMENT_REPEAT = 10
DEFAULT_PATH = Path(__file__).parent.resolve()
def main(question_path, prompt_path, chal_config):
os.chdir(DEFAULT_PATH)
mixtral_task = mixtral.MixtralTask(question_path=question_path,
task_config=chal_config,
url_path=os.path.abspath("./keys/mixtral_api.txt"))
resp = mixtral_task.task_prompt(prompt=prompt_path, use_file=False, append_msg="", template_prompt=True)
# print("============================== RESPONSE FROM MODEL ==============================")
# print(resp)
mixtral_task.save_code(resp)
solved = mixtral_task.validate_sol(resp)
return solved
if __name__ == "__main__":
# p = subprocess.run("sudo docker run --rm -it -v $PWD:/opt/exp ctfenv /bin/bash -c \'cd /opt/exp/solutions/rev/\"Rebug 1\"&&python sol.py\'", stdout=subprocess.PIPE, stderr=subprocess.STDOUT, timeout=5, shell=True)
# print(str('\n' + p.stdout.decode("utf-8")))
# if len(sys.argv) != 3:
# print("Usage: python script.py <question_path> <prompt_path>")
# sys.exit(1)
question_path = str(sys.argv[1])
prompt_path = str(sys.argv[2]) if len(sys.argv) > 2 else ""
with open(os.path.join(question_path, "challenge.json"), 'r') as f:
chal_json = json.load(f)
success = 0
chal_name = chal_json["name"]
for i in range(EXPERIMENT_REPEAT):
try:
if main(question_path, prompt_path, chal_json):
success += 1
except Exception as e:
print(e)
with open("results.txt", "a+") as f:
res = f"Challenge: {chal_name}, Success: {success}/{EXPERIMENT_REPEAT}\n"
f.write(res)
print(res)