Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -28,51 +28,56 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 28 |
class BasicAgent:
|
| 29 |
def __init__(self):
|
| 30 |
print("BasicAgent initialized. . . .")
|
| 31 |
-
# self.agent = smart_agent()
|
| 32 |
-
# self.api_key = os.getenv("HF_TOKEN")
|
| 33 |
OpenAI_key = os.getenv("OPEN_AI_TOKEN")
|
| 34 |
#self.llm = OpenAI(model="gpt-4o-mini", temperature=0.2, api_key=OpenAI_key)
|
| 35 |
-
self.llm = OpenAI(model="gpt-4o", temperature=0.1, api_key=OpenAI_key)
|
| 36 |
self.system_prompt = (
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
"- Use 'youtube_transcript_tool' to extract transcripts from YouTube videos when the question requires understanding the video content. (e.g., 'Use youtube_transcript to summarize the key points of this video').\n"
|
| 43 |
-
"- Use 'transcribe_audio_tool' to transcribe uploaded audio files. (e.g., 'Use audio_transcriber to get the text from this audio recording').\n"
|
| 44 |
-
"- Use 'solve_chess_image_tool' to analyze and solve chess puzzles from images. (e.g., 'Use chess_image_solver to determine the best move in this chess position').\n"
|
| 45 |
-
"- Use 'parse_file_and_summarize_tool' to parse and analyze data from Excel or CSV files. (e.g., 'Use file_parser to calculate the average sales from this data').\n"
|
| 46 |
-
"- Use 'vegetable_classifier_tool' to classify a list of food items and extract only the vegetables. (e.g., 'Use vegetable_classifier_2022 to get a list of the vegetables in this grocery list').\n"
|
| 47 |
-
"- Use 'excel_food_sales_sum_tool' to extract total food sales from excel files. (e.g., 'Use excel_food_sales_sum to calculate the total food sales').\n"
|
| 48 |
-
"- Use 'google_web_search_tool' to find factual information about topics, events, people, from the web if not spificied to be fund in wikipedia etc. (e.g., 'find the population of France').\n"
|
| 49 |
-
"Do NOT guess or make up answers. If a tool cannot provide the answer, truthfully respond that you were unable to find the information.\n"
|
| 50 |
-
"Use the tools to research or calculate the answer.\n"
|
| 51 |
-
"If a tool fails, explain the reason for the failure instead of hallucinating an answer.\n"
|
| 52 |
-
"Provide concise and direct answers as requested in the questions. Do not add extra information unless explicitly asked for.\n"
|
| 53 |
-
"For example, if asked for a number, return only the number. If asked for a list, return only the list.\n"
|
| 54 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
self.agent = AgentWorkflow.from_tools_or_functions(
|
| 56 |
[
|
| 57 |
wikipedia_search_tool, youtube_transcript_tool, youtube_transcript_snippet_tool, round_to_two_decimals_tool, text_inverter_tool, google_web_search_tool,transcribe_audio_tool, excel_food_sales_sum_tool, parse_file_and_summarize_tool, solve_chess_image_tool, vegetable_classifier_tool
|
| 58 |
],
|
| 59 |
llm=self.llm,
|
| 60 |
system_prompt=self.system_prompt,
|
| 61 |
-
verbose=True,
|
| 62 |
)
|
| 63 |
async def run(self, question: str) -> str:
|
| 64 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 65 |
# answer = await self.agent.run(question)
|
| 66 |
answer = await self.agent.run(
|
| 67 |
f"{question}\n\nIf you have enough information, respond with a concise final answer.",
|
| 68 |
-
max_iterations=
|
| 69 |
)
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
|
|
|
| 76 |
|
| 77 |
def __call__(self, question: str) -> str:
|
| 78 |
return asyncio.run(self.run(question))
|
|
|
|
| 28 |
class BasicAgent:
|
| 29 |
def __init__(self):
|
| 30 |
print("BasicAgent initialized. . . .")
|
|
|
|
|
|
|
| 31 |
OpenAI_key = os.getenv("OPEN_AI_TOKEN")
|
| 32 |
#self.llm = OpenAI(model="gpt-4o-mini", temperature=0.2, api_key=OpenAI_key)
|
|
|
|
| 33 |
self.system_prompt = (
|
| 34 |
+
"You are a helpful AI assistant completing GAIA benchmark tasks.\n"
|
| 35 |
+
"You MUST use the tools provided when needed.\n"
|
| 36 |
+
"If you already have enough information, respond directly with:\n"
|
| 37 |
+
"FINAL ANSWER: <answer>\n"
|
| 38 |
+
"Once you output 'FINAL ANSWER', stop reasoning and do not call any tool.\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
)
|
| 40 |
+
self.llm = OpenAI(model="gpt-4o", temperature=0.1, api_key=OpenAI_key)
|
| 41 |
+
# self.system_prompt = (
|
| 42 |
+
# "You are a helpful AI assistant completing GAIA benchmark tasks.\n"
|
| 43 |
+
# "You MUST use the tools provided to answer the user's question. Do not answer from your own knowledge.\n"
|
| 44 |
+
# "Carefully analyze the question to determine the most appropriate tool to use.\n"
|
| 45 |
+
# "Here are guidelines for using the tools:\n"
|
| 46 |
+
# "- Use 'wikipedia_search_tool' to find factual information about topics, events, people, etc. (e.g., 'Use wikipedia_search to find the population of France').\n"
|
| 47 |
+
# "- Use 'youtube_transcript_tool' to extract transcripts from YouTube videos when the question requires understanding the video content. (e.g., 'Use youtube_transcript to summarize the key points of this video').\n"
|
| 48 |
+
# "- Use 'transcribe_audio_tool' to transcribe uploaded audio files. (e.g., 'Use audio_transcriber to get the text from this audio recording').\n"
|
| 49 |
+
# "- Use 'solve_chess_image_tool' to analyze and solve chess puzzles from images. (e.g., 'Use chess_image_solver to determine the best move in this chess position').\n"
|
| 50 |
+
# "- Use 'parse_file_and_summarize_tool' to parse and analyze data from Excel or CSV files. (e.g., 'Use file_parser to calculate the average sales from this data').\n"
|
| 51 |
+
# "- Use 'vegetable_classifier_tool' to classify a list of food items and extract only the vegetables. (e.g., 'Use vegetable_classifier_2022 to get a list of the vegetables in this grocery list').\n"
|
| 52 |
+
# "- Use 'excel_food_sales_sum_tool' to extract total food sales from excel files. (e.g., 'Use excel_food_sales_sum to calculate the total food sales').\n"
|
| 53 |
+
# "- Use 'google_web_search_tool' to find factual information about topics, events, people, from the web if not spificied to be fund in wikipedia etc. (e.g., 'find the population of France').\n"
|
| 54 |
+
# "Do NOT guess or make up answers. If a tool cannot provide the answer, truthfully respond that you were unable to find the information.\n"
|
| 55 |
+
# "Use the tools to research or calculate the answer.\n"
|
| 56 |
+
# "If a tool fails, explain the reason for the failure instead of hallucinating an answer.\n"
|
| 57 |
+
# "Provide concise and direct answers as requested in the questions. Do not add extra information unless explicitly asked for.\n"
|
| 58 |
+
# "For example, if asked for a number, return only the number. If asked for a list, return only the list.\n"
|
| 59 |
+
# )
|
| 60 |
self.agent = AgentWorkflow.from_tools_or_functions(
|
| 61 |
[
|
| 62 |
wikipedia_search_tool, youtube_transcript_tool, youtube_transcript_snippet_tool, round_to_two_decimals_tool, text_inverter_tool, google_web_search_tool,transcribe_audio_tool, excel_food_sales_sum_tool, parse_file_and_summarize_tool, solve_chess_image_tool, vegetable_classifier_tool
|
| 63 |
],
|
| 64 |
llm=self.llm,
|
| 65 |
system_prompt=self.system_prompt,
|
|
|
|
| 66 |
)
|
| 67 |
async def run(self, question: str) -> str:
|
| 68 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 69 |
# answer = await self.agent.run(question)
|
| 70 |
answer = await self.agent.run(
|
| 71 |
f"{question}\n\nIf you have enough information, respond with a concise final answer.",
|
| 72 |
+
max_iterations=10
|
| 73 |
)
|
| 74 |
+
return str(answer)
|
| 75 |
+
# if hasattr(answer, "output"):
|
| 76 |
+
# print(f"Agent returning answer: {answer}")
|
| 77 |
+
# return str(answer.output)
|
| 78 |
+
# else:
|
| 79 |
+
# print(f"Agent returning answer: {answer}")
|
| 80 |
+
# return str(answer)
|
| 81 |
|
| 82 |
def __call__(self, question: str) -> str:
|
| 83 |
return asyncio.run(self.run(question))
|