Omkar1806 commited on
Commit
d7e0500
·
verified ·
1 Parent(s): 272ae1e

Update inference.py

Browse files
Files changed (1) hide show
  1. inference.py +14 -12
inference.py CHANGED
@@ -9,15 +9,16 @@ API_BASE_URL = os.environ.get("API_BASE_URL")
9
  API_KEY = os.environ.get("API_KEY")
10
  MODEL_NAME = os.environ.get("MODEL_NAME", "meta-llama/Llama-3-70b-chat-hf")
11
 
 
12
  client = OpenAI(base_url=API_BASE_URL, api_key=API_KEY)
13
 
14
  def get_llm_action(email_desc, context, keywords):
15
  prompt = f"""
16
- Email: {email_desc}
 
17
  Context: {context}
18
  Keywords: {keywords}
19
- Classify: Urgency (0-2), Routing (0-2), Resolution (0-2).
20
- Return only numbers: e.g., 1, 0, 1
21
  """
22
  try:
23
  response = client.chat.completions.create(
@@ -29,7 +30,7 @@ def get_llm_action(email_desc, context, keywords):
29
  res = response.choices[0].message.content.strip()
30
  actions = [int(x.strip()) for x in res.split(",")[:3]]
31
  return np.array(actions, dtype=np.int64)
32
- except:
33
  return np.array([0, 0, 0], dtype=np.int64)
34
 
35
  def run_inference():
@@ -37,10 +38,11 @@ def run_inference():
37
 
38
  for task_name in tasks:
39
  try:
40
- # Task load karna (Ensure your env.py supports task argument)
41
  env = EmailTriageEnv(task=task_name, shuffle=False)
42
  obs, info = env.reset(seed=42)
43
 
 
44
  print(f"[START] task={task_name}", flush=True)
45
 
46
  terminated = False
@@ -49,24 +51,24 @@ def run_inference():
49
  emails = list(env._queue)
50
 
51
  while not terminated and step_count < len(emails):
52
- action = get_llm_action(emails[step_count]['description'],
53
- emails[step_count]['context'],
54
- emails[step_count]['keywords'])
 
55
 
56
  obs, reward, terminated, truncated, info = env.step(action)
57
  total_reward += reward
58
 
 
59
  print(f"[STEP] step={step_count+1} reward={reward:.2f}", flush=True)
60
  step_count += 1
61
 
62
- # --- FIX: SCORE CLIPPING (Strictly between 0 and 1) ---
63
- # Agar score 1.0 hai toh 0.99 ho jayega, agar 0.0 hai toh 0.01
64
- final_score = max(0.01, min(0.99, total_reward))
65
 
 
66
  print(f"[END] task={task_name} score={final_score:.3f} steps={step_count}", flush=True)
67
 
68
  except Exception as e:
69
- # Failure case mein bhi 0.010 bhej rahe hain range error se bachne ke liye
70
  print(f"[END] task={task_name} score=0.010 steps=0", flush=True)
71
 
72
  if __name__ == "__main__":
 
9
  API_KEY = os.environ.get("API_KEY")
10
  MODEL_NAME = os.environ.get("MODEL_NAME", "meta-llama/Llama-3-70b-chat-hf")
11
 
12
+ # Proxy Client Initialization
13
  client = OpenAI(base_url=API_BASE_URL, api_key=API_KEY)
14
 
15
  def get_llm_action(email_desc, context, keywords):
16
  prompt = f"""
17
+ Classify this email:
18
+ Desc: {email_desc}
19
  Context: {context}
20
  Keywords: {keywords}
21
+ Return 3 numbers (0-2) separated by commas. Example: 1, 0, 1
 
22
  """
23
  try:
24
  response = client.chat.completions.create(
 
30
  res = response.choices[0].message.content.strip()
31
  actions = [int(x.strip()) for x in res.split(",")[:3]]
32
  return np.array(actions, dtype=np.int64)
33
+ except Exception:
34
  return np.array([0, 0, 0], dtype=np.int64)
35
 
36
  def run_inference():
 
38
 
39
  for task_name in tasks:
40
  try:
41
+ # Environment initialize
42
  env = EmailTriageEnv(task=task_name, shuffle=False)
43
  obs, info = env.reset(seed=42)
44
 
45
+
46
  print(f"[START] task={task_name}", flush=True)
47
 
48
  terminated = False
 
51
  emails = list(env._queue)
52
 
53
  while not terminated and step_count < len(emails):
54
+ email_data = emails[step_count]
55
+ action = get_llm_action(email_data['description'],
56
+ email_data['context'],
57
+ email_data['keywords'])
58
 
59
  obs, reward, terminated, truncated, info = env.step(action)
60
  total_reward += reward
61
 
62
+
63
  print(f"[STEP] step={step_count+1} reward={reward:.2f}", flush=True)
64
  step_count += 1
65
 
 
 
 
66
 
67
+ final_score = max(0.01, min(0.99, total_reward))
68
  print(f"[END] task={task_name} score={final_score:.3f} steps={step_count}", flush=True)
69
 
70
  except Exception as e:
71
+
72
  print(f"[END] task={task_name} score=0.010 steps=0", flush=True)
73
 
74
  if __name__ == "__main__":