Spaces:
Configuration error
Configuration error
oremaz
commited on
Commit
·
a8a67ee
1
Parent(s):
c9df553
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -14,7 +14,7 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
| 14 |
# LlamaIndex core imports
|
| 15 |
from llama_index.core import VectorStoreIndex, Document, Settings
|
| 16 |
from llama_index.core.agent.workflow import FunctionAgent, ReActAgent, AgentStream
|
| 17 |
-
from llama_index.core.node_parser import
|
| 18 |
from llama_index.core.postprocessor import SentenceTransformerRerank
|
| 19 |
from llama_index.core.query_engine import RetrieverQueryEngine
|
| 20 |
from llama_index.core.retrievers import VectorIndexRetriever
|
|
@@ -366,13 +366,15 @@ class DynamicQueryEngineManager:
|
|
| 366 |
|
| 367 |
# Use UnstructuredElementNodeParser for text content with multimodal awareness
|
| 368 |
element_parser = UnstructuredElementNodeParser()
|
|
|
|
| 369 |
nodes = []
|
| 370 |
|
| 371 |
# Process text documents with UnstructuredElementNodeParser
|
| 372 |
if text_documents:
|
| 373 |
try:
|
| 374 |
-
|
| 375 |
-
|
|
|
|
| 376 |
except Exception as e:
|
| 377 |
print(f"Error parsing text documents with UnstructuredElementNodeParser: {e}")
|
| 378 |
# Fallback to simple parsing if UnstructuredElementNodeParser fails
|
|
|
|
| 14 |
# LlamaIndex core imports
|
| 15 |
from llama_index.core import VectorStoreIndex, Document, Settings
|
| 16 |
from llama_index.core.agent.workflow import FunctionAgent, ReActAgent, AgentStream
|
| 17 |
+
from llama_index.core.node_parser import UnstructuredElementNodeParser, SentenceSplitter
|
| 18 |
from llama_index.core.postprocessor import SentenceTransformerRerank
|
| 19 |
from llama_index.core.query_engine import RetrieverQueryEngine
|
| 20 |
from llama_index.core.retrievers import VectorIndexRetriever
|
|
|
|
| 366 |
|
| 367 |
# Use UnstructuredElementNodeParser for text content with multimodal awareness
|
| 368 |
element_parser = UnstructuredElementNodeParser()
|
| 369 |
+
splitter = SentenceSplitter(chunk_size=1024, chunk_overlap=200)
|
| 370 |
nodes = []
|
| 371 |
|
| 372 |
# Process text documents with UnstructuredElementNodeParser
|
| 373 |
if text_documents:
|
| 374 |
try:
|
| 375 |
+
initial_nodes = element_parser.get_nodes_from_documents(text_documents)
|
| 376 |
+
final_nodes = splitter.get_nodes_from_documents(initial_nodes)
|
| 377 |
+
nodes.extend(final_nodes)
|
| 378 |
except Exception as e:
|
| 379 |
print(f"Error parsing text documents with UnstructuredElementNodeParser: {e}")
|
| 380 |
# Fallback to simple parsing if UnstructuredElementNodeParser fails
|