Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -72,9 +72,31 @@ async def chunk_text(data: ChunkRequest):
|
|
72 |
Settings.embed_model = SimpleEmbedding()
|
73 |
|
74 |
|
75 |
-
|
|
|
|
|
|
|
|
|
76 |
parser = SemanticSplitterNodeParser.from_defaults()
|
77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
# ✅ Vérification du nombre de chunks générés
|
80 |
print(f"✅ Nombre de chunks générés : {len(nodes)}")
|
|
|
72 |
Settings.embed_model = SimpleEmbedding()
|
73 |
|
74 |
|
75 |
+
|
76 |
+
|
77 |
+
|
78 |
+
print("✅ Début du split sémantique...")
|
79 |
+
|
80 |
parser = SemanticSplitterNodeParser.from_defaults()
|
81 |
+
fallback_splitter = Settings.node_parser # fallback = splitter par défaut
|
82 |
+
|
83 |
+
doc = Document(text=data.text)
|
84 |
+
|
85 |
+
try:
|
86 |
+
nodes = parser.get_nodes_from_documents([doc])
|
87 |
+
print(f"✅ Nombre de chunks générés : {len(nodes)}")
|
88 |
+
print(f"🧩 Exemple chunk : {nodes[0].text[:100]}...")
|
89 |
+
except Exception as e:
|
90 |
+
print(f"❌ Erreur lors du split sémantique : {e}")
|
91 |
+
nodes = fallback_splitter.get_nodes_from_documents([doc])
|
92 |
+
print(f"⚠️ Split fallback utilisé - chunks générés : {len(nodes)}")
|
93 |
+
|
94 |
+
|
95 |
+
|
96 |
+
|
97 |
+
# ✅ Découpage sémantique intelligent
|
98 |
+
# parser = SemanticSplitterNodeParser.from_defaults()
|
99 |
+
# nodes = parser.get_nodes_from_documents([Document(text=data.text)])
|
100 |
|
101 |
# ✅ Vérification du nombre de chunks générés
|
102 |
print(f"✅ Nombre de chunks générés : {len(nodes)}")
|