Spaces:
Runtime error
Runtime error
fix phase2 timeout
Browse files- inference.py +12 -6
inference.py
CHANGED
|
@@ -23,13 +23,19 @@ MODEL_NAME = os.getenv("MODEL_NAME", "Qwen/Qwen2.5-7B-Instruct")
|
|
| 23 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 24 |
|
| 25 |
try:
|
|
|
|
| 26 |
client = OpenAI(
|
| 27 |
base_url=API_BASE_URL,
|
| 28 |
api_key=HF_TOKEN
|
| 29 |
)
|
| 30 |
|
| 31 |
env = DeceptionEnv()
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
print(
|
| 35 |
"[START] task=ai-deception env=cyber-security model=AI-agent",
|
|
@@ -39,6 +45,7 @@ try:
|
|
| 39 |
rewards = []
|
| 40 |
history = []
|
| 41 |
|
|
|
|
| 42 |
for step in range(1, 4):
|
| 43 |
|
| 44 |
try:
|
|
@@ -46,10 +53,11 @@ try:
|
|
| 46 |
except Exception:
|
| 47 |
pass
|
| 48 |
|
|
|
|
| 49 |
try:
|
| 50 |
state = env.state()
|
| 51 |
except Exception:
|
| 52 |
-
|
| 53 |
|
| 54 |
summary = {
|
| 55 |
"failed_logins": state.get("failed_logins", 0),
|
|
@@ -78,12 +86,13 @@ block_ip
|
|
| 78 |
messages=[{"role": "user", "content": prompt}],
|
| 79 |
temperature=0.2,
|
| 80 |
max_tokens=20,
|
| 81 |
-
timeout=
|
| 82 |
)
|
| 83 |
|
| 84 |
action = response.choices[0].message.content.strip()
|
| 85 |
|
| 86 |
except Exception:
|
|
|
|
| 87 |
if not history:
|
| 88 |
action = "detect_attack"
|
| 89 |
elif history[-1] == "detect_attack":
|
|
@@ -107,9 +116,6 @@ block_ip
|
|
| 107 |
flush=True
|
| 108 |
)
|
| 109 |
|
| 110 |
-
if done:
|
| 111 |
-
break
|
| 112 |
-
|
| 113 |
score = min(sum(rewards), 1.0)
|
| 114 |
|
| 115 |
print(
|
|
|
|
| 23 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 24 |
|
| 25 |
try:
|
| 26 |
+
|
| 27 |
client = OpenAI(
|
| 28 |
base_url=API_BASE_URL,
|
| 29 |
api_key=HF_TOKEN
|
| 30 |
)
|
| 31 |
|
| 32 |
env = DeceptionEnv()
|
| 33 |
+
|
| 34 |
+
# reset API must work
|
| 35 |
+
try:
|
| 36 |
+
state = env.reset()
|
| 37 |
+
except Exception:
|
| 38 |
+
state = {}
|
| 39 |
|
| 40 |
print(
|
| 41 |
"[START] task=ai-deception env=cyber-security model=AI-agent",
|
|
|
|
| 45 |
rewards = []
|
| 46 |
history = []
|
| 47 |
|
| 48 |
+
# EXACTLY 3 STEPS
|
| 49 |
for step in range(1, 4):
|
| 50 |
|
| 51 |
try:
|
|
|
|
| 53 |
except Exception:
|
| 54 |
pass
|
| 55 |
|
| 56 |
+
# state API must work
|
| 57 |
try:
|
| 58 |
state = env.state()
|
| 59 |
except Exception:
|
| 60 |
+
pass
|
| 61 |
|
| 62 |
summary = {
|
| 63 |
"failed_logins": state.get("failed_logins", 0),
|
|
|
|
| 86 |
messages=[{"role": "user", "content": prompt}],
|
| 87 |
temperature=0.2,
|
| 88 |
max_tokens=20,
|
| 89 |
+
timeout=15
|
| 90 |
)
|
| 91 |
|
| 92 |
action = response.choices[0].message.content.strip()
|
| 93 |
|
| 94 |
except Exception:
|
| 95 |
+
# fallback logic
|
| 96 |
if not history:
|
| 97 |
action = "detect_attack"
|
| 98 |
elif history[-1] == "detect_attack":
|
|
|
|
| 116 |
flush=True
|
| 117 |
)
|
| 118 |
|
|
|
|
|
|
|
|
|
|
| 119 |
score = min(sum(rewards), 1.0)
|
| 120 |
|
| 121 |
print(
|