Update agent.py
Browse files
agent.py
CHANGED
|
@@ -541,7 +541,38 @@ def combine_images(
|
|
| 541 |
return {"error": str(e)}
|
| 542 |
|
| 543 |
|
| 544 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 545 |
|
| 546 |
def build_graph():
|
| 547 |
llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash", api_key=os.getenv("GOOGLE_API_KEY"))
|
|
|
|
| 541 |
return {"error": str(e)}
|
| 542 |
|
| 543 |
|
| 544 |
+
@tool
|
| 545 |
+
def download_task_file(task_id: str, api_url: str = "https://agents-course-unit4-scoring.hf.space") -> str:
|
| 546 |
+
"""
|
| 547 |
+
Download a file associated with a task from the evaluation API.
|
| 548 |
+
Args:
|
| 549 |
+
task_id (str): The task ID to download the file for
|
| 550 |
+
api_url (str): The base API URL (defaults to the evaluation server)
|
| 551 |
+
"""
|
| 552 |
+
try:
|
| 553 |
+
# Construct the file download URL
|
| 554 |
+
file_url = f"{api_url}/files/{task_id}"
|
| 555 |
+
|
| 556 |
+
# Create temporary file
|
| 557 |
+
temp_dir = tempfile.gettempdir()
|
| 558 |
+
filename = f"task_{task_id}.png" # Most files are images
|
| 559 |
+
filepath = os.path.join(temp_dir, filename)
|
| 560 |
+
|
| 561 |
+
# Download the file
|
| 562 |
+
response = requests.get(file_url, stream=True)
|
| 563 |
+
response.raise_for_status()
|
| 564 |
+
|
| 565 |
+
# Save the file
|
| 566 |
+
with open(filepath, "wb") as f:
|
| 567 |
+
for chunk in response.iter_content(chunk_size=8192):
|
| 568 |
+
f.write(chunk)
|
| 569 |
+
|
| 570 |
+
return f"Task file downloaded to {filepath}. You can now analyze this file."
|
| 571 |
+
except Exception as e:
|
| 572 |
+
return f"Error downloading task file: {str(e)}"
|
| 573 |
+
|
| 574 |
+
|
| 575 |
+
tools = [multiply, add, subtract, divide, wikidata_search, tavily_search_tool, youtube_search_tool, combine_images, analyze_image, transform_image, draw_on_image, generate_simple_image, analyze_csv_file, analyze_excel_file, save_and_read_file, download_file_from_url, extract_text_from_image, download_task_file]
|
| 576 |
|
| 577 |
def build_graph():
|
| 578 |
llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash", api_key=os.getenv("GOOGLE_API_KEY"))
|