Spaces:
Sleeping
Sleeping
added introductory prompt
Browse files- backend.py +19 -17
backend.py
CHANGED
@@ -131,27 +131,29 @@ def handle_query(query_str: str,
|
|
131 |
)
|
132 |
|
133 |
#chat_engine.reset()
|
134 |
-
|
135 |
outputs = []
|
136 |
response = chat_engine.stream_chat(query_str, conversation)
|
137 |
-
|
138 |
#response = chat_engine.chat(query_str)
|
|
|
139 |
for token in response.response_gen:
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
|
|
|
|
155 |
except Exception as e:
|
156 |
yield f"Error processing query: {str(e)}"
|
157 |
|
|
|
131 |
)
|
132 |
|
133 |
#chat_engine.reset()
|
|
|
134 |
outputs = []
|
135 |
response = chat_engine.stream_chat(query_str, conversation)
|
136 |
+
sources = [] # Use a list to collect multiple sources if present
|
137 |
#response = chat_engine.chat(query_str)
|
138 |
+
|
139 |
for token in response.response_gen:
|
140 |
+
if not token.startswith("system:") and not token.startswith("user:"):
|
141 |
+
if token.startswith("file_path:"):
|
142 |
+
sources.append(token)
|
143 |
+
|
144 |
+
outputs.append(token)
|
145 |
+
print(f"Generated token: {token}")
|
146 |
+
yield "".join(outputs)
|
147 |
+
|
148 |
+
if sources:
|
149 |
+
sources_str = ", ".join(sources)
|
150 |
+
outputs.append(f"Fonti utilizzate: {sources_str}")
|
151 |
+
else:
|
152 |
+
outputs.append("Nessuna fonte specifica utilizzata.")
|
153 |
+
|
154 |
+
yield "".join(outputs)
|
155 |
+
|
156 |
+
|
157 |
except Exception as e:
|
158 |
yield f"Error processing query: {str(e)}"
|
159 |
|