Spaces:
Configuration error
Configuration error
oremaz
commited on
Commit
·
bd0cde3
1
Parent(s):
80d56b6
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -239,16 +239,17 @@ def create_rag_tool_fn(documents: List[Document], query: str = None) -> Union[Qu
|
|
| 239 |
|
| 240 |
return rag_engine_tool
|
| 241 |
|
| 242 |
-
|
| 243 |
fn=create_rag_tool_fn,
|
| 244 |
-
name="
|
| 245 |
description=(
|
|
|
|
| 246 |
"Use this tool to build a Retrieval Augmented Generation (RAG) engine from documents AND optionally query it immediately. "
|
| 247 |
-
"Input: documents (list of documents
|
| 248 |
"If no query is provided: creates and returns a RAG query engine tool for later use. "
|
| 249 |
"If query is provided: creates the RAG engine AND immediately returns the answer to your question. "
|
| 250 |
-
"
|
| 251 |
-
"
|
| 252 |
)
|
| 253 |
)
|
| 254 |
# 1. Create the base DuckDuckGo search tool from the official spec.
|
|
@@ -288,51 +289,6 @@ extract_url_tool = FunctionTool.from_defaults(
|
|
| 288 |
)
|
| 289 |
)
|
| 290 |
|
| 291 |
-
from llama_index.core.query_pipeline import QueryPipeline, FnComponent
|
| 292 |
-
|
| 293 |
-
# Convertir vos fonctions en composants de pipeline
|
| 294 |
-
def read_and_parse_fn(input_path: str):
|
| 295 |
-
"""Function compatible avec QueryPipeline"""
|
| 296 |
-
return read_and_parse_content(input_path)
|
| 297 |
-
|
| 298 |
-
def create_rag_fn(documents, query = None):
|
| 299 |
-
"""Function compatible avec QueryPipeline"""
|
| 300 |
-
return create_rag_tool(documents, query)
|
| 301 |
-
|
| 302 |
-
# Créer le pipeline avec FnComponent
|
| 303 |
-
def create_forced_rag_pipeline():
|
| 304 |
-
pipeline = QueryPipeline(verbose=True)
|
| 305 |
-
|
| 306 |
-
# Utiliser FnComponent au lieu de FunctionTool
|
| 307 |
-
pipeline.add_modules({
|
| 308 |
-
"read_and_parse": FnComponent(fn=read_and_parse_fn),
|
| 309 |
-
"create_rag": FnComponent(fn=create_rag_fn),
|
| 310 |
-
})
|
| 311 |
-
|
| 312 |
-
# Forcer la liaison
|
| 313 |
-
pipeline.add_link("read_and_parse", "create_rag")
|
| 314 |
-
|
| 315 |
-
return pipeline
|
| 316 |
-
|
| 317 |
-
forced_rag_pipeline = create_forced_rag_pipeline()
|
| 318 |
-
|
| 319 |
-
def forced_rag_pipeline_fn(input_path, query) :
|
| 320 |
-
return forced_rag_pipeline.run(input_path,query)
|
| 321 |
-
# Remplacer les tools individuels par le pipeline
|
| 322 |
-
information_retrieval_tool = FunctionTool.from_defaults(
|
| 323 |
-
fn=forced_rag_pipeline_fn,
|
| 324 |
-
name="information_retrieval_tool",
|
| 325 |
-
description=(
|
| 326 |
-
"This tool is the PRIMARY and MOST EFFECTIVE method for answering user queries by extracting and retrieving information from URLs or documents. "
|
| 327 |
-
"When given a document or URL, it AUTOMATICALLY processes the content and DIRECTLY ANSWERS your specific question or information need. "
|
| 328 |
-
"The tool first uses read_and_parse to fully extract and parse content from web pages, PDFs, or document files. "
|
| 329 |
-
"Then, it creates a powerful Retrieval Augmented Generation (RAG) query engine optimized for semantic search and precise information retrieval. "
|
| 330 |
-
"Most importantly, it IMMEDIATELY applies this RAG engine to provide direct, accurate answers to your query, eliminating the need for manual searching. "
|
| 331 |
-
"This tool is specifically designed to transform user questions into precise answers by leveraging advanced document understanding and query processing capabilities. "
|
| 332 |
-
"Instead of manual page access or ad-hoc parsing, use this tool to get immediate, reliable answers to your information retrieval needs."
|
| 333 |
-
)
|
| 334 |
-
)
|
| 335 |
-
|
| 336 |
safe_globals = {
|
| 337 |
"__builtins__": {
|
| 338 |
"len": len, "str": str, "int": int, "float": float,
|
|
@@ -600,6 +556,7 @@ class EnhancedGAIAAgent:
|
|
| 600 |
# Initialize only the tools that are actually defined in the file
|
| 601 |
self.available_tools = [
|
| 602 |
extract_url_tool,
|
|
|
|
| 603 |
information_retrieval_tool,
|
| 604 |
code_execution_tool,
|
| 605 |
generate_code_tool,
|
|
|
|
| 239 |
|
| 240 |
return rag_engine_tool
|
| 241 |
|
| 242 |
+
information_retrieval_tool = FunctionTool.from_defaults(
|
| 243 |
fn=create_rag_tool_fn,
|
| 244 |
+
name="information_retrieval_tool",
|
| 245 |
description=(
|
| 246 |
+
"This is the BEST and OPTIMAL tool to query information from documents parsed from URLs or files. "
|
| 247 |
"Use this tool to build a Retrieval Augmented Generation (RAG) engine from documents AND optionally query it immediately. "
|
| 248 |
+
"Input: documents (list of documents) and optional query parameter. "
|
| 249 |
"If no query is provided: creates and returns a RAG query engine tool for later use. "
|
| 250 |
"If query is provided: creates the RAG engine AND immediately returns the answer to your question. "
|
| 251 |
+
"ALWAYS use this tool when you need to retrieve specific information from documents obtained via URLs or file. "
|
| 252 |
+
"This dual-mode tool enables both RAG engine creation and direct question-answering in one step, making it the most efficient approach for document-based information retrieval."
|
| 253 |
)
|
| 254 |
)
|
| 255 |
# 1. Create the base DuckDuckGo search tool from the official spec.
|
|
|
|
| 289 |
)
|
| 290 |
)
|
| 291 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
safe_globals = {
|
| 293 |
"__builtins__": {
|
| 294 |
"len": len, "str": str, "int": int, "float": float,
|
|
|
|
| 556 |
# Initialize only the tools that are actually defined in the file
|
| 557 |
self.available_tools = [
|
| 558 |
extract_url_tool,
|
| 559 |
+
read_and_parse_tool,
|
| 560 |
information_retrieval_tool,
|
| 561 |
code_execution_tool,
|
| 562 |
generate_code_tool,
|