Spaces:
Build error
Build error
Update app.py
Browse files3 unmodified lines456789101112131415161718192021222324252627282930313233341635363738394041424344454647484950515253545556575859606162636465666768697071727374757677187879808182838458 unmodified lines143144145831461471481493 unmodified linesimport inspectimport pandas as pd
from smolagents import ToolCallingAgent, HfApiModel, DuckDuckGoSearchTool, PythonInterpreterToolfrom smolagents import OpenAIServerModel
from agentsTools.toolVisitWebpage import visit_webpagefrom agentsTools.tool_fetch_task_file import fetch_task_filefrom agentsTools.tool_read_excel_as_json import read_excel_as_json
# (Keep Constants as is)# --- Constants ---DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
hf_token = os.getenv("HUGGINGFACEHUB_API_TOKEN")
def get_gemini_model(): return OpenAIServerModel( model_id="gemini-2.5-pro-preview-03-25", api_base="https://generativelanguage.googleapis.com/v1beta/", api_key=os.getenv("GEMINI_API_KEY", "your-gemini-api-key-here") )
model = get_gemini_model()
# --- Basic Agent Definition ---# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------class BasicAgent: def __init__(self): print("BasicAgent initialized.") def __call__(self, question: str) -> str: def __call__(self, question: str, taskid: str) -> str: print(f"Agent received question (first 50 chars): {question[:50]}...") agent = ToolCallingAgent( tools=[ DuckDuckGoSearchTool(), PythonInterpreterTool(), visit_webpage, fetch_task_file, read_excel_as_json, # update_File,
], #model=HfApiModel(api_key=hf_token), model=model, max_steps=10 )
task = f""" You are a general AI assistant. I will ask you a question and you can use 8 steps to answer it. You can use the tools I provided to you to answer the question. Every time you use a tool, the number of steps will decrease by one. If you have a list of possible pages to visit, prefer the wikipedia ones. If a page does not allow visit, skip it. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
The taskid is {taskid} in case you need to get extra files, use taskid and not name of the file and the question is {question}
"""
# Let the agent drive the task execution (ReAct loop) fixed_answer = "This is a default answer." # fixed_answer = "This is a default answer." fixed_answer = agent.run(task)
print(f"Agent returning fixed answer: {fixed_answer}") return fixed_answer
58 unmodified lines print(f"Skipping item with missing task_id or question: {item}") continue try: submitted_answer = agent(question_text) submitted_answer = agent(question_text,task_id) answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer}) results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer}) except Exception as e:app.py+66-3