Spaces:
Sleeping
Sleeping
final fix
Browse files- inference.py +13 -5
inference.py
CHANGED
|
@@ -8,10 +8,14 @@ MODEL_NAME = os.getenv("MODEL_NAME", "Qwen/Qwen2.5-72B-Instruct")
|
|
| 8 |
|
| 9 |
# ------------------ OPENAI CLIENT ------------------
|
| 10 |
|
| 11 |
-
|
|
|
|
| 12 |
base_url=os.environ["API_BASE_URL"],
|
| 13 |
api_key=os.environ["API_KEY"]
|
| 14 |
)
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
MAX_STEPS = 6
|
|
@@ -49,18 +53,22 @@ action_type,column_name
|
|
| 49 |
"""
|
| 50 |
|
| 51 |
try:
|
|
|
|
| 52 |
# 🔥 ALWAYS attempt API call (NO client check)
|
| 53 |
response = client.chat.completions.create(
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
)
|
| 59 |
|
| 60 |
output = response.choices[0].message.content.strip()
|
| 61 |
action_type, column = output.split(",")
|
| 62 |
|
| 63 |
return {"type": action_type.strip(), "column": column.strip()}
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
except Exception as e:
|
| 66 |
print("LLM error:", e)
|
|
|
|
| 8 |
|
| 9 |
# ------------------ OPENAI CLIENT ------------------
|
| 10 |
|
| 11 |
+
try:
|
| 12 |
+
client = OpenAI(
|
| 13 |
base_url=os.environ["API_BASE_URL"],
|
| 14 |
api_key=os.environ["API_KEY"]
|
| 15 |
)
|
| 16 |
+
except Exception as e:
|
| 17 |
+
print("Client init failed:", e)
|
| 18 |
+
client = None
|
| 19 |
|
| 20 |
|
| 21 |
MAX_STEPS = 6
|
|
|
|
| 53 |
"""
|
| 54 |
|
| 55 |
try:
|
| 56 |
+
if client is not None:
|
| 57 |
# 🔥 ALWAYS attempt API call (NO client check)
|
| 58 |
response = client.chat.completions.create(
|
| 59 |
+
model=MODEL_NAME,
|
| 60 |
+
messages=[{"role": "user", "content": prompt}],
|
| 61 |
+
temperature=0.3,
|
| 62 |
+
max_tokens=50
|
| 63 |
)
|
| 64 |
|
| 65 |
output = response.choices[0].message.content.strip()
|
| 66 |
action_type, column = output.split(",")
|
| 67 |
|
| 68 |
return {"type": action_type.strip(), "column": column.strip()}
|
| 69 |
+
|
| 70 |
+
else:
|
| 71 |
+
raise Exception("Client not available")
|
| 72 |
|
| 73 |
except Exception as e:
|
| 74 |
print("LLM error:", e)
|