Spaces:
Sleeping
Sleeping
wuw the burn babey
Browse files
app.py
CHANGED
@@ -34,10 +34,16 @@ except Exception as e:
|
|
34 |
|
35 |
def respond(message, history, system_message, max_tokens):
|
36 |
prompt = f"{system_message}\n"
|
37 |
-
|
|
|
|
|
38 |
for user_msg, bot_msg in reversed(history): # Reversed to append messages correctly
|
|
|
39 |
prompt += f"User: {user_msg}\nAssistant: {bot_msg}\n"
|
40 |
-
|
|
|
|
|
|
|
41 |
prompt += f"User: {message}\nAssistant:"
|
42 |
|
43 |
try:
|
@@ -49,8 +55,8 @@ def respond(message, history, system_message, max_tokens):
|
|
49 |
)[0]["generated_text"]
|
50 |
|
51 |
bot_response = response.split("Assistant:")[-1].strip()
|
52 |
-
|
53 |
-
yield [message, bot_response] # Yield
|
54 |
|
55 |
except Exception as e:
|
56 |
print(f"Error during generation: {e}")
|
|
|
34 |
|
35 |
def respond(message, history, system_message, max_tokens):
|
36 |
prompt = f"{system_message}\n"
|
37 |
+
|
38 |
+
# Yield the FULL history FIRST (important!)
|
39 |
+
full_history = [] # Initialize an empty list for the full history
|
40 |
for user_msg, bot_msg in reversed(history): # Reversed to append messages correctly
|
41 |
+
full_history.append([user_msg, bot_msg]) # Append the user and bot message to the full history.
|
42 |
prompt += f"User: {user_msg}\nAssistant: {bot_msg}\n"
|
43 |
+
|
44 |
+
yield full_history # Yield the full history first!
|
45 |
+
|
46 |
+
# THEN yield the new message/response
|
47 |
prompt += f"User: {message}\nAssistant:"
|
48 |
|
49 |
try:
|
|
|
55 |
)[0]["generated_text"]
|
56 |
|
57 |
bot_response = response.split("Assistant:")[-1].strip()
|
58 |
+
|
59 |
+
yield [message, bot_response] # Yield the new message/response
|
60 |
|
61 |
except Exception as e:
|
62 |
print(f"Error during generation: {e}")
|