Update agent.py
Browse files
agent.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
-
# agent.py —
|
2 |
|
3 |
import os
|
4 |
import asyncio
|
5 |
from llama_index.llms.openai import OpenAI
|
6 |
-
from llama_index.core.agent import
|
7 |
from llama_index.core.tools import FunctionTool
|
8 |
|
9 |
from langchain_community.utilities.wikipedia import WikipediaAPIWrapper
|
@@ -84,10 +84,10 @@ TOOLS = [
|
|
84 |
FunctionTool.from_defaults(extract_excel_total_food_sales, name="extract_excel_total_food_sales", description="Sum total sales from Excel where category is 'food'.")
|
85 |
]
|
86 |
|
87 |
-
# Create agent with
|
88 |
llm = OpenAI(model="gpt-4")
|
89 |
|
90 |
-
agent =
|
91 |
tools=TOOLS,
|
92 |
llm=llm,
|
93 |
verbose=True,
|
@@ -109,10 +109,12 @@ Rules:
|
|
109 |
5. Avoid all explanation unless requested.
|
110 |
"""
|
111 |
)
|
|
|
|
|
112 |
async def answer_question(question: str) -> str:
|
113 |
try:
|
114 |
result = await agent.run(question)
|
115 |
-
return result.strip()
|
116 |
except Exception as e:
|
117 |
print("❌ Agent error:", e)
|
118 |
return "[ERROR] " + str(e)
|
|
|
1 |
+
# agent.py — alternatywa z FunctionAgent (stabilna dla GAIA)
|
2 |
|
3 |
import os
|
4 |
import asyncio
|
5 |
from llama_index.llms.openai import OpenAI
|
6 |
+
from llama_index.core.agent.workflow import FunctionAgent
|
7 |
from llama_index.core.tools import FunctionTool
|
8 |
|
9 |
from langchain_community.utilities.wikipedia import WikipediaAPIWrapper
|
|
|
84 |
FunctionTool.from_defaults(extract_excel_total_food_sales, name="extract_excel_total_food_sales", description="Sum total sales from Excel where category is 'food'.")
|
85 |
]
|
86 |
|
87 |
+
# Create agent with FunctionAgent (compatible with run)
|
88 |
llm = OpenAI(model="gpt-4")
|
89 |
|
90 |
+
agent = FunctionAgent(
|
91 |
tools=TOOLS,
|
92 |
llm=llm,
|
93 |
verbose=True,
|
|
|
109 |
5. Avoid all explanation unless requested.
|
110 |
"""
|
111 |
)
|
112 |
+
|
113 |
+
# Stable async answer handler
|
114 |
async def answer_question(question: str) -> str:
|
115 |
try:
|
116 |
result = await agent.run(question)
|
117 |
+
return str(result).strip()
|
118 |
except Exception as e:
|
119 |
print("❌ Agent error:", e)
|
120 |
return "[ERROR] " + str(e)
|