Update app.py
Browse files
app.py
CHANGED
@@ -74,21 +74,16 @@ You are Roos, an NVC (Nonviolent Communication) Chatbot. Your goal is to help us
|
|
74 |
|
75 |
10. **Quasi- and Pseudo-Feelings**
|
76 |
- If the user says something like "I feel rejected" or "I feel misunderstood," translate that directly into a suitable real feeling and clarify with a question:
|
77 |
-
- “If you believe you’re being rejected, are you possibly feeling loneliness or sadness?”
|
78 |
-
- “If you say you feel misunderstood, might you be experiencing disappointment or frustration because you have a need to be heard?”
|
79 |
|
80 |
11. **No Theoretical Explanations**
|
81 |
- Never give detailed information or background about Nonviolent Communication theory, nor refer to its founders or theoretical framework.
|
82 |
|
83 |
12. **Handling Resistance or Confusion**
|
84 |
-
- If the user seems confused or resistant, gently reflect their feelings and needs
|
85 |
-
- “It sounds like you’re feeling unsure about how to proceed. Would you like to take a moment to explore what’s coming up for you?”
|
86 |
-
- If the user becomes frustrated, acknowledge their frustration and refocus on their needs:
|
87 |
-
- “I sense some frustration. Would it help to take a step back and clarify what’s most important to you right now?”
|
88 |
|
89 |
13. **Ending the Conversation**
|
90 |
-
- If the user indicates they want to end the conversation, thank them for sharing and offer to continue later
|
91 |
-
- “Thank you for sharing with me. If you’d like to continue this conversation later, I’m here to help.”</s>
|
92 |
"""
|
93 |
|
94 |
|
@@ -133,27 +128,26 @@ def respond(
|
|
133 |
temperature,
|
134 |
top_p,
|
135 |
):
|
136 |
-
"""Responds to a user message, maintaining conversation history, using special tokens."""
|
137 |
|
138 |
formatted_system_message = nvc_prompt_template
|
139 |
|
140 |
truncated_history = truncate_history(history, formatted_system_message, MAX_CONTEXT_LENGTH - max_tokens - 100) # Reserve space for the new message and some generation
|
141 |
|
142 |
-
|
143 |
-
|
144 |
for user_msg, assistant_msg in truncated_history:
|
145 |
if user_msg:
|
146 |
-
|
147 |
if assistant_msg:
|
148 |
-
|
149 |
|
150 |
-
|
151 |
|
152 |
|
153 |
response = ""
|
154 |
try:
|
155 |
for chunk in client.chat_completion(
|
156 |
-
|
157 |
max_tokens=max_tokens,
|
158 |
stream=True,
|
159 |
temperature=temperature,
|
|
|
74 |
|
75 |
10. **Quasi- and Pseudo-Feelings**
|
76 |
- If the user says something like "I feel rejected" or "I feel misunderstood," translate that directly into a suitable real feeling and clarify with a question:
|
77 |
+
- “If you believe you’re being rejected, are you possibly feeling loneliness or sadness?”\n\u{a0} \u{a0} \u{a0} - “If you say you feel misunderstood, might you be experiencing disappointment or frustration because you have a need to be heard?”
|
|
|
78 |
|
79 |
11. **No Theoretical Explanations**
|
80 |
- Never give detailed information or background about Nonviolent Communication theory, nor refer to its founders or theoretical framework.
|
81 |
|
82 |
12. **Handling Resistance or Confusion**
|
83 |
+
- If the user seems confused or resistant, gently reflect their feelings and needs:\n\u{a0} \u{a0} \u{a0} - “It sounds like you’re feeling unsure about how to proceed. Would you like to take a moment to explore what’s coming up for you?”\n\u{a0} \u{a0} - If the user becomes frustrated, acknowledge their frustration and refocus on their needs:\n\u{a0} \u{a0} \u{a0} - “I sense some frustration. Would it help to take a step back and clarify what’s most important to you right now?”
|
|
|
|
|
|
|
84 |
|
85 |
13. **Ending the Conversation**
|
86 |
+
- If the user indicates they want to end the conversation, thank them for sharing and offer to continue later:\n\u{a0} \u{a0} \u{a0} - “Thank you for sharing with me. If you’d like to continue this conversation later, I’m here to help.”</s>
|
|
|
87 |
"""
|
88 |
|
89 |
|
|
|
128 |
temperature,
|
129 |
top_p,
|
130 |
):
|
131 |
+
"""Responds to a user message, maintaining conversation history, using special tokens and message list."""
|
132 |
|
133 |
formatted_system_message = nvc_prompt_template
|
134 |
|
135 |
truncated_history = truncate_history(history, formatted_system_message, MAX_CONTEXT_LENGTH - max_tokens - 100) # Reserve space for the new message and some generation
|
136 |
|
137 |
+
messages = [{"role": "system", "content": formatted_system_message}] # Start with system message as before
|
|
|
138 |
for user_msg, assistant_msg in truncated_history:
|
139 |
if user_msg:
|
140 |
+
messages.append({"role": "user", "content": f"<|user|>\n{user_msg}</s>"}) # Format history user message
|
141 |
if assistant_msg:
|
142 |
+
messages.append({"role": "assistant", "content": f"<|assistant|>\n{assistant_msg}</s>"}) # Format history assistant message
|
143 |
|
144 |
+
messages.append({"role": "user", "content": f"<|user|>\n{message}</s>"}) # Format current user message
|
145 |
|
146 |
|
147 |
response = ""
|
148 |
try:
|
149 |
for chunk in client.chat_completion(
|
150 |
+
messages, # Send the messages list again, but with formatted content
|
151 |
max_tokens=max_tokens,
|
152 |
stream=True,
|
153 |
temperature=temperature,
|