Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,6 @@ import requests
|
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
import re
|
| 7 |
-
import json
|
| 8 |
from pathlib import Path
|
| 9 |
from typing import Optional
|
| 10 |
from dotenv import load_dotenv
|
|
@@ -34,6 +33,7 @@ class OpenRouterLLM(ChatOpenAI):
|
|
| 34 |
|
| 35 |
@tool
|
| 36 |
def search_web(query: str) -> str:
|
|
|
|
| 37 |
try:
|
| 38 |
search_url = f"https://api.duckduckgo.com/?q={query}&format=json&no_html=1&skip_disambig=1"
|
| 39 |
response = requests.get(search_url, timeout=10)
|
|
@@ -53,6 +53,7 @@ def search_web(query: str) -> str:
|
|
| 53 |
|
| 54 |
@tool
|
| 55 |
def search_wikipedia(query: str) -> str:
|
|
|
|
| 56 |
try:
|
| 57 |
search_url = "https://en.wikipedia.org/api/rest_v1/page/summary/" + query.replace(" ", "_")
|
| 58 |
response = requests.get(search_url, timeout=10)
|
|
@@ -66,6 +67,7 @@ def search_wikipedia(query: str) -> str:
|
|
| 66 |
|
| 67 |
@tool
|
| 68 |
def execute_python(code: str) -> str:
|
|
|
|
| 69 |
try:
|
| 70 |
safe_globals = {
|
| 71 |
'__builtins__': {
|
|
@@ -93,6 +95,7 @@ def execute_python(code: str) -> str:
|
|
| 93 |
|
| 94 |
@tool
|
| 95 |
def read_excel_file(file_path: str, sheet_name: Optional[str] = None) -> str:
|
|
|
|
| 96 |
try:
|
| 97 |
file_path_obj = Path(file_path)
|
| 98 |
if not file_path_obj.exists():
|
|
@@ -116,6 +119,7 @@ def read_excel_file(file_path: str, sheet_name: Optional[str] = None) -> str:
|
|
| 116 |
|
| 117 |
@tool
|
| 118 |
def read_text_file(file_path: str) -> str:
|
|
|
|
| 119 |
try:
|
| 120 |
file_path_obj = Path(file_path)
|
| 121 |
if not file_path_obj.exists():
|
|
|
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
import re
|
|
|
|
| 7 |
from pathlib import Path
|
| 8 |
from typing import Optional
|
| 9 |
from dotenv import load_dotenv
|
|
|
|
| 33 |
|
| 34 |
@tool
|
| 35 |
def search_web(query: str) -> str:
|
| 36 |
+
"""Search the web using DuckDuckGo and return current information."""
|
| 37 |
try:
|
| 38 |
search_url = f"https://api.duckduckgo.com/?q={query}&format=json&no_html=1&skip_disambig=1"
|
| 39 |
response = requests.get(search_url, timeout=10)
|
|
|
|
| 53 |
|
| 54 |
@tool
|
| 55 |
def search_wikipedia(query: str) -> str:
|
| 56 |
+
"""Search Wikipedia for factual information and return a short summary."""
|
| 57 |
try:
|
| 58 |
search_url = "https://en.wikipedia.org/api/rest_v1/page/summary/" + query.replace(" ", "_")
|
| 59 |
response = requests.get(search_url, timeout=10)
|
|
|
|
| 67 |
|
| 68 |
@tool
|
| 69 |
def execute_python(code: str) -> str:
|
| 70 |
+
"""Execute Python code safely and return the output or error message."""
|
| 71 |
try:
|
| 72 |
safe_globals = {
|
| 73 |
'__builtins__': {
|
|
|
|
| 95 |
|
| 96 |
@tool
|
| 97 |
def read_excel_file(file_path: str, sheet_name: Optional[str] = None) -> str:
|
| 98 |
+
"""Read an Excel file and return its contents as a formatted string."""
|
| 99 |
try:
|
| 100 |
file_path_obj = Path(file_path)
|
| 101 |
if not file_path_obj.exists():
|
|
|
|
| 119 |
|
| 120 |
@tool
|
| 121 |
def read_text_file(file_path: str) -> str:
|
| 122 |
+
"""Read a text file and return its contents as a string."""
|
| 123 |
try:
|
| 124 |
file_path_obj = Path(file_path)
|
| 125 |
if not file_path_obj.exists():
|