Spaces:
Sleeping
Sleeping
Shivappa commited on
Commit Β·
caa07e1
1
Parent(s): 6026955
fix: remove silent except in get_model_action + fix port default
Browse files- Remove try/except in get_model_action() β LLM errors now propagate
loudly so the validator log shows the real failure reason
- Fix ENV_BASE_URL default: 7860 (matches Dockerfile PORT) not 8000
- No dotenv, no fallback model, no silent swallowing of API errors
- inference.py +20 -31
inference.py
CHANGED
|
@@ -32,7 +32,7 @@ from email_triage_rl_hackathon import EmailTriageEnv, TriageAction
|
|
| 32 |
# so they are resolved AFTER the validator sets them β never use a module-level default
|
| 33 |
# that could silently bypass the proxy.
|
| 34 |
MODEL_NAME = os.environ.get("MODEL_NAME", "gpt-4o-mini")
|
| 35 |
-
ENV_BASE_URL = os.environ.get("ENV_BASE_URL", "http://localhost:
|
| 36 |
LOCAL_IMAGE_NAME = os.environ.get("LOCAL_IMAGE_NAME", "")
|
| 37 |
TASK_LEVEL = os.environ.get("TASK_LEVEL", "easy") # easy | medium | hard
|
| 38 |
BENCHMARK = "email_triage_rl_hackathon"
|
|
@@ -113,38 +113,27 @@ def build_user_prompt(obs, step: int, history: List[str]) -> str:
|
|
| 113 |
def get_model_action(client: OpenAI, obs, step: int, history: List[str]) -> TriageAction:
|
| 114 |
"""Call the LLM and parse the JSON response into a TriageAction."""
|
| 115 |
user_prompt = build_user_prompt(obs, step, history)
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
content = (completion.choices[0].message.content or "").strip()
|
| 128 |
-
|
| 129 |
-
# Strip markdown code fences if present
|
| 130 |
-
if content.startswith("```"):
|
| 131 |
-
content = content.split("```")[1]
|
| 132 |
-
if content.startswith("json"):
|
| 133 |
-
content = content[4:]
|
| 134 |
-
content = content.strip()
|
| 135 |
|
| 136 |
-
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
# Safe fallback action β note: this means NO API call was made for this step
|
| 142 |
-
return TriageAction(
|
| 143 |
-
category="general",
|
| 144 |
-
priority="low",
|
| 145 |
-
department="support",
|
| 146 |
-
reply="",
|
| 147 |
-
)
|
| 148 |
|
| 149 |
|
| 150 |
# ββ Main episode loop βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 32 |
# so they are resolved AFTER the validator sets them β never use a module-level default
|
| 33 |
# that could silently bypass the proxy.
|
| 34 |
MODEL_NAME = os.environ.get("MODEL_NAME", "gpt-4o-mini")
|
| 35 |
+
ENV_BASE_URL = os.environ.get("ENV_BASE_URL", "http://localhost:7860")
|
| 36 |
LOCAL_IMAGE_NAME = os.environ.get("LOCAL_IMAGE_NAME", "")
|
| 37 |
TASK_LEVEL = os.environ.get("TASK_LEVEL", "easy") # easy | medium | hard
|
| 38 |
BENCHMARK = "email_triage_rl_hackathon"
|
|
|
|
| 113 |
def get_model_action(client: OpenAI, obs, step: int, history: List[str]) -> TriageAction:
|
| 114 |
"""Call the LLM and parse the JSON response into a TriageAction."""
|
| 115 |
user_prompt = build_user_prompt(obs, step, history)
|
| 116 |
+
completion = client.chat.completions.create(
|
| 117 |
+
model=MODEL_NAME,
|
| 118 |
+
messages=[
|
| 119 |
+
{"role": "system", "content": SYSTEM_PROMPT},
|
| 120 |
+
{"role": "user", "content": user_prompt},
|
| 121 |
+
],
|
| 122 |
+
temperature=TEMPERATURE,
|
| 123 |
+
max_tokens=MAX_TOKENS,
|
| 124 |
+
stream=False,
|
| 125 |
+
)
|
| 126 |
+
content = (completion.choices[0].message.content or "").strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
+
# Strip markdown code fences if present
|
| 129 |
+
if content.startswith("```"):
|
| 130 |
+
content = content.split("```")[1]
|
| 131 |
+
if content.startswith("json"):
|
| 132 |
+
content = content[4:]
|
| 133 |
+
content = content.strip()
|
| 134 |
|
| 135 |
+
data = json.loads(content)
|
| 136 |
+
return TriageAction(**data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
|
| 138 |
|
| 139 |
# ββ Main episode loop βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|