Update GAIA agent-updated requirements
Browse files- app.py +3 -30
- requirements.txt +22 -28
- tools.py +35 -0
app.py
CHANGED
|
@@ -100,41 +100,14 @@ def extract_final_answer(text: str) -> str:
|
|
| 100 |
return normalise(line)
|
| 101 |
return ""
|
| 102 |
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
@Tool.from_function
|
| 107 |
-
def web_open(url: str) -> str:
|
| 108 |
-
"""Open a URL and return raw text (simplest form). Use after web_search when you need details."""
|
| 109 |
-
try:
|
| 110 |
-
r = requests.get(url, timeout=15)
|
| 111 |
-
return r.text[:40_000] # limit to keep context small
|
| 112 |
-
except Exception as e:
|
| 113 |
-
return f"ERROR opening {url}: {e}"
|
| 114 |
-
|
| 115 |
-
@Tool.from_function
|
| 116 |
-
def table_sum(file_bytes: bytes, column: str = "Total") -> str:
|
| 117 |
-
"""Sum a numeric column named *Total* in an uploaded Excel/CSV file and return the sum as 2βdp string."""
|
| 118 |
-
try:
|
| 119 |
-
buf = io.BytesIO(file_bytes)
|
| 120 |
-
if column.lower().endswith("csv"):
|
| 121 |
-
df = pd.read_csv(buf)
|
| 122 |
-
else:
|
| 123 |
-
df = pd.read_excel(buf)
|
| 124 |
-
total = df[column].sum()
|
| 125 |
-
return f"{total:.2f}"
|
| 126 |
-
except Exception as e:
|
| 127 |
-
return f"ERROR {e}"
|
| 128 |
-
|
| 129 |
-
CUSTOM_TOOLS = [web_open, table_sum]
|
| 130 |
-
|
| 131 |
-
# ββ GAIA Agent class βββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 132 |
class GAIAAgent:
|
| 133 |
def __init__(self):
|
| 134 |
os.environ["SKIP_PERSONA_RAG"] = "true"
|
| 135 |
self.llm = setup_llm()
|
| 136 |
from tools import get_gaia_tools # existing web_search, calculator, etc.
|
| 137 |
-
self.tools = get_gaia_tools(self.llm)
|
| 138 |
self._build_agent()
|
| 139 |
|
| 140 |
def _build_agent(self):
|
|
|
|
| 100 |
return normalise(line)
|
| 101 |
return ""
|
| 102 |
|
| 103 |
+
|
| 104 |
+
# ββ GAIA Agent class βββββββββββββββββββββββββββββββββββββββββββββββββββββ βββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
class GAIAAgent:
|
| 106 |
def __init__(self):
|
| 107 |
os.environ["SKIP_PERSONA_RAG"] = "true"
|
| 108 |
self.llm = setup_llm()
|
| 109 |
from tools import get_gaia_tools # existing web_search, calculator, etc.
|
| 110 |
+
self.tools = get_gaia_tools(self.llm)
|
| 111 |
self._build_agent()
|
| 112 |
|
| 113 |
def _build_agent(self):
|
requirements.txt
CHANGED
|
@@ -1,33 +1,27 @@
|
|
| 1 |
-
#
|
| 2 |
-
# Updated for the final course project
|
| 3 |
-
|
| 4 |
-
# Core framework
|
| 5 |
llama-index-core>=0.10.0
|
| 6 |
-
gradio>=4.0.0
|
| 7 |
-
requests>=2.28.0
|
| 8 |
-
pandas>=1.5.0
|
| 9 |
-
|
| 10 |
-
# LLM integrations - multiple options for flexibility
|
| 11 |
-
llama-index-llms-anthropic # Claude 3.5 Sonnet (best for GAIA)
|
| 12 |
-
llama-index-llms-groq # Groq (fast, free tier)
|
| 13 |
-
llama-index-llms-together # Together AI
|
| 14 |
-
llama-index-llms-huggingface-api # HuggingFace (free option)
|
| 15 |
-
llama-index-llms-openai # OpenAI GPT models
|
| 16 |
-
llama-index-llms-google-genai # Google Gemini (generous limits)
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
llama-index-
|
| 23 |
-
|
|
|
|
| 24 |
|
| 25 |
-
#
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
| 30 |
|
| 31 |
-
#
|
| 32 |
-
|
| 33 |
-
nest-asyncio # For async operations
|
|
|
|
| 1 |
+
# Core agent & orchestration
|
|
|
|
|
|
|
|
|
|
| 2 |
llama-index-core>=0.10.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
# LLM back-ends (optional but pre-installed avoids βmodule not foundβ if the key is present)
|
| 5 |
+
llama-index-llms-google-genai # Gemini / Google GenAI
|
| 6 |
+
llama-index-llms-groq # Groq
|
| 7 |
+
llama-index-llms-together # Together AI
|
| 8 |
+
llama-index-llms-anthropic # Claude (optional)
|
| 9 |
+
llama-index-llms-openai # OpenAI (optional)
|
| 10 |
+
llama-index-llms-huggingface-api # HF Inference API fallback
|
| 11 |
|
| 12 |
+
# Tools that appear in tools.py
|
| 13 |
+
duckduckgo-search>=6.0.0 # Fallback web search
|
| 14 |
+
chromadb>=0.4.0 # Vector store (only used if persona RAG re-enabled)
|
| 15 |
+
llama-index-embeddings-huggingface
|
| 16 |
+
llama-index-vector-stores-chroma
|
| 17 |
+
llama-index-retrievers-bm25
|
| 18 |
|
| 19 |
+
# Data / utility libraries
|
| 20 |
+
pandas>=1.5.0
|
| 21 |
+
openpyxl>=3.1.0 # Needed for Excel parsing in table_sum()
|
| 22 |
+
requests>=2.28.0
|
| 23 |
+
python-dotenv # Local testing convenience
|
| 24 |
+
nest-asyncio # Keeps Gradio + asyncio happy
|
| 25 |
|
| 26 |
+
# Front-end
|
| 27 |
+
gradio[oauth]>=4.0.0
|
|
|
tools.py
CHANGED
|
@@ -10,11 +10,28 @@ import math
|
|
| 10 |
import re
|
| 11 |
from typing import List, Optional
|
| 12 |
from llama_index.core.tools import FunctionTool, QueryEngineTool
|
|
|
|
| 13 |
|
| 14 |
# Set up better logging
|
| 15 |
logger = logging.getLogger(__name__)
|
| 16 |
logger.setLevel(logging.INFO)
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
# ==========================================
|
| 19 |
# Web Search Functions
|
| 20 |
# ==========================================
|
|
@@ -545,9 +562,27 @@ def get_gaia_tools(llm=None):
|
|
| 545 |
name="weather",
|
| 546 |
description="""Get current weather for a location. Input should be the location name."""
|
| 547 |
)
|
|
|
|
|
|
|
| 548 |
]
|
| 549 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 550 |
tools.extend(function_tools)
|
|
|
|
| 551 |
|
| 552 |
# Skip persona RAG for GAIA evaluation (too slow)
|
| 553 |
if os.getenv("SKIP_PERSONA_RAG", "false").lower() != "true":
|
|
|
|
| 10 |
import re
|
| 11 |
from typing import List, Optional
|
| 12 |
from llama_index.core.tools import FunctionTool, QueryEngineTool
|
| 13 |
+
import io, pandas as pd
|
| 14 |
|
| 15 |
# Set up better logging
|
| 16 |
logger = logging.getLogger(__name__)
|
| 17 |
logger.setLevel(logging.INFO)
|
| 18 |
|
| 19 |
+
|
| 20 |
+
# --- helper functions -----------------
|
| 21 |
+
def _web_open_raw(url: str) -> str:
|
| 22 |
+
try:
|
| 23 |
+
return requests.get(url, timeout=15).text[:40_000]
|
| 24 |
+
except Exception as e:
|
| 25 |
+
return f"ERROR opening {url}: {e}"
|
| 26 |
+
|
| 27 |
+
def _table_sum_raw(file_bytes: bytes, column: str = "Total") -> str:
|
| 28 |
+
try:
|
| 29 |
+
buf = io.BytesIO(file_bytes)
|
| 30 |
+
df = (pd.read_csv(buf) if column.lower().endswith("csv") else pd.read_excel(buf))
|
| 31 |
+
return f"{df[column].sum():.2f}"
|
| 32 |
+
except Exception as e:
|
| 33 |
+
return f"ERROR {e}"
|
| 34 |
+
|
| 35 |
# ==========================================
|
| 36 |
# Web Search Functions
|
| 37 |
# ==========================================
|
|
|
|
| 562 |
name="weather",
|
| 563 |
description="""Get current weather for a location. Input should be the location name."""
|
| 564 |
)
|
| 565 |
+
|
| 566 |
+
|
| 567 |
]
|
| 568 |
|
| 569 |
+
# --- FunctionTool wrappers -------------
|
| 570 |
+
web_open_tool = FunctionTool.from_defaults(
|
| 571 |
+
fn=_web_open_raw,
|
| 572 |
+
name="web_open",
|
| 573 |
+
description="Open a URL returned by web_search and return page text (first 40 kB).",
|
| 574 |
+
)
|
| 575 |
+
|
| 576 |
+
table_sum_tool = FunctionTool.from_defaults(
|
| 577 |
+
fn=_table_sum_raw,
|
| 578 |
+
name="table_sum",
|
| 579 |
+
description="Sum numeric column 'Total' in an uploaded CSV/XLSX and return the total (two decimals).",
|
| 580 |
+
)
|
| 581 |
+
|
| 582 |
+
CUSTOM_TOOLS = [web_open_tool, table_sum_tool]
|
| 583 |
+
|
| 584 |
tools.extend(function_tools)
|
| 585 |
+
tools.extend(CUSTOM_TOOLS)
|
| 586 |
|
| 587 |
# Skip persona RAG for GAIA evaluation (too slow)
|
| 588 |
if os.getenv("SKIP_PERSONA_RAG", "false").lower() != "true":
|