Spaces:
Runtime error
Runtime error
on1onmangoes
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -62,33 +62,26 @@ def stream_chat_with_rag(
|
|
62 |
|
63 |
def format_answer_string(answer: str):
|
64 |
"""
|
65 |
-
This function
|
66 |
-
|
67 |
"""
|
68 |
-
# Step 1: Split the
|
69 |
-
split_marker = "
|
70 |
if split_marker in answer:
|
71 |
-
|
|
|
72 |
else:
|
73 |
-
# If no documents
|
74 |
-
|
75 |
|
76 |
-
# Step 2: Clean
|
77 |
-
formatted_answer =
|
78 |
-
|
79 |
-
# Step 3: Format the documents section
|
80 |
-
formatted_answer += "Relevant Documents:\n"
|
81 |
-
document_entries = documents_section.split("Document ")
|
82 |
|
83 |
-
# Step 4: Reformat each document entry
|
84 |
-
for entry in document_entries[1:]: # Skip the first empty split
|
85 |
-
doc_number, rest = entry.split(":", 1)
|
86 |
-
formatted_answer += f"{doc_number}. {rest.strip()}\n\n"
|
87 |
-
|
88 |
return formatted_answer
|
89 |
|
90 |
|
91 |
|
|
|
92 |
# this version works just issue with formatting
|
93 |
# def stream_chat_with_rag(
|
94 |
# message: str,
|
|
|
62 |
|
63 |
def format_answer_string(answer: str):
|
64 |
"""
|
65 |
+
This function extracts and formats the assistant's response before document metadata.
|
66 |
+
Anything after the marker `[(` (where documents are listed) is ignored.
|
67 |
"""
|
68 |
+
# Step 1: Split the response at the start of the document metadata
|
69 |
+
split_marker = "[("
|
70 |
if split_marker in answer:
|
71 |
+
# Everything before the marker is the relevant answer
|
72 |
+
answer_before_docs = answer.split(split_marker)[0]
|
73 |
else:
|
74 |
+
# If no documents metadata, return the entire answer
|
75 |
+
answer_before_docs = answer
|
76 |
|
77 |
+
# Step 2: Clean up formatting by replacing escaped newline characters
|
78 |
+
formatted_answer = answer_before_docs.replace("\\n", "\n").strip()
|
|
|
|
|
|
|
|
|
79 |
|
|
|
|
|
|
|
|
|
|
|
80 |
return formatted_answer
|
81 |
|
82 |
|
83 |
|
84 |
+
|
85 |
# this version works just issue with formatting
|
86 |
# def stream_chat_with_rag(
|
87 |
# message: str,
|