Spaces:
Runtime error
Runtime error
Commit ·
945fbe1
1
Parent(s): d678c9d
updated emotional logic
Browse files
app.py
CHANGED
|
@@ -138,13 +138,10 @@ def chat(input_text):
|
|
| 138 |
# Limit the size of the conversation history
|
| 139 |
conversation_history = truncate_history(conversation_history, max_tokens=1024)
|
| 140 |
|
| 141 |
-
#
|
| 142 |
-
previous_emotion = current_emotion
|
| 143 |
-
current_emotion = analyze_history(conversation_history)
|
| 144 |
-
|
| 145 |
-
# Combine base prompt and conversation history
|
| 146 |
history = "\n".join(conversation_history)
|
| 147 |
final_prompt = f"""{base_prompt}
|
|
|
|
| 148 |
### Instructions ###
|
| 149 |
Respond concisely and directly to the user's input. Avoid repeating the user's input unless clarification is needed.
|
| 150 |
|
|
@@ -159,7 +156,16 @@ Rena:"""
|
|
| 159 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 160 |
|
| 161 |
# Remove artifacts and repeated user input
|
| 162 |
-
artifacts = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
for artifact in artifacts:
|
| 164 |
response = response.replace(artifact, "").strip()
|
| 165 |
|
|
@@ -169,13 +175,9 @@ Rena:"""
|
|
| 169 |
# Add emotional context only if the emotion changes significantly
|
| 170 |
if current_emotion != previous_emotion:
|
| 171 |
emotional_prefix = emotions.get(current_emotion, "")
|
| 172 |
-
if emotional_prefix and not response.startswith(emotional_prefix)
|
| 173 |
response = f"{emotional_prefix} {response}".strip()
|
| 174 |
|
| 175 |
-
# Clean up "User:" if it appears in the response
|
| 176 |
-
if response.startswith("User:"):
|
| 177 |
-
response = response.replace("User:", "").strip()
|
| 178 |
-
|
| 179 |
# Add Rena's response to the conversation history
|
| 180 |
conversation_history.append(f"Rena: {response}")
|
| 181 |
|
|
@@ -212,6 +214,7 @@ Rena:"""
|
|
| 212 |
|
| 213 |
|
| 214 |
|
|
|
|
| 215 |
# Custom CSS for avatar styling
|
| 216 |
css = """
|
| 217 |
#rena_avatar img {
|
|
|
|
| 138 |
# Limit the size of the conversation history
|
| 139 |
conversation_history = truncate_history(conversation_history, max_tokens=1024)
|
| 140 |
|
| 141 |
+
# Combine base prompt and conversation history (instructions are not included in history)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
history = "\n".join(conversation_history)
|
| 143 |
final_prompt = f"""{base_prompt}
|
| 144 |
+
|
| 145 |
### Instructions ###
|
| 146 |
Respond concisely and directly to the user's input. Avoid repeating the user's input unless clarification is needed.
|
| 147 |
|
|
|
|
| 156 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 157 |
|
| 158 |
# Remove artifacts and repeated user input
|
| 159 |
+
artifacts = [
|
| 160 |
+
base_prompt,
|
| 161 |
+
"### Conversation History ###",
|
| 162 |
+
"Rena:",
|
| 163 |
+
"Assistant:",
|
| 164 |
+
"<|assistant|>",
|
| 165 |
+
"<|user|>",
|
| 166 |
+
"### Instructions ###",
|
| 167 |
+
"Respond concisely and directly to the user's input. Avoid repeating the user's input unless clarification is needed."
|
| 168 |
+
]
|
| 169 |
for artifact in artifacts:
|
| 170 |
response = response.replace(artifact, "").strip()
|
| 171 |
|
|
|
|
| 175 |
# Add emotional context only if the emotion changes significantly
|
| 176 |
if current_emotion != previous_emotion:
|
| 177 |
emotional_prefix = emotions.get(current_emotion, "")
|
| 178 |
+
if emotional_prefix and not response.startswith(emotional_prefix):
|
| 179 |
response = f"{emotional_prefix} {response}".strip()
|
| 180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
# Add Rena's response to the conversation history
|
| 182 |
conversation_history.append(f"Rena: {response}")
|
| 183 |
|
|
|
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
+
|
| 218 |
# Custom CSS for avatar styling
|
| 219 |
css = """
|
| 220 |
#rena_avatar img {
|