| | import os |
| | from smolagents import CodeAgent, ToolCallingAgent |
| | from smolagents import OpenAIServerModel |
| | from tools.fetch import fetch_webpage |
| | from tools.yttranscript import get_youtube_transcript, get_youtube_title_description |
| | import myprompts |
| |
|
| | |
| | class BasicAgent: |
| | def __init__(self): |
| | print("BasicAgent initialized.") |
| | def __call__(self, question: str) -> str: |
| |
|
| | print(f"Agent received question (first 50 chars): {question[:50]}...") |
| |
|
| | try: |
| | |
| | print("Calling reviewer agent...") |
| | reviewer_answer = reviewer_agent.run(myprompts.review_prompt + "\nThe question is:\n" + question) |
| | print(f"Reviewer agent answer: {reviewer_answer}") |
| |
|
| | question = question + '\n' + myprompts.output_format |
| | fixed_answer = "" |
| |
|
| | if reviewer_answer == "code": |
| | fixed_answer = gaia_agent.run(question) |
| | print(f"Code agent answer: {fixed_answer}") |
| | |
| | elif reviewer_answer == "model": |
| | |
| | print("Using model agent to answer the question.") |
| | fixed_answer = model_agent.run(myprompts.model_prompt + "\nThe question is:\n" + question) |
| | print(f"Model agent answer: {fixed_answer}") |
| |
|
| | return fixed_answer |
| | except Exception as e: |
| | error = f"An error occurred while processing the question: {e}" |
| | print(error) |
| | return error |
| |
|
| | |
| | |
| | |
| | model = OpenAIServerModel( |
| | model_id="gpt-3.5-turbo", |
| | api_base="https://api.openai.com/v1", |
| | api_key=os.environ["OPENAI_API_KEY"], |
| | ) |
| |
|
| | reviewer_agent= ToolCallingAgent(model=model, tools=[]) |
| | model_agent = ToolCallingAgent(model=model,tools=[fetch_webpage]) |
| | gaia_agent = CodeAgent(tools=[fetch_webpage,get_youtube_title_description,get_youtube_transcript ], model=model) |
| |
|
| | if __name__ == "__main__": |
| | |
| | question = "What was the actual enrollment of the Malko competition in 2023?" |
| | agent = BasicAgent() |
| | answer = agent(question) |
| | print(f"Answer: {answer}") |