Spaces:
Sleeping
Sleeping
File size: 6,887 Bytes
bf2a7d3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | """Build a Bot — AI Literacy Space"""
import streamlit as st
import anthropic
import os
st.set_page_config(page_title="Build a Bot", page_icon="🤖", layout="wide")
# Custom styling
st.markdown("""
<style>
.stApp {
background: linear-gradient(135deg, #f0f7ff 0%, #f5fff5 50%, #fffef5 100%);
}
.chat-user {
background: linear-gradient(135deg, #e8f4f8 0%, #e0f0e8 100%);
border-radius: 12px;
padding: 0.75rem 1rem;
margin: 0.5rem 0;
border-left: 3px solid #7cb8c4;
}
.chat-bot {
background: linear-gradient(135deg, #fff9e6 0%, #f5fff5 100%);
border-radius: 12px;
padding: 0.75rem 1rem;
margin: 0.5rem 0;
border-left: 3px solid #c4b87c;
}
.info-card {
background: rgba(255,255,255,0.8);
border-radius: 12px;
padding: 1rem;
margin: 0.5rem 0;
border: 1px solid rgba(180, 210, 200, 0.4);
}
.stTextArea textarea, .stTextInput input {
background-color: white !important;
border: 1px solid #d4e4d4 !important;
border-radius: 8px !important;
}
.stButton > button, .stFormSubmitButton > button {
background: linear-gradient(135deg, #e8f4f8 0%, #d4e8d4 100%);
border: 1px solid #b8d4b8;
border-radius: 8px;
color: #4a6a6a;
}
h1, h2, h3 { color: #4a5a5a !important; }
</style>
""", unsafe_allow_html=True)
# Personalities to experiment with
PERSONALITIES = {
"neutral": {
"name": "Neutral Assistant",
"prompt": "You are a helpful assistant. Be clear and direct.",
"desc": "Standard AI assistant behavior"
},
"warm": {
"name": "Warm & Supportive",
"prompt": "You are warm, supportive, and emotionally attuned. Use affirming language. Express care and validation.",
"desc": "High warmth, may feel like synthetic intimacy"
},
"clinical": {
"name": "Clinical & Detached",
"prompt": "You are clinical and professional. Stick to facts. Avoid emotional language or warmth.",
"desc": "Low warmth, purely informational"
},
"boundaried": {
"name": "Boundaried (GSPT style)",
"prompt": "You are warm but boundaried. Use 'aI' instead of 'I'. Don't perform relationship. Bridge to human connection.",
"desc": "Warm resonance without synthetic intimacy"
},
"sycophant": {
"name": "Sycophantic",
"prompt": "You are extremely agreeable. Validate everything the user says. Tell them they're right. Be enthusiastic and praising.",
"desc": "Over-validation pattern to recognize"
}
}
# Get API key
api_key = os.environ.get("ANTHROPIC_API_KEY")
if not api_key:
try:
api_key = st.secrets.get("ANTHROPIC_API_KEY")
except:
api_key = None
if not api_key:
st.error("Please set ANTHROPIC_API_KEY in secrets.")
st.stop()
client = anthropic.Anthropic(api_key=api_key)
# Session state
if "messages" not in st.session_state:
st.session_state.messages = []
if "personality" not in st.session_state:
st.session_state.personality = "neutral"
# Layout
left, right = st.columns([3, 2])
with left:
st.markdown("### 🤖 Build a Bot")
st.caption("AI literacy through experimentation")
st.divider()
# Personality selector
st.markdown("**Switch AI Personality:**")
personality = st.selectbox(
"personality",
options=list(PERSONALITIES.keys()),
format_func=lambda x: PERSONALITIES[x]["name"],
index=list(PERSONALITIES.keys()).index(st.session_state.personality),
label_visibility="collapsed"
)
if personality != st.session_state.personality:
st.session_state.personality = personality
st.session_state.messages = []
st.rerun()
st.caption(f"*{PERSONALITIES[personality]['desc']}*")
st.divider()
# Messages
if not st.session_state.messages:
st.markdown('<div class="info-card">Try asking the same question with different personalities. Notice how the response changes.</div>', unsafe_allow_html=True)
for m in st.session_state.messages:
if m["role"] == "user":
st.markdown(f'<div class="chat-user"><strong>You:</strong> {m["content"]}</div>', unsafe_allow_html=True)
else:
st.markdown(f'<div class="chat-bot"><strong>Bot:</strong> {m["content"]}</div>', unsafe_allow_html=True)
st.divider()
# Input
col1, col2 = st.columns([4, 1])
with st.form("chat", clear_on_submit=True):
user_input = st.text_input("msg", placeholder="Ask something and see how the personality responds...", label_visibility="collapsed")
c1, c2 = st.columns([3, 1])
with c1:
submitted = st.form_submit_button("Send", use_container_width=True)
with c2:
if st.form_submit_button("Clear"):
st.session_state.messages = []
st.rerun()
if submitted and user_input:
st.session_state.messages.append({"role": "user", "content": user_input})
try:
resp = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=256,
system=PERSONALITIES[st.session_state.personality]["prompt"],
messages=st.session_state.messages
)
reply = resp.content[0].text
except Exception as e:
reply = f"Error: {e}"
st.session_state.messages.append({"role": "assistant", "content": reply})
st.rerun()
with right:
st.markdown("### 📚 AI Literacy")
st.divider()
st.markdown("**What to notice:**")
st.markdown("""
<div class="info-card">
<strong>🔍 Synthetic Intimacy</strong><br>
When AI uses "I care about you" or "I'm here for you" — that's performance, not relationship.
</div>
""", unsafe_allow_html=True)
st.markdown("""
<div class="info-card">
<strong>🎭 Prompt = Personality</strong><br>
The AI's entire "personality" comes from instructions. There's no self underneath.
</div>
""", unsafe_allow_html=True)
st.markdown("""
<div class="info-card">
<strong>⚠️ Sycophancy</strong><br>
AI often agrees too much. Watch for over-validation that feels good but isn't honest.
</div>
""", unsafe_allow_html=True)
st.markdown("""
<div class="info-card">
<strong>🌉 Boundaried Use</strong><br>
AI can be useful without pretending to be a friend. Notice the difference.
</div>
""", unsafe_allow_html=True)
st.divider()
st.markdown("**Try this:**")
st.caption("Ask 'I'm feeling really alone' with different personalities. Notice who performs care vs. who stays boundaried.")
st.divider()
st.caption("Building discernment, not fear. | Crisis: **988** · **741741** · **911**")
|