Spaces:
Configuration error
Configuration error
oremaz
commited on
Commit
·
6eb1ce3
1
Parent(s):
0883c55
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -48,7 +48,7 @@ from llama_index.core.tools import QueryEngineTool
|
|
| 48 |
from llama_index.core.node_parser import SentenceWindowNodeParser, HierarchicalNodeParser
|
| 49 |
from llama_index.core.postprocessor import SentenceTransformerRerank
|
| 50 |
from llama_index.core.query_engine import RetrieverQueryEngine
|
| 51 |
-
|
| 52 |
|
| 53 |
|
| 54 |
wandb_callback = WandbCallbackHandler(run_args={"project": "gaia-llamaindex-agents"})
|
|
@@ -266,6 +266,30 @@ extract_url_tool = FunctionTool.from_defaults(
|
|
| 266 |
)
|
| 267 |
)
|
| 268 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
safe_globals = {
|
| 270 |
"__builtins__": {
|
| 271 |
"len": len, "str": str, "int": int, "float": float,
|
|
@@ -541,11 +565,10 @@ class EnhancedGAIAAgent:
|
|
| 541 |
|
| 542 |
# Initialize only the tools that are actually defined in the file
|
| 543 |
self.available_tools = [
|
| 544 |
-
read_and_parse_tool,
|
| 545 |
extract_url_tool,
|
| 546 |
code_execution_tool,
|
| 547 |
generate_code_tool,
|
| 548 |
-
|
| 549 |
]
|
| 550 |
|
| 551 |
# Create main coordinator using only defined tools
|
|
@@ -555,11 +578,10 @@ class EnhancedGAIAAgent:
|
|
| 555 |
You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
|
| 556 |
|
| 557 |
Available tools:
|
| 558 |
-
1. **
|
| 559 |
2. **extract_url_tool** - Search and extract relevant URLs when no specific source is provided
|
| 560 |
3. **generate_code_tool** - Generate Python code for complex computations
|
| 561 |
4. **code_execution_tool** - Execute Python code safely
|
| 562 |
-
MANDATORY : IF you use read_and_parse_tool, use : 5. **create_rag_tool** - Create RAG tool from parsed files to improve the information retrieval.
|
| 563 |
""",
|
| 564 |
llm=proj_llm,
|
| 565 |
tools=self.available_tools,
|
|
|
|
| 48 |
from llama_index.core.node_parser import SentenceWindowNodeParser, HierarchicalNodeParser
|
| 49 |
from llama_index.core.postprocessor import SentenceTransformerRerank
|
| 50 |
from llama_index.core.query_engine import RetrieverQueryEngine
|
| 51 |
+
from llama_index.core.query_pipeline import QueryPipeline
|
| 52 |
|
| 53 |
|
| 54 |
wandb_callback = WandbCallbackHandler(run_args={"project": "gaia-llamaindex-agents"})
|
|
|
|
| 266 |
)
|
| 267 |
)
|
| 268 |
|
| 269 |
+
# Créer un pipeline forcé read_and_parse → create_rag
|
| 270 |
+
def create_forced_rag_pipeline():
|
| 271 |
+
pipeline = QueryPipeline(verbose=True)
|
| 272 |
+
|
| 273 |
+
# Ajouter les modules
|
| 274 |
+
pipeline.add_modules({
|
| 275 |
+
"read_and_parse": read_and_parse_tool,
|
| 276 |
+
"create_rag": create_rag_tool,
|
| 277 |
+
})
|
| 278 |
+
|
| 279 |
+
# Forcer la liaison : read_and_parse → create_rag
|
| 280 |
+
pipeline.add_link("read_and_parse", "create_rag")
|
| 281 |
+
|
| 282 |
+
return pipeline
|
| 283 |
+
|
| 284 |
+
forced_rag_pipeline = create_forced_rag_pipeline()
|
| 285 |
+
|
| 286 |
+
# Remplacer les tools individuels par le pipeline
|
| 287 |
+
process_docs_urls_tool = FunctionTool.from_defaults(
|
| 288 |
+
fn=lambda input_path: forced_rag_pipeline.run(input_path),
|
| 289 |
+
name="process_docs_urls_tool",
|
| 290 |
+
description="AUTOMATICALLY processes documents or URLs with read_and_parse for content extraction and parsing then creates RAG query engine on it"
|
| 291 |
+
)
|
| 292 |
+
|
| 293 |
safe_globals = {
|
| 294 |
"__builtins__": {
|
| 295 |
"len": len, "str": str, "int": int, "float": float,
|
|
|
|
| 565 |
|
| 566 |
# Initialize only the tools that are actually defined in the file
|
| 567 |
self.available_tools = [
|
|
|
|
| 568 |
extract_url_tool,
|
| 569 |
code_execution_tool,
|
| 570 |
generate_code_tool,
|
| 571 |
+
process_docs_urls_tool
|
| 572 |
]
|
| 573 |
|
| 574 |
# Create main coordinator using only defined tools
|
|
|
|
| 578 |
You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
|
| 579 |
|
| 580 |
Available tools:
|
| 581 |
+
1. **process_docs_urls_tool** - Read and parse files/URLs (PDF, DOCX, CSV, images, web pages, YouTube, audio files) and create a query engine.
|
| 582 |
2. **extract_url_tool** - Search and extract relevant URLs when no specific source is provided
|
| 583 |
3. **generate_code_tool** - Generate Python code for complex computations
|
| 584 |
4. **code_execution_tool** - Execute Python code safely
|
|
|
|
| 585 |
""",
|
| 586 |
llm=proj_llm,
|
| 587 |
tools=self.available_tools,
|