kevanthonyP commited on
Commit
5a01f1c
·
verified ·
1 Parent(s): 1b34c7a

Update inference.py

Browse files
Files changed (1) hide show
  1. inference.py +27 -15
inference.py CHANGED
@@ -1,24 +1,36 @@
 
1
  import requests
 
2
 
3
- BASE_URL = "https://kevanthonyp-it-support-triage.hf.space"
 
 
 
 
 
4
 
5
  TASKS = ["task_easy", "task_medium", "task_hard"]
6
 
7
  def agent_policy(observation):
8
- text = str(observation).lower()
9
- if "password" in text or "hacked" in text:
10
- return {
11
- "category": "security",
12
- "priority": "high",
13
- "response": "Disconnect system and contact IT."
14
- }
15
- elif "not working" in text:
16
- return {
17
- "category": "hardware",
18
- "priority": "medium",
19
- "response": "Restart device."
20
- }
21
- else:
 
 
 
 
 
22
  return {
23
  "category": "software",
24
  "priority": "low",
 
1
+ import os
2
  import requests
3
+ from openai import OpenAI
4
 
5
+ BASE_URL = os.environ.get("BASE_URL", "https://kevanthonyp-it-support-triage.hf.space")
6
+
7
+ client = OpenAI(
8
+ base_url=os.environ["API_BASE_URL"],
9
+ api_key=os.environ["API_KEY"],
10
+ )
11
 
12
  TASKS = ["task_easy", "task_medium", "task_hard"]
13
 
14
  def agent_policy(observation):
15
+ prompt = f"""You are an IT support triage agent. Given this support ticket observation, respond with a JSON object containing:
16
+ - category: one of "security", "hardware", "software", "network"
17
+ - priority: one of "high", "medium", "low"
18
+ - response: a brief action to resolve the issue
19
+
20
+ Observation: {observation}
21
+
22
+ Respond with only valid JSON, no markdown."""
23
+
24
+ completion = client.chat.completions.create(
25
+ model="openai/gpt-4o-mini",
26
+ messages=[{"role": "user", "content": prompt}],
27
+ max_tokens=200,
28
+ )
29
+
30
+ import json
31
+ try:
32
+ return json.loads(completion.choices[0].message.content)
33
+ except Exception:
34
  return {
35
  "category": "software",
36
  "priority": "low",