spidey121 commited on
Commit
4985974
·
1 Parent(s): 237a97a

fix round 1

Browse files
Files changed (1) hide show
  1. inference.py +7 -26
inference.py CHANGED
@@ -1,4 +1,3 @@
1
- import threading
2
  import time
3
  import os
4
  import random
@@ -7,14 +6,9 @@ from openai import OpenAI
7
 
8
  random.seed(42)
9
 
10
- from server.app import main as run_server
11
  from env.env import DeceptionEnv
12
  from env.attacker import simulate_attack
13
 
14
- # Start server in background
15
- threading.Thread(target=run_server, daemon=True).start()
16
- time.sleep(2)
17
-
18
  API_BASE_URL = os.getenv("API_BASE_URL", "https://router.huggingface.co/v1")
19
  MODEL_NAME = os.getenv("MODEL_NAME", "Qwen/Qwen2.5-7B-Instruct")
20
  HF_TOKEN = os.getenv("HF_TOKEN")
@@ -33,7 +27,7 @@ def run_task(task_name):
33
  env.reset()
34
 
35
  print(
36
- f"[START] task={task_name} env=cyber-security model={MODEL_NAME}",
37
  flush=True
38
  )
39
 
@@ -52,7 +46,7 @@ def run_task(task_name):
52
  except Exception:
53
  pass
54
 
55
- # Required OpenAI call (validator requirement)
56
  try:
57
  client.chat.completions.create(
58
  model=MODEL_NAME,
@@ -62,22 +56,12 @@ def run_task(task_name):
62
  except Exception:
63
  pass
64
 
65
- # Task-specific logic
66
  if task_name == "easy":
67
- if step == 1:
68
- action = "detect_attack"
69
- elif step == 2:
70
- action = "detect_attack"
71
- else:
72
- action = "deploy_honeypot"
73
 
74
  elif task_name == "medium":
75
- if step == 1:
76
- action = "detect_attack"
77
- elif step == 2:
78
- action = "deploy_honeypot"
79
- else:
80
- action = "deploy_honeypot"
81
 
82
  else: # hard
83
  if step == 1:
@@ -89,9 +73,7 @@ def run_task(task_name):
89
 
90
  state, reward, done, _ = env.step(action)
91
 
92
- # clamp reward to (0,1)
93
  reward = min(max(reward, 0.05), 0.95)
94
-
95
  rewards.append(reward)
96
 
97
  print(
@@ -111,7 +93,7 @@ def run_task(task_name):
111
 
112
  print(
113
  f"[END] success={str(success).lower()} steps={steps} "
114
- f"score={score:.3f} rewards={','.join(f'{r:.2f}' for r in rewards)}",
115
  flush=True
116
  )
117
 
@@ -123,10 +105,9 @@ def run_task(task_name):
123
  )
124
 
125
 
126
- # Run tasks
127
  run_task("easy")
128
  run_task("medium")
129
  run_task("hard")
130
 
131
- # Keep space alive briefly for validation (3 min)
132
  time.sleep(180)
 
 
1
  import time
2
  import os
3
  import random
 
6
 
7
  random.seed(42)
8
 
 
9
  from env.env import DeceptionEnv
10
  from env.attacker import simulate_attack
11
 
 
 
 
 
12
  API_BASE_URL = os.getenv("API_BASE_URL", "https://router.huggingface.co/v1")
13
  MODEL_NAME = os.getenv("MODEL_NAME", "Qwen/Qwen2.5-7B-Instruct")
14
  HF_TOKEN = os.getenv("HF_TOKEN")
 
27
  env.reset()
28
 
29
  print(
30
+ f"[START] task={task_name} env=ai-deception-openenv model={MODEL_NAME}",
31
  flush=True
32
  )
33
 
 
46
  except Exception:
47
  pass
48
 
49
+ # Required OpenAI call
50
  try:
51
  client.chat.completions.create(
52
  model=MODEL_NAME,
 
56
  except Exception:
57
  pass
58
 
59
+ # Task logic
60
  if task_name == "easy":
61
+ action = "detect_attack" if step < 3 else "deploy_honeypot"
 
 
 
 
 
62
 
63
  elif task_name == "medium":
64
+ action = "detect_attack" if step == 1 else "deploy_honeypot"
 
 
 
 
 
65
 
66
  else: # hard
67
  if step == 1:
 
73
 
74
  state, reward, done, _ = env.step(action)
75
 
 
76
  reward = min(max(reward, 0.05), 0.95)
 
77
  rewards.append(reward)
78
 
79
  print(
 
93
 
94
  print(
95
  f"[END] success={str(success).lower()} steps={steps} "
96
+ f"score={score:.2f} rewards={','.join(f'{r:.2f}' for r in rewards)}",
97
  flush=True
98
  )
99
 
 
105
  )
106
 
107
 
 
108
  run_task("easy")
109
  run_task("medium")
110
  run_task("hard")
111
 
112
+ # Keep alive briefly
113
  time.sleep(180)