Update app.py
Browse files
app.py
CHANGED
|
@@ -11,7 +11,15 @@ import re
|
|
| 11 |
# --- Enhanced Tools ---
|
| 12 |
@tool
|
| 13 |
def enhanced_search(query: str, num_results: int = 3) -> str:
|
| 14 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
try:
|
| 16 |
with DDGS() as ddgs:
|
| 17 |
results = ddgs.text(query, max_results=num_results)
|
|
@@ -29,7 +37,14 @@ def enhanced_search(query: str, num_results: int = 3) -> str:
|
|
| 29 |
|
| 30 |
@tool
|
| 31 |
def scientific_calculator(expression: str) -> str:
|
| 32 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
allowed_names = {k: v for k, v in math.__dict__.items() if not k.startswith("__")}
|
| 34 |
try:
|
| 35 |
result = eval(expression, {"__builtins__": {}}, allowed_names)
|
|
@@ -39,12 +54,25 @@ def scientific_calculator(expression: str) -> str:
|
|
| 39 |
|
| 40 |
@tool
|
| 41 |
def get_current_date() -> str:
|
| 42 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 44 |
|
| 45 |
@tool
|
| 46 |
def unit_converter(amount: float, from_unit: str, to_unit: str) -> str:
|
| 47 |
-
"""Converts between common units
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
conversions = {
|
| 49 |
('miles', 'kilometers'): lambda x: x * 1.60934,
|
| 50 |
('pounds', 'kilograms'): lambda x: x * 0.453592,
|
|
@@ -59,6 +87,7 @@ def unit_converter(amount: float, from_unit: str, to_unit: str) -> str:
|
|
| 59 |
return "Invalid amount"
|
| 60 |
return f"Unsupported conversion: {from_unit} → {to_unit}"
|
| 61 |
|
|
|
|
| 62 |
# --- Agent Core ---
|
| 63 |
class GAIAAgent:
|
| 64 |
def __init__(self):
|
|
|
|
| 11 |
# --- Enhanced Tools ---
|
| 12 |
@tool
|
| 13 |
def enhanced_search(query: str, num_results: int = 3) -> str:
|
| 14 |
+
"""Performs web search with result filtering and quality checks.
|
| 15 |
+
|
| 16 |
+
Args:
|
| 17 |
+
query: The search query string to look up.
|
| 18 |
+
num_results: Number of results to return (default 3).
|
| 19 |
+
|
| 20 |
+
Returns:
|
| 21 |
+
A formatted string containing the search results or error message.
|
| 22 |
+
"""
|
| 23 |
try:
|
| 24 |
with DDGS() as ddgs:
|
| 25 |
results = ddgs.text(query, max_results=num_results)
|
|
|
|
| 37 |
|
| 38 |
@tool
|
| 39 |
def scientific_calculator(expression: str) -> str:
|
| 40 |
+
"""Evaluates mathematical expressions with scientific functions.
|
| 41 |
+
|
| 42 |
+
Args:
|
| 43 |
+
expression: The mathematical expression to evaluate.
|
| 44 |
+
|
| 45 |
+
Returns:
|
| 46 |
+
The result as a string or error message.
|
| 47 |
+
"""
|
| 48 |
allowed_names = {k: v for k, v in math.__dict__.items() if not k.startswith("__")}
|
| 49 |
try:
|
| 50 |
result = eval(expression, {"__builtins__": {}}, allowed_names)
|
|
|
|
| 54 |
|
| 55 |
@tool
|
| 56 |
def get_current_date() -> str:
|
| 57 |
+
"""Gets the current date and time.
|
| 58 |
+
|
| 59 |
+
Returns:
|
| 60 |
+
Current datetime in YYYY-MM-DD HH:MM:SS format.
|
| 61 |
+
"""
|
| 62 |
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 63 |
|
| 64 |
@tool
|
| 65 |
def unit_converter(amount: float, from_unit: str, to_unit: str) -> str:
|
| 66 |
+
"""Converts between common measurement units.
|
| 67 |
+
|
| 68 |
+
Args:
|
| 69 |
+
amount: The numerical value to convert.
|
| 70 |
+
from_unit: The source unit (e.g., 'miles').
|
| 71 |
+
to_unit: The target unit (e.g., 'kilometers').
|
| 72 |
+
|
| 73 |
+
Returns:
|
| 74 |
+
The converted value with unit or error message.
|
| 75 |
+
"""
|
| 76 |
conversions = {
|
| 77 |
('miles', 'kilometers'): lambda x: x * 1.60934,
|
| 78 |
('pounds', 'kilograms'): lambda x: x * 0.453592,
|
|
|
|
| 87 |
return "Invalid amount"
|
| 88 |
return f"Unsupported conversion: {from_unit} → {to_unit}"
|
| 89 |
|
| 90 |
+
|
| 91 |
# --- Agent Core ---
|
| 92 |
class GAIAAgent:
|
| 93 |
def __init__(self):
|