Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -85,13 +85,11 @@ def generate_response(
|
|
| 85 |
messages.append({"role": "user", "content": first_msg})
|
| 86 |
|
| 87 |
# Add conversation history ensuring alternating pattern (user, assistant, user, assistant...)
|
| 88 |
-
for
|
| 89 |
-
if
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
if bot_msg:
|
| 94 |
-
messages.append({"role": "assistant", "content": bot_msg})
|
| 95 |
|
| 96 |
try:
|
| 97 |
response = ""
|
|
@@ -108,7 +106,7 @@ def generate_response(
|
|
| 108 |
except Exception as e:
|
| 109 |
print(f"Error generating response: {str(e)}")
|
| 110 |
yield "I apologize, but I encountered an error while generating the response. Please try again."
|
| 111 |
-
|
| 112 |
@app.route('/')
|
| 113 |
def index():
|
| 114 |
"""Serve the HTML page for the user interface"""
|
|
|
|
| 85 |
messages.append({"role": "user", "content": first_msg})
|
| 86 |
|
| 87 |
# Add conversation history ensuring alternating pattern (user, assistant, user, assistant...)
|
| 88 |
+
for user_msg, bot_msg in history:
|
| 89 |
+
if user_msg.strip(): # Check if user message is not empty
|
| 90 |
+
messages.append({"role": "user", "content": user_msg})
|
| 91 |
+
if bot_msg.strip(): # Check if assistant message is not empty
|
| 92 |
+
messages.append({"role": "assistant", "content": bot_msg})
|
|
|
|
|
|
|
| 93 |
|
| 94 |
try:
|
| 95 |
response = ""
|
|
|
|
| 106 |
except Exception as e:
|
| 107 |
print(f"Error generating response: {str(e)}")
|
| 108 |
yield "I apologize, but I encountered an error while generating the response. Please try again."
|
| 109 |
+
|
| 110 |
@app.route('/')
|
| 111 |
def index():
|
| 112 |
"""Serve the HTML page for the user interface"""
|