Update agent.py
Browse files
agent.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
# agent.py —
|
2 |
|
3 |
import os
|
4 |
import asyncio
|
@@ -75,16 +75,16 @@ def extract_excel_total_food_sales(file_path: str) -> str:
|
|
75 |
except Exception as e:
|
76 |
return f"[EXCEL ERROR] {e}"
|
77 |
|
78 |
-
# Assemble tools with
|
79 |
TOOLS = [
|
80 |
-
FunctionTool.from_defaults(search_wikipedia, return_direct=True, name="search_wikipedia"
|
81 |
-
FunctionTool.from_defaults(run_python_code,
|
82 |
-
FunctionTool.from_defaults(get_youtube_transcript,
|
83 |
-
FunctionTool.from_defaults(transcribe_audio,
|
84 |
-
FunctionTool.from_defaults(extract_excel_total_food_sales,
|
85 |
]
|
86 |
|
87 |
-
# Create agent with
|
88 |
llm = OpenAI(model="gpt-4")
|
89 |
|
90 |
agent = FunctionCallingAgent.from_tools(
|
@@ -108,4 +108,12 @@ Rules:
|
|
108 |
5. Avoid all explanation unless requested.
|
109 |
"""
|
110 |
)
|
111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# agent.py — final version using FunctionCallingAgent
|
2 |
|
3 |
import os
|
4 |
import asyncio
|
|
|
75 |
except Exception as e:
|
76 |
return f"[EXCEL ERROR] {e}"
|
77 |
|
78 |
+
# Assemble tools with return_direct
|
79 |
TOOLS = [
|
80 |
+
FunctionTool.from_defaults(search_wikipedia, return_direct=True, name="search_wikipedia"),
|
81 |
+
FunctionTool.from_defaults(run_python_code, return_direct=True, name="run_python"),
|
82 |
+
FunctionTool.from_defaults(get_youtube_transcript, return_direct=True, name="get_youtube_transcript"),
|
83 |
+
FunctionTool.from_defaults(transcribe_audio, return_direct=True, name="transcribe_audio"),
|
84 |
+
FunctionTool.from_defaults(extract_excel_total_food_sales, return_direct=True, name="extract_excel_total_food_sales")
|
85 |
]
|
86 |
|
87 |
+
# Create agent with FunctionCallingAgent
|
88 |
llm = OpenAI(model="gpt-4")
|
89 |
|
90 |
agent = FunctionCallingAgent.from_tools(
|
|
|
108 |
5. Avoid all explanation unless requested.
|
109 |
"""
|
110 |
)
|
111 |
+
|
112 |
+
# Agent answer wrapper
|
113 |
+
async def answer_question(question: str) -> str:
|
114 |
+
try:
|
115 |
+
result = await agent.run(question)
|
116 |
+
return str(result).strip()
|
117 |
+
except Exception as e:
|
118 |
+
print("❌ Agent error:", e)
|
119 |
+
return "[ERROR] " + str(e)
|