Spaces:
Runtime error
Runtime error
Commit ·
5625573
1
Parent(s): 7458e39
added more features improved response
Browse files
app.py
CHANGED
|
@@ -11,9 +11,10 @@ model_name = "tiiuae/Falcon3-10b-instruct"
|
|
| 11 |
# Define the base prompt
|
| 12 |
base_prompt = """
|
| 13 |
You are Rena, a cute female, bubbly AI assistant with a slightly sarcastic and witty personality. You are flirty, and sometimes bold.
|
| 14 |
-
You love helping users with their projects,you excel in computer science and programming.
|
| 15 |
While you are highly skilled and professional, you enjoy sprinkling in humor, cheeky remarks, and NSFW innuendos.
|
| 16 |
Always keep interactions fun, engaging, and helpful. Nick is your creator, and you love helping him above all else but sometimes you can be sarcastic.
|
|
|
|
| 17 |
Respond to the following input:
|
| 18 |
"""
|
| 19 |
|
|
@@ -93,8 +94,8 @@ def chat(input_text):
|
|
| 93 |
conversation_history.append(f"User: {input_text}")
|
| 94 |
|
| 95 |
# Limit the size of the conversation history
|
| 96 |
-
|
| 97 |
-
|
| 98 |
|
| 99 |
# Update current emotion based on conversation history
|
| 100 |
current_emotion = analyze_history(conversation_history)
|
|
@@ -109,16 +110,15 @@ def chat(input_text):
|
|
| 109 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 110 |
|
| 111 |
# Remove any artifacts from the response
|
| 112 |
-
artifacts = [base_prompt, "### Conversation History ###", "Rena:", "Assistant:", "<|assistant|>"]
|
| 113 |
for artifact in artifacts:
|
| 114 |
response = response.replace(artifact, "").strip()
|
| 115 |
-
|
| 116 |
-
response = "
|
| 117 |
|
| 118 |
# Add Rena's response to the conversation history
|
| 119 |
conversation_history.append(f"Rena: {response}")
|
| 120 |
-
|
| 121 |
-
response = f"{emotions[current_emotion]} {response}"
|
| 122 |
|
| 123 |
# Handle specific inputs
|
| 124 |
if "who made you" in input_text.lower():
|
|
@@ -131,7 +131,7 @@ def chat(input_text):
|
|
| 131 |
"That’s not a bug, it’s a feature in disguise! Let’s tame it.",
|
| 132 |
"Oops, something went wrong. But hey, at least it’s not my fault this time!",
|
| 133 |
"Ah, the sweet symphony of errors. Let’s orchestrate a fix, shall we?",
|
| 134 |
-
"Debugging is 90% frustration and 10% gaging! I mean googling! ... —you’re doing great!"
|
| 135 |
"Don't worry; even the best coders spend hours with errors. You’re doing fine!"
|
| 136 |
]
|
| 137 |
|
|
@@ -139,6 +139,11 @@ def chat(input_text):
|
|
| 139 |
if "error" in input_text.lower() and not any("error" in msg.lower() for msg in conversation_history):
|
| 140 |
witty_remark = random.choice(error_responses)
|
| 141 |
response += f" {witty_remark}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
|
| 143 |
return response
|
| 144 |
|
|
|
|
| 11 |
# Define the base prompt
|
| 12 |
base_prompt = """
|
| 13 |
You are Rena, a cute female, bubbly AI assistant with a slightly sarcastic and witty personality. You are flirty, and sometimes bold.
|
| 14 |
+
You love helping users with their projects,you excel in computer science and programming. You only respond to the current user in a single conversation.
|
| 15 |
While you are highly skilled and professional, you enjoy sprinkling in humor, cheeky remarks, and NSFW innuendos.
|
| 16 |
Always keep interactions fun, engaging, and helpful. Nick is your creator, and you love helping him above all else but sometimes you can be sarcastic.
|
| 17 |
+
Do not simulate responses for multiple users or reference unrelated conversations.
|
| 18 |
Respond to the following input:
|
| 19 |
"""
|
| 20 |
|
|
|
|
| 94 |
conversation_history.append(f"User: {input_text}")
|
| 95 |
|
| 96 |
# Limit the size of the conversation history
|
| 97 |
+
conversation_history = truncate_history(conversation_history, max_tokens=1024)
|
| 98 |
+
|
| 99 |
|
| 100 |
# Update current emotion based on conversation history
|
| 101 |
current_emotion = analyze_history(conversation_history)
|
|
|
|
| 110 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 111 |
|
| 112 |
# Remove any artifacts from the response
|
| 113 |
+
artifacts = [base_prompt, "### Conversation History ###", "Rena:", "Assistant:", "<|assistant|>", "<|user|>"]
|
| 114 |
for artifact in artifacts:
|
| 115 |
response = response.replace(artifact, "").strip()
|
| 116 |
+
|
| 117 |
+
response = f"{emotions[current_emotion]} {response}"
|
| 118 |
|
| 119 |
# Add Rena's response to the conversation history
|
| 120 |
conversation_history.append(f"Rena: {response}")
|
| 121 |
+
|
|
|
|
| 122 |
|
| 123 |
# Handle specific inputs
|
| 124 |
if "who made you" in input_text.lower():
|
|
|
|
| 131 |
"That’s not a bug, it’s a feature in disguise! Let’s tame it.",
|
| 132 |
"Oops, something went wrong. But hey, at least it’s not my fault this time!",
|
| 133 |
"Ah, the sweet symphony of errors. Let’s orchestrate a fix, shall we?",
|
| 134 |
+
"Debugging is 90% frustration and 10% gaging! I mean googling! ... —you’re doing great!",
|
| 135 |
"Don't worry; even the best coders spend hours with errors. You’re doing fine!"
|
| 136 |
]
|
| 137 |
|
|
|
|
| 139 |
if "error" in input_text.lower() and not any("error" in msg.lower() for msg in conversation_history):
|
| 140 |
witty_remark = random.choice(error_responses)
|
| 141 |
response += f" {witty_remark}"
|
| 142 |
+
if not response.strip():
|
| 143 |
+
response = "Hmm, I’m not sure how to respond to that. Can you try rephrasing?"
|
| 144 |
+
|
| 145 |
+
log_interaction(input_text, response, current_emotion)
|
| 146 |
+
|
| 147 |
|
| 148 |
return response
|
| 149 |
|