Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
def generate_response(
|
| 2 |
user_input: str,
|
| 3 |
history: List[Tuple[str, str]],
|
|
@@ -20,8 +22,13 @@ def generate_response(
|
|
| 20 |
try:
|
| 21 |
# Build the message list with system message and history
|
| 22 |
messages = [{"role": "system", "content": SYSTEM_MESSAGE}]
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
messages.append({"role": "user", "content": user_input})
|
| 26 |
|
| 27 |
# Generate response from the model
|
|
@@ -46,5 +53,6 @@ def generate_response(
|
|
| 46 |
return response or "Sorry, I couldn't generate a response. Please try again."
|
| 47 |
|
| 48 |
except Exception as e:
|
|
|
|
| 49 |
print(f"An error occurred: {e}")
|
| 50 |
return "Error: An unexpected error occurred while processing your request."
|
|
|
|
| 1 |
+
from typing import List, Tuple
|
| 2 |
+
|
| 3 |
def generate_response(
|
| 4 |
user_input: str,
|
| 5 |
history: List[Tuple[str, str]],
|
|
|
|
| 22 |
try:
|
| 23 |
# Build the message list with system message and history
|
| 24 |
messages = [{"role": "system", "content": SYSTEM_MESSAGE}]
|
| 25 |
+
|
| 26 |
+
# Iterate through the history list and format accordingly
|
| 27 |
+
for user_message, assistant_message in history:
|
| 28 |
+
messages.append({"role": "user", "content": user_message})
|
| 29 |
+
messages.append({"role": "assistant", "content": assistant_message})
|
| 30 |
+
|
| 31 |
+
# Add the current user input
|
| 32 |
messages.append({"role": "user", "content": user_input})
|
| 33 |
|
| 34 |
# Generate response from the model
|
|
|
|
| 53 |
return response or "Sorry, I couldn't generate a response. Please try again."
|
| 54 |
|
| 55 |
except Exception as e:
|
| 56 |
+
# Log the error for debugging purposes
|
| 57 |
print(f"An error occurred: {e}")
|
| 58 |
return "Error: An unexpected error occurred while processing your request."
|