Spaces:
Sleeping
Sleeping
Update tools.py
Browse files
tools.py
CHANGED
|
@@ -45,8 +45,16 @@ def _download_file_for_task(task_id: str, ext: str) -> str:
|
|
| 45 |
@tool
|
| 46 |
def image_tool(task_id: str) -> str:
|
| 47 |
"""
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
"""
|
| 51 |
|
| 52 |
import requests, os
|
|
@@ -111,12 +119,16 @@ def image_tool(task_id: str) -> str:
|
|
| 111 |
@tool
|
| 112 |
def excel_tool(task_id: str) -> str:
|
| 113 |
"""
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
β’ task_id β required (used to download the file)
|
| 118 |
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
"""
|
| 121 |
print("reached excel_tool")
|
| 122 |
sheet = "Sheet1"
|
|
@@ -141,11 +153,16 @@ import openai
|
|
| 141 |
@tool
|
| 142 |
def audio_transcriber_tool(task_id: str) -> str:
|
| 143 |
"""
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
"""
|
| 150 |
print("reached audio_transcriber_tool")
|
| 151 |
|
|
@@ -188,11 +205,16 @@ import requests
|
|
| 188 |
@tool
|
| 189 |
def wikipedia_search_tool(wiki_query: str) -> str:
|
| 190 |
"""
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
"""
|
| 197 |
print(f"DEBUG: reached wikipedia_search_tool with query: {wiki_query}")
|
| 198 |
try:
|
|
@@ -252,9 +274,16 @@ def wikipedia_search_tool(wiki_query: str) -> str:
|
|
| 252 |
@tool
|
| 253 |
def arxiv_search_tool(arxiv_query: str) -> str:
|
| 254 |
"""
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 258 |
"""
|
| 259 |
print(f"DEBUG: reached arxiv_search_tool with query: {arxiv_query}")
|
| 260 |
try:
|
|
@@ -321,12 +350,16 @@ LLM = ChatOpenAI(model_name="gpt-4o-mini", temperature=0.2)
|
|
| 321 |
@tool
|
| 322 |
def analyze_code_tool(task_id: str) -> str:
|
| 323 |
"""
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 330 |
"""
|
| 331 |
print("reached analyze_code_tool")
|
| 332 |
code_txt = ""
|
|
@@ -357,6 +390,82 @@ def analyze_code_tool(task_id: str) -> str:
|
|
| 357 |
return LLM.invoke(prompt).content.strip()
|
| 358 |
|
| 359 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 360 |
# def web_search_tool(state: AgentState) -> AgentState:
|
| 361 |
# """
|
| 362 |
# Expects: state["web_search_query"] is a nonβempty string.
|
|
@@ -404,56 +513,4 @@ def analyze_code_tool(task_id: str) -> str:
|
|
| 404 |
# return {
|
| 405 |
# "web_search_query": None,
|
| 406 |
# "web_search_result": result_text
|
| 407 |
-
# }
|
| 408 |
-
|
| 409 |
-
# βββββββββββββββββββββββββββ Math Tools βββββββββββββββββββββββββββββββ
|
| 410 |
-
|
| 411 |
-
@tool
|
| 412 |
-
def add_tool(a: float, b: float) -> str:
|
| 413 |
-
"""
|
| 414 |
-
Add two numbers.
|
| 415 |
-
Args:
|
| 416 |
-
a: First number
|
| 417 |
-
b: Second number
|
| 418 |
-
Returns: The sum of a and b
|
| 419 |
-
"""
|
| 420 |
-
result = a + b
|
| 421 |
-
return f"Addition result: {a} + {b} = {result}"
|
| 422 |
-
|
| 423 |
-
@tool
|
| 424 |
-
def subtract_tool(a: float, b: float) -> str:
|
| 425 |
-
"""
|
| 426 |
-
Subtract two numbers.
|
| 427 |
-
Args:
|
| 428 |
-
a: First number (minuend)
|
| 429 |
-
b: Second number (subtrahend)
|
| 430 |
-
Returns: The difference of a minus b
|
| 431 |
-
"""
|
| 432 |
-
result = a - b
|
| 433 |
-
return f"Subtraction result: {a} - {b} = {result}"
|
| 434 |
-
|
| 435 |
-
@tool
|
| 436 |
-
def multiply_tool(a: float, b: float) -> str:
|
| 437 |
-
"""
|
| 438 |
-
Multiply two numbers.
|
| 439 |
-
Args:
|
| 440 |
-
a: First number
|
| 441 |
-
b: Second number
|
| 442 |
-
Returns: The product of a and b
|
| 443 |
-
"""
|
| 444 |
-
result = a * b
|
| 445 |
-
return f"Multiplication result: {a} Γ {b} = {result}"
|
| 446 |
-
|
| 447 |
-
@tool
|
| 448 |
-
def divide_tool(a: float, b: float) -> str:
|
| 449 |
-
"""
|
| 450 |
-
Divide two numbers.
|
| 451 |
-
Args:
|
| 452 |
-
a: First number (dividend)
|
| 453 |
-
b: Second number (divisor)
|
| 454 |
-
Returns: The quotient of a divided by b
|
| 455 |
-
"""
|
| 456 |
-
if b == 0:
|
| 457 |
-
return "Division error: Cannot divide by zero"
|
| 458 |
-
result = a / b
|
| 459 |
-
return f"Division result: {a} Γ· {b} = {result}"
|
|
|
|
| 45 |
@tool
|
| 46 |
def image_tool(task_id: str) -> str:
|
| 47 |
"""
|
| 48 |
+
TOOL NAME: Image Analysis Tool
|
| 49 |
+
|
| 50 |
+
Purpose: When the user asks about images, photos, or visual content, use this tool to get a description of the image.
|
| 51 |
+
|
| 52 |
+
Input: A task_id string that identifies the specific image to analyze.
|
| 53 |
+
|
| 54 |
+
Example usage:
|
| 55 |
+
- "What is shown in this image?"
|
| 56 |
+
- "Describe the contents of the picture"
|
| 57 |
+
- "What objects are visible in the photo?"
|
| 58 |
"""
|
| 59 |
|
| 60 |
import requests, os
|
|
|
|
| 119 |
@tool
|
| 120 |
def excel_tool(task_id: str) -> str:
|
| 121 |
"""
|
| 122 |
+
TOOL NAME: Excel Data Analysis Tool
|
| 123 |
+
|
| 124 |
+
Purpose: When the user asks about data in spreadsheets, tables, or Excel files, use this tool to read and analyze the data.
|
|
|
|
| 125 |
|
| 126 |
+
Input: A task_id string that identifies the specific Excel file to analyze.
|
| 127 |
+
|
| 128 |
+
Example usage:
|
| 129 |
+
- "What data is in this spreadsheet?"
|
| 130 |
+
- "Analyze the Excel file contents"
|
| 131 |
+
- "Show me the data from the table"
|
| 132 |
"""
|
| 133 |
print("reached excel_tool")
|
| 134 |
sheet = "Sheet1"
|
|
|
|
| 153 |
@tool
|
| 154 |
def audio_transcriber_tool(task_id: str) -> str:
|
| 155 |
"""
|
| 156 |
+
TOOL NAME: Audio Transcription Tool
|
| 157 |
+
|
| 158 |
+
Purpose: When the user asks about audio files, speech, or wants to know what was said in an audio recording, use this tool.
|
| 159 |
+
|
| 160 |
+
Input: A task_id string that identifies the specific audio file to transcribe.
|
| 161 |
+
|
| 162 |
+
Example usage:
|
| 163 |
+
- "What is said in this audio file?"
|
| 164 |
+
- "Transcribe the speech from the recording"
|
| 165 |
+
- "Convert the audio to text"
|
| 166 |
"""
|
| 167 |
print("reached audio_transcriber_tool")
|
| 168 |
|
|
|
|
| 205 |
@tool
|
| 206 |
def wikipedia_search_tool(wiki_query: str) -> str:
|
| 207 |
"""
|
| 208 |
+
TOOL NAME: Wikipedia Search Tool
|
| 209 |
+
|
| 210 |
+
Purpose: When the user asks for historical, biographical, scientific, or factual information, use this tool.
|
| 211 |
+
|
| 212 |
+
Input: A string describing a topic to search on Wikipedia.
|
| 213 |
+
|
| 214 |
+
Example usage:
|
| 215 |
+
- "Who was Marie Curie?"
|
| 216 |
+
- "Explain quantum entanglement"
|
| 217 |
+
- "Tell me about the French Revolution"
|
| 218 |
"""
|
| 219 |
print(f"DEBUG: reached wikipedia_search_tool with query: {wiki_query}")
|
| 220 |
try:
|
|
|
|
| 274 |
@tool
|
| 275 |
def arxiv_search_tool(arxiv_query: str) -> str:
|
| 276 |
"""
|
| 277 |
+
TOOL NAME: ArXiv Academic Search Tool
|
| 278 |
+
|
| 279 |
+
Purpose: When the user asks for academic research, scientific papers, or technical information, use this tool.
|
| 280 |
+
|
| 281 |
+
Input: A string describing the academic topic to search for on ArXiv.
|
| 282 |
+
|
| 283 |
+
Example usage:
|
| 284 |
+
- "Find research papers about machine learning"
|
| 285 |
+
- "What are recent studies on climate change?"
|
| 286 |
+
- "Search for papers on quantum computing"
|
| 287 |
"""
|
| 288 |
print(f"DEBUG: reached arxiv_search_tool with query: {arxiv_query}")
|
| 289 |
try:
|
|
|
|
| 350 |
@tool
|
| 351 |
def analyze_code_tool(task_id: str) -> str:
|
| 352 |
"""
|
| 353 |
+
TOOL NAME: Code Analysis Tool
|
| 354 |
+
|
| 355 |
+
Purpose: When the user asks about code, programming files, or wants to understand what a script does, use this tool.
|
| 356 |
+
|
| 357 |
+
Input: A task_id string that identifies the specific code file to analyze.
|
| 358 |
+
|
| 359 |
+
Example usage:
|
| 360 |
+
- "What does this Python code do?"
|
| 361 |
+
- "Analyze the code file for bugs"
|
| 362 |
+
- "Explain the functions in this script"
|
| 363 |
"""
|
| 364 |
print("reached analyze_code_tool")
|
| 365 |
code_txt = ""
|
|
|
|
| 390 |
return LLM.invoke(prompt).content.strip()
|
| 391 |
|
| 392 |
|
| 393 |
+
|
| 394 |
+
# βββββββββββββββββββββββββββ Math Tools βββοΏ½οΏ½οΏ½βββββββββββββββββββββββββββ
|
| 395 |
+
|
| 396 |
+
@tool
|
| 397 |
+
def add_tool(a: float, b: float) -> str:
|
| 398 |
+
"""
|
| 399 |
+
TOOL NAME: Addition Tool
|
| 400 |
+
|
| 401 |
+
Purpose: When the user asks to add numbers or perform addition calculations, use this tool.
|
| 402 |
+
|
| 403 |
+
Input: Two numbers (a and b) to add together.
|
| 404 |
+
|
| 405 |
+
Example usage:
|
| 406 |
+
- "What is 25 + 17?"
|
| 407 |
+
- "Add 3.14 and 2.86"
|
| 408 |
+
- "Calculate the sum of 100 and 250"
|
| 409 |
+
"""
|
| 410 |
+
result = a + b
|
| 411 |
+
return f"Addition result: {a} + {b} = {result}"
|
| 412 |
+
|
| 413 |
+
@tool
|
| 414 |
+
def subtract_tool(a: float, b: float) -> str:
|
| 415 |
+
"""
|
| 416 |
+
TOOL NAME: Subtraction Tool
|
| 417 |
+
|
| 418 |
+
Purpose: When the user asks to subtract numbers or perform subtraction calculations, use this tool.
|
| 419 |
+
|
| 420 |
+
Input: Two numbers (a and b) where b is subtracted from a.
|
| 421 |
+
|
| 422 |
+
Example usage:
|
| 423 |
+
- "What is 50 - 23?"
|
| 424 |
+
- "Subtract 15.5 from 40.2"
|
| 425 |
+
- "Calculate 1000 minus 347"
|
| 426 |
+
"""
|
| 427 |
+
result = a - b
|
| 428 |
+
return f"Subtraction result: {a} - {b} = {result}"
|
| 429 |
+
|
| 430 |
+
@tool
|
| 431 |
+
def multiply_tool(a: float, b: float) -> str:
|
| 432 |
+
"""
|
| 433 |
+
TOOL NAME: Multiplication Tool
|
| 434 |
+
|
| 435 |
+
Purpose: When the user asks to multiply numbers or perform multiplication calculations, use this tool.
|
| 436 |
+
|
| 437 |
+
Input: Two numbers (a and b) to multiply together.
|
| 438 |
+
|
| 439 |
+
Example usage:
|
| 440 |
+
- "What is 8 Γ 7?"
|
| 441 |
+
- "Multiply 12.5 by 4"
|
| 442 |
+
- "Calculate the product of 15 and 20"
|
| 443 |
+
"""
|
| 444 |
+
result = a * b
|
| 445 |
+
return f"Multiplication result: {a} Γ {b} = {result}"
|
| 446 |
+
|
| 447 |
+
@tool
|
| 448 |
+
def divide_tool(a: float, b: float) -> str:
|
| 449 |
+
"""
|
| 450 |
+
TOOL NAME: Division Tool
|
| 451 |
+
|
| 452 |
+
Purpose: When the user asks to divide numbers or perform division calculations, use this tool.
|
| 453 |
+
|
| 454 |
+
Input: Two numbers (a and b) where a is divided by b.
|
| 455 |
+
|
| 456 |
+
Example usage:
|
| 457 |
+
- "What is 100 Γ· 4?"
|
| 458 |
+
- "Divide 75 by 3"
|
| 459 |
+
- "Calculate 144 divided by 12"
|
| 460 |
+
"""
|
| 461 |
+
if b == 0:
|
| 462 |
+
return "Division error: Cannot divide by zero"
|
| 463 |
+
result = a / b
|
| 464 |
+
return f"Division result: {a} Γ· {b} = {result}"
|
| 465 |
+
|
| 466 |
+
|
| 467 |
+
|
| 468 |
+
|
| 469 |
# def web_search_tool(state: AgentState) -> AgentState:
|
| 470 |
# """
|
| 471 |
# Expects: state["web_search_query"] is a nonβempty string.
|
|
|
|
| 513 |
# return {
|
| 514 |
# "web_search_query": None,
|
| 515 |
# "web_search_result": result_text
|
| 516 |
+
# }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|