Spaces:
Sleeping
Sleeping
Update inference.py
Browse files- 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 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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",
|