Update app.py
Browse files
app.py
CHANGED
@@ -225,7 +225,43 @@ def custom_css():
|
|
225 |
"""
|
226 |
|
227 |
|
228 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
229 |
|
230 |
def create_history_entry(page_content, metadata):
|
231 |
source = metadata.get('source', 'No source available')
|
@@ -275,8 +311,10 @@ def generate_auswahl(prompt_in, file, file_history, chatbot, history, anzahl_doc
|
|
275 |
|
276 |
#File hochladen in Chroma und dann Antwort generieren
|
277 |
results = generate_text_zu_doc(neu_file, prompt, k, rag_option, chatbot, history, vektordatenbank)
|
|
|
|
|
278 |
|
279 |
-
for text in
|
280 |
print("text..............."+str(text))
|
281 |
entry = create_history_entry(text['page_content'], text['metadata'])
|
282 |
print("hier...........................")
|
|
|
225 |
"""
|
226 |
|
227 |
|
228 |
+
#####################################################################
|
229 |
+
# Antwort des Vektorstores in ein Dictionary packen
|
230 |
+
def parse_vectorstore_response(response_text):
|
231 |
+
# Trenne die verschiedenen Einträge anhand des Musters
|
232 |
+
entries = re.split(r"(\d+\. page_content=)", response_text)
|
233 |
+
|
234 |
+
# Entferne das erste leere Element, falls vorhanden
|
235 |
+
if entries[0] == '':
|
236 |
+
entries.pop(0)
|
237 |
+
|
238 |
+
# Kombiniere die Identifier und Inhalte wieder zu vollständigen Einträgen
|
239 |
+
entries = [entries[i] + entries[i + 1] for i in range(0, len(entries), 2)]
|
240 |
+
|
241 |
+
parsed_entries = []
|
242 |
+
|
243 |
+
for entry in entries:
|
244 |
+
# Extrahiere page_content
|
245 |
+
page_content_match = re.search(r"page_content='(.*?)' metadata=", entry, re.DOTALL)
|
246 |
+
page_content = page_content_match.group(1) if page_content_match else ''
|
247 |
+
|
248 |
+
# Extrahiere metadata
|
249 |
+
metadata_match = re.search(r"metadata=\{(.*?)\}", entry)
|
250 |
+
metadata_str = metadata_match.group(1) if metadata_match else ''
|
251 |
+
|
252 |
+
# Konvertiere metadata in ein Dictionary
|
253 |
+
metadata = {}
|
254 |
+
for item in metadata_str.split(', '):
|
255 |
+
key, value = item.split(': ')
|
256 |
+
metadata[key.strip("'")] = value.strip("'")
|
257 |
+
|
258 |
+
parsed_entries.append({
|
259 |
+
"page_content": page_content,
|
260 |
+
"metadata": metadata
|
261 |
+
})
|
262 |
+
|
263 |
+
return parsed_entries
|
264 |
+
|
265 |
|
266 |
def create_history_entry(page_content, metadata):
|
267 |
source = metadata.get('source', 'No source available')
|
|
|
311 |
|
312 |
#File hochladen in Chroma und dann Antwort generieren
|
313 |
results = generate_text_zu_doc(neu_file, prompt, k, rag_option, chatbot, history, vektordatenbank)
|
314 |
+
|
315 |
+
results_dictionary = parse_vectorstore_response(results)
|
316 |
|
317 |
+
for text in results_dictionary:
|
318 |
print("text..............."+str(text))
|
319 |
entry = create_history_entry(text['page_content'], text['metadata'])
|
320 |
print("hier...........................")
|