Spaces:
Sleeping
Sleeping
Compliance: Fixed 5 functional bugs in inference.py (params, task_id, obs keys)
Browse files- inference.py +13 -11
inference.py
CHANGED
|
@@ -20,8 +20,8 @@ API_BASE_URL = os.environ.get("API_BASE_URL")
|
|
| 20 |
MODEL_NAME = os.environ.get("MODEL_NAME", "meta-llama/Llama-3.1-8B-Instruct")
|
| 21 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 22 |
|
| 23 |
-
TASKS = ["short_term_direction", "medium_term_direction", "
|
| 24 |
-
ENV_TERMS = {"short_term_direction": "short", "medium_term_direction": "medium", "
|
| 25 |
|
| 26 |
|
| 27 |
def _parse_direction_and_conviction(text: str):
|
|
@@ -60,16 +60,17 @@ def run_evaluation(env_url, n_episodes):
|
|
| 60 |
|
| 61 |
for i in range(n_episodes):
|
| 62 |
try:
|
| 63 |
-
# 1. Reset Environment
|
| 64 |
-
reset_resp = requests.post(f"{env_url}/reset",
|
| 65 |
if reset_resp.status_code != 200:
|
| 66 |
continue
|
| 67 |
|
| 68 |
data = reset_resp.json()
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
|
|
|
| 73 |
|
| 74 |
# 2. Build Prompt
|
| 75 |
system_prompt = "You are a quantitative analyst. Given technical indicators, predict the directional price move as Bullish, Bearish, or Neutral. Provide reasoning then output a JSON with 'reasoning', 'direction', and 'conviction' (0.0-1.0)."
|
|
@@ -88,10 +89,11 @@ def run_evaluation(env_url, n_episodes):
|
|
| 88 |
response = chat_completion.choices[0].message.content
|
| 89 |
direction, conviction = _parse_direction_and_conviction(response)
|
| 90 |
|
| 91 |
-
# 4. Step Environment
|
| 92 |
step_resp = requests.post(
|
| 93 |
f"{env_url}/step",
|
| 94 |
-
|
|
|
|
| 95 |
timeout=30
|
| 96 |
)
|
| 97 |
if step_resp.status_code != 200:
|
|
@@ -123,7 +125,7 @@ def run_evaluation(env_url, n_episodes):
|
|
| 123 |
# In OpenEnv, the grader is usually a separate endpoint
|
| 124 |
grader_resp = requests.post(
|
| 125 |
f"{env_url}/grader",
|
| 126 |
-
json={"
|
| 127 |
timeout=60
|
| 128 |
)
|
| 129 |
final_score = grader_resp.json().get("score", 0.0) if grader_resp.status_code == 200 else 0.0
|
|
|
|
| 20 |
MODEL_NAME = os.environ.get("MODEL_NAME", "meta-llama/Llama-3.1-8B-Instruct")
|
| 21 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 22 |
|
| 23 |
+
TASKS = ["short_term_direction", "medium_term_direction", "long_term_conviction"]
|
| 24 |
+
ENV_TERMS = {"short_term_direction": "short", "medium_term_direction": "medium", "long_term_conviction": "long"}
|
| 25 |
|
| 26 |
|
| 27 |
def _parse_direction_and_conviction(text: str):
|
|
|
|
| 60 |
|
| 61 |
for i in range(n_episodes):
|
| 62 |
try:
|
| 63 |
+
# 1. Reset Environment (use params, not json body)
|
| 64 |
+
reset_resp = requests.post(f"{env_url}/reset", params={"term": term}, timeout=30)
|
| 65 |
if reset_resp.status_code != 200:
|
| 66 |
continue
|
| 67 |
|
| 68 |
data = reset_resp.json()
|
| 69 |
+
obs = data.get("observation", {})
|
| 70 |
+
state = obs
|
| 71 |
+
session_id = data.get("info", {}).get("session_id", "")
|
| 72 |
+
symbol = obs.get("symbol", "N/A")
|
| 73 |
+
date = obs.get("date", "N/A")
|
| 74 |
|
| 75 |
# 2. Build Prompt
|
| 76 |
system_prompt = "You are a quantitative analyst. Given technical indicators, predict the directional price move as Bullish, Bearish, or Neutral. Provide reasoning then output a JSON with 'reasoning', 'direction', and 'conviction' (0.0-1.0)."
|
|
|
|
| 89 |
response = chat_completion.choices[0].message.content
|
| 90 |
direction, conviction = _parse_direction_and_conviction(response)
|
| 91 |
|
| 92 |
+
# 4. Step Environment (use params for session_id, json body for action)
|
| 93 |
step_resp = requests.post(
|
| 94 |
f"{env_url}/step",
|
| 95 |
+
params={"session_id": session_id},
|
| 96 |
+
json={"direction": direction, "conviction": conviction},
|
| 97 |
timeout=30
|
| 98 |
)
|
| 99 |
if step_resp.status_code != 200:
|
|
|
|
| 125 |
# In OpenEnv, the grader is usually a separate endpoint
|
| 126 |
grader_resp = requests.post(
|
| 127 |
f"{env_url}/grader",
|
| 128 |
+
json={"task_id": task_id, "episode_results": episode_results},
|
| 129 |
timeout=60
|
| 130 |
)
|
| 131 |
final_score = grader_resp.json().get("score", 0.0) if grader_resp.status_code == 200 else 0.0
|