Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -200,9 +200,8 @@ def _get_api_base():
|
|
| 200 |
base = base[:-3]
|
| 201 |
return base
|
| 202 |
|
| 203 |
-
@tool
|
| 204 |
def web_search(query: str) -> str:
|
| 205 |
-
# ... 不变 ...
|
| 206 |
try:
|
| 207 |
url = "https://api.duckduckgo.com/"
|
| 208 |
params = {"q": query, "format": "json", "no_html": 1}
|
|
@@ -218,9 +217,8 @@ def web_search(query: str) -> str:
|
|
| 218 |
except Exception as e:
|
| 219 |
return f"搜索失败: {e}"
|
| 220 |
|
| 221 |
-
@tool
|
| 222 |
def web_scraper(url: str) -> str:
|
| 223 |
-
# ... 不变 ...
|
| 224 |
try:
|
| 225 |
headers = {"User-Agent": "Mozilla/5.0"}
|
| 226 |
resp = requests.get(url, headers=headers, timeout=15)
|
|
@@ -233,9 +231,8 @@ def web_scraper(url: str) -> str:
|
|
| 233 |
except Exception as e:
|
| 234 |
return f"抓取失败: {e}"
|
| 235 |
|
| 236 |
-
@tool
|
| 237 |
def calculator(expression: str) -> str:
|
| 238 |
-
# ... 不变 ...
|
| 239 |
try:
|
| 240 |
import math
|
| 241 |
allowed = {k: v for k, v in math.__dict__.items() if not k.startswith("__")}
|
|
@@ -244,9 +241,8 @@ def calculator(expression: str) -> str:
|
|
| 244 |
except Exception as e:
|
| 245 |
return f"计算失败: {e}"
|
| 246 |
|
| 247 |
-
@tool
|
| 248 |
def analyze_image(image_data: str) -> str:
|
| 249 |
-
"""分析图片内容(URL 或 base64)"""
|
| 250 |
try:
|
| 251 |
headers = {"Authorization": f"Bearer {AGICTO_API_KEY}", "Content-Type": "application/json"}
|
| 252 |
if not image_data.startswith("http"):
|
|
@@ -259,7 +255,6 @@ def analyze_image(image_data: str) -> str:
|
|
| 259 |
]}],
|
| 260 |
"max_tokens": 800
|
| 261 |
}
|
| 262 |
-
# 使用修正后的基地址
|
| 263 |
base = _get_api_base()
|
| 264 |
url = f"{base}/v1/chat/completions"
|
| 265 |
resp = requests.post(url, headers=headers, json=body, timeout=30)
|
|
@@ -269,9 +264,8 @@ def analyze_image(image_data: str) -> str:
|
|
| 269 |
except Exception as e:
|
| 270 |
return f"图片分析失败: {e}"
|
| 271 |
|
| 272 |
-
@tool
|
| 273 |
def transcribe_audio(audio_path: str) -> str:
|
| 274 |
-
"""转录音频文件(路径或 URL)"""
|
| 275 |
try:
|
| 276 |
headers = {"Authorization": f"Bearer {AGICTO_API_KEY}"}
|
| 277 |
if audio_path.startswith("http"):
|
|
@@ -290,9 +284,8 @@ def transcribe_audio(audio_path: str) -> str:
|
|
| 290 |
except Exception as e:
|
| 291 |
return f"转录失败: {e}"
|
| 292 |
|
| 293 |
-
@tool
|
| 294 |
def get_youtube_transcript(video_url: str) -> str:
|
| 295 |
-
# ... 不变 ...
|
| 296 |
try:
|
| 297 |
if "watch?v=" in video_url:
|
| 298 |
vid = video_url.split("v=")[1].split("&")[0]
|
|
@@ -305,9 +298,8 @@ def get_youtube_transcript(video_url: str) -> str:
|
|
| 305 |
except Exception as e:
|
| 306 |
return f"获取字幕失败: {e}"
|
| 307 |
|
| 308 |
-
@tool
|
| 309 |
def download_file_for_task(task_id: str) -> str:
|
| 310 |
-
# ... 不变 ...
|
| 311 |
try:
|
| 312 |
url = f"{api_url_tasks}/files/{task_id}"
|
| 313 |
resp = requests.get(url, timeout=20)
|
|
|
|
| 200 |
base = base[:-3]
|
| 201 |
return base
|
| 202 |
|
| 203 |
+
@tool(description="搜索互联网信息,返回相关摘要。")
|
| 204 |
def web_search(query: str) -> str:
|
|
|
|
| 205 |
try:
|
| 206 |
url = "https://api.duckduckgo.com/"
|
| 207 |
params = {"q": query, "format": "json", "no_html": 1}
|
|
|
|
| 217 |
except Exception as e:
|
| 218 |
return f"搜索失败: {e}"
|
| 219 |
|
| 220 |
+
@tool(description="抓取网页并提取纯文本内容。")
|
| 221 |
def web_scraper(url: str) -> str:
|
|
|
|
| 222 |
try:
|
| 223 |
headers = {"User-Agent": "Mozilla/5.0"}
|
| 224 |
resp = requests.get(url, headers=headers, timeout=15)
|
|
|
|
| 231 |
except Exception as e:
|
| 232 |
return f"抓取失败: {e}"
|
| 233 |
|
| 234 |
+
@tool(description="执行数学表达式计算。")
|
| 235 |
def calculator(expression: str) -> str:
|
|
|
|
| 236 |
try:
|
| 237 |
import math
|
| 238 |
allowed = {k: v for k, v in math.__dict__.items() if not k.startswith("__")}
|
|
|
|
| 241 |
except Exception as e:
|
| 242 |
return f"计算失败: {e}"
|
| 243 |
|
| 244 |
+
@tool(description="分析图片内容(支持URL或base64编码)。")
|
| 245 |
def analyze_image(image_data: str) -> str:
|
|
|
|
| 246 |
try:
|
| 247 |
headers = {"Authorization": f"Bearer {AGICTO_API_KEY}", "Content-Type": "application/json"}
|
| 248 |
if not image_data.startswith("http"):
|
|
|
|
| 255 |
]}],
|
| 256 |
"max_tokens": 800
|
| 257 |
}
|
|
|
|
| 258 |
base = _get_api_base()
|
| 259 |
url = f"{base}/v1/chat/completions"
|
| 260 |
resp = requests.post(url, headers=headers, json=body, timeout=30)
|
|
|
|
| 264 |
except Exception as e:
|
| 265 |
return f"图片分析失败: {e}"
|
| 266 |
|
| 267 |
+
@tool(description="将音频文件(路径或URL)转录为文字。")
|
| 268 |
def transcribe_audio(audio_path: str) -> str:
|
|
|
|
| 269 |
try:
|
| 270 |
headers = {"Authorization": f"Bearer {AGICTO_API_KEY}"}
|
| 271 |
if audio_path.startswith("http"):
|
|
|
|
| 284 |
except Exception as e:
|
| 285 |
return f"转录失败: {e}"
|
| 286 |
|
| 287 |
+
@tool(description="获取YouTube视频的字幕文本。")
|
| 288 |
def get_youtube_transcript(video_url: str) -> str:
|
|
|
|
| 289 |
try:
|
| 290 |
if "watch?v=" in video_url:
|
| 291 |
vid = video_url.split("v=")[1].split("&")[0]
|
|
|
|
| 298 |
except Exception as e:
|
| 299 |
return f"获取字幕失败: {e}"
|
| 300 |
|
| 301 |
+
@tool(description="下载指定任务关联的文件,并返回文本内容或分析结果。")
|
| 302 |
def download_file_for_task(task_id: str) -> str:
|
|
|
|
| 303 |
try:
|
| 304 |
url = f"{api_url_tasks}/files/{task_id}"
|
| 305 |
resp = requests.get(url, timeout=20)
|