Update utils.py
Browse files
utils.py
CHANGED
@@ -267,11 +267,23 @@ def rag_chain(prompt, db, k=3):
|
|
267 |
rag_template = "Nutze ausschließlich die folgenden Kontext Teile am Ende, um die Frage zu beantworten . " + template + "Frage: " + prompt + "Kontext Teile: "
|
268 |
retrieved_chunks = db.similarity_search(prompt, k)
|
269 |
|
270 |
-
|
|
|
271 |
for i, chunk in enumerate(retrieved_chunks):
|
272 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
273 |
|
274 |
-
return neu_prompt
|
275 |
|
276 |
|
277 |
|
|
|
267 |
rag_template = "Nutze ausschließlich die folgenden Kontext Teile am Ende, um die Frage zu beantworten . " + template + "Frage: " + prompt + "Kontext Teile: "
|
268 |
retrieved_chunks = db.similarity_search(prompt, k)
|
269 |
|
270 |
+
# Erstelle ein Dictionary für die Chunks
|
271 |
+
chunks_dict = []
|
272 |
for i, chunk in enumerate(retrieved_chunks):
|
273 |
+
chunk_dict = {
|
274 |
+
"chunk_index": i + 1,
|
275 |
+
"page_content": chunk.page_content, # assuming chunk has page_content attribute
|
276 |
+
"metadata": chunk.metadata # assuming chunk has metadata attribute
|
277 |
+
}
|
278 |
+
chunks_dict.append(chunk_dict)
|
279 |
+
|
280 |
+
# Erstelle das neue Prompt
|
281 |
+
neu_prompt = rag_template
|
282 |
+
for chunk in chunks_dict:
|
283 |
+
neu_prompt += f"{chunk['chunk_index']}. {chunk['page_content']}\n"
|
284 |
+
|
285 |
+
return neu_prompt, chunks_dict # returning both the new prompt and the dictionary
|
286 |
|
|
|
287 |
|
288 |
|
289 |
|