Update app.py
Browse files
app.py
CHANGED
|
@@ -41,14 +41,33 @@ def safe_calc(expr: str):
|
|
| 41 |
|
| 42 |
@tool
|
| 43 |
def calculator(expr: str) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
try:
|
| 45 |
val = safe_calc(expr)
|
| 46 |
return json.dumps({"expression": expr, "result": float(val)})
|
| 47 |
except Exception as e:
|
| 48 |
return json.dumps({"error": f"Calc error: {e}"})
|
| 49 |
|
|
|
|
| 50 |
@tool
|
| 51 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
try:
|
| 53 |
tz = pytz.timezone(timezone)
|
| 54 |
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
|
@@ -56,6 +75,7 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 56 |
except Exception as e:
|
| 57 |
return json.dumps({"error": f"Timezone error: {e}"})
|
| 58 |
|
|
|
|
| 59 |
# -------------------------
|
| 60 |
# Load prompts.yaml if exists
|
| 61 |
# -------------------------
|
|
@@ -72,7 +92,7 @@ except Exception:
|
|
| 72 |
MODEL_ID = 'Qwen/Qwen2.5-Coder-32B-Instruct'
|
| 73 |
|
| 74 |
code_agent = CodeAgent(
|
| 75 |
-
model=MODEL_ID,
|
| 76 |
tools=[calculator, get_current_time_in_timezone],
|
| 77 |
max_steps=6,
|
| 78 |
verbosity_level=0,
|
|
|
|
| 41 |
|
| 42 |
@tool
|
| 43 |
def calculator(expr: str) -> str:
|
| 44 |
+
"""
|
| 45 |
+
Safely evaluate a mathematical expression.
|
| 46 |
+
|
| 47 |
+
Args:
|
| 48 |
+
expr (str): A string containing a math expression like "2 + 2 * 3".
|
| 49 |
+
|
| 50 |
+
Returns:
|
| 51 |
+
str: JSON string with {"expression": expr, "result": value} or {"error": "..."} on failure.
|
| 52 |
+
"""
|
| 53 |
try:
|
| 54 |
val = safe_calc(expr)
|
| 55 |
return json.dumps({"expression": expr, "result": float(val)})
|
| 56 |
except Exception as e:
|
| 57 |
return json.dumps({"error": f"Calc error: {e}"})
|
| 58 |
|
| 59 |
+
|
| 60 |
@tool
|
| 61 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 62 |
+
"""
|
| 63 |
+
Get the current local time in a specified timezone.
|
| 64 |
+
|
| 65 |
+
Args:
|
| 66 |
+
timezone (str): A valid timezone string (e.g., "Europe/Paris").
|
| 67 |
+
|
| 68 |
+
Returns:
|
| 69 |
+
str: JSON string with {"timezone": timezone, "local_time": "..."} or {"error": "..."} on failure.
|
| 70 |
+
"""
|
| 71 |
try:
|
| 72 |
tz = pytz.timezone(timezone)
|
| 73 |
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
| 75 |
except Exception as e:
|
| 76 |
return json.dumps({"error": f"Timezone error: {e}"})
|
| 77 |
|
| 78 |
+
|
| 79 |
# -------------------------
|
| 80 |
# Load prompts.yaml if exists
|
| 81 |
# -------------------------
|
|
|
|
| 92 |
MODEL_ID = 'Qwen/Qwen2.5-Coder-32B-Instruct'
|
| 93 |
|
| 94 |
code_agent = CodeAgent(
|
| 95 |
+
model=MODEL_ID,
|
| 96 |
tools=[calculator, get_current_time_in_timezone],
|
| 97 |
max_steps=6,
|
| 98 |
verbosity_level=0,
|