Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
import time
|
| 3 |
import gc
|
|
|
|
| 4 |
from queue import Queue
|
| 5 |
from threading import Thread, Event
|
| 6 |
from itertools import islice
|
|
@@ -160,6 +161,8 @@ def chat_response(user_msg, chat_history, system_prompt,
|
|
| 160 |
else:
|
| 161 |
debug = 'Web search disabled.'
|
| 162 |
|
|
|
|
|
|
|
| 163 |
try:
|
| 164 |
# wait up to 1s for snippets, then replace debug with them
|
| 165 |
if enable_search:
|
|
@@ -172,8 +175,6 @@ def chat_response(user_msg, chat_history, system_prompt,
|
|
| 172 |
else:
|
| 173 |
debug = "*No web search results found.*"
|
| 174 |
enriched = system_prompt
|
| 175 |
-
else:
|
| 176 |
-
enriched = system_prompt
|
| 177 |
|
| 178 |
pipe = load_pipeline(model_name)
|
| 179 |
prompt = format_conversation(history, enriched, pipe["tokenizer"])
|
|
@@ -259,7 +260,7 @@ def chat_response(user_msg, chat_history, system_prompt,
|
|
| 259 |
gen_thread.join()
|
| 260 |
yield history, debug + prompt_debug
|
| 261 |
except Exception as e:
|
| 262 |
-
history.append({'role': 'assistant', 'content': f"Error: {
|
| 263 |
yield history, debug
|
| 264 |
finally:
|
| 265 |
gc.collect()
|
|
|
|
| 1 |
import os
|
| 2 |
import time
|
| 3 |
import gc
|
| 4 |
+
import traceback
|
| 5 |
from queue import Queue
|
| 6 |
from threading import Thread, Event
|
| 7 |
from itertools import islice
|
|
|
|
| 161 |
else:
|
| 162 |
debug = 'Web search disabled.'
|
| 163 |
|
| 164 |
+
|
| 165 |
+
enriched = system_prompt
|
| 166 |
try:
|
| 167 |
# wait up to 1s for snippets, then replace debug with them
|
| 168 |
if enable_search:
|
|
|
|
| 175 |
else:
|
| 176 |
debug = "*No web search results found.*"
|
| 177 |
enriched = system_prompt
|
|
|
|
|
|
|
| 178 |
|
| 179 |
pipe = load_pipeline(model_name)
|
| 180 |
prompt = format_conversation(history, enriched, pipe["tokenizer"])
|
|
|
|
| 260 |
gen_thread.join()
|
| 261 |
yield history, debug + prompt_debug
|
| 262 |
except Exception as e:
|
| 263 |
+
history.append({'role': 'assistant', 'content': f"Error: {traceback.format_exc()}"})
|
| 264 |
yield history, debug
|
| 265 |
finally:
|
| 266 |
gc.collect()
|