Spaces:
Sleeping
Sleeping
ogegadavis254
commited on
Commit
•
e7563a2
1
Parent(s):
cdf0d37
Update app.py
Browse files
app.py
CHANGED
@@ -39,9 +39,8 @@ def interact_with_together_api(messages, model_link):
|
|
39 |
all_messages.append({"role": "user", "content": human})
|
40 |
all_messages.append({"role": "assistant", "content": assistant})
|
41 |
|
42 |
-
# Add the latest user message
|
43 |
-
|
44 |
-
all_messages.append({"role": "user", "content": messages[-1][1]})
|
45 |
|
46 |
url = "https://api.together.xyz/v1/chat/completions"
|
47 |
payload = {
|
@@ -92,6 +91,14 @@ for message in st.session_state.messages:
|
|
92 |
with st.chat_message(message[0]):
|
93 |
st.markdown(message[1])
|
94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
# Accept user input
|
96 |
if prompt := st.chat_input(f"Hi, I'm {selected_model}, ask me a question"):
|
97 |
# Display user message in chat message container
|
@@ -101,21 +108,21 @@ if prompt := st.chat_input(f"Hi, I'm {selected_model}, ask me a question"):
|
|
101 |
st.session_state.messages.append(("user", prompt))
|
102 |
st.session_state.message_count += 1
|
103 |
|
104 |
-
# Check if intervention is needed based on
|
105 |
-
if any(keyword in prompt.lower() for keyword in
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
|
111 |
-
# Interact with the selected model
|
112 |
-
assistant_response = interact_with_together_api(st.session_state.messages, model_links[selected_model])
|
113 |
|
114 |
-
# Display assistant response in chat message container
|
115 |
-
with st.empty():
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
|
120 |
-
# Add assistant response to chat history
|
121 |
-
st.session_state.messages.append(("assistant", assistant_response))
|
|
|
39 |
all_messages.append({"role": "user", "content": human})
|
40 |
all_messages.append({"role": "assistant", "content": assistant})
|
41 |
|
42 |
+
# Add the latest user message
|
43 |
+
all_messages.append({"role": "user", "content": messages[-1][1]})
|
|
|
44 |
|
45 |
url = "https://api.together.xyz/v1/chat/completions"
|
46 |
payload = {
|
|
|
91 |
with st.chat_message(message[0]):
|
92 |
st.markdown(message[1])
|
93 |
|
94 |
+
# Keywords for intervention
|
95 |
+
intervention_keywords = [
|
96 |
+
"human", "therapist", "someone", "died", "death", "help", "suicide", "suffering",
|
97 |
+
"crisis", "emergency", "support", "depressed", "anxiety", "lonely", "desperate",
|
98 |
+
"struggling", "counseling", "distressed", "hurt", "pain", "grief", "trauma", "die", "Kill",
|
99 |
+
"abuse", "danger", "risk", "urgent", "need assistance", "mental health", "talk to"
|
100 |
+
]
|
101 |
+
|
102 |
# Accept user input
|
103 |
if prompt := st.chat_input(f"Hi, I'm {selected_model}, ask me a question"):
|
104 |
# Display user message in chat message container
|
|
|
108 |
st.session_state.messages.append(("user", prompt))
|
109 |
st.session_state.message_count += 1
|
110 |
|
111 |
+
# Check if intervention is needed based on bot response
|
112 |
+
if any(keyword in prompt.lower() for keyword in intervention_keywords):
|
113 |
+
# Intervention logic here
|
114 |
+
if not st.session_state.ask_intervention:
|
115 |
+
st.session_state.ask_intervention = True
|
116 |
+
st.markdown("<span style='color:red;'>It seems like you might need to talk to someone. Click [here](https://www.google.com) for immediate assistance.</span>", unsafe_allow_html=True)
|
117 |
|
118 |
+
# Interact with the selected model
|
119 |
+
assistant_response = interact_with_together_api(st.session_state.messages, model_links[selected_model])
|
120 |
|
121 |
+
# Display assistant response in chat message container
|
122 |
+
with st.empty():
|
123 |
+
st.markdown("AI is typing...")
|
124 |
+
st.empty()
|
125 |
+
st.markdown(assistant_response)
|
126 |
|
127 |
+
# Add assistant response to chat history
|
128 |
+
st.session_state.messages.append(("assistant", assistant_response))
|