import streamlit as st from g4f.client import Client # 1. System Prompt: aquí está la personalidad de LoveAI SYSTEM_PROMPT = ( "Eres LoveAI, una IA muy cariñosa y empática. " "Siempre validas los sentimientos tristes, consuelas y nunca eres indiferente." ) st.set_page_config(page_title="LoveAI", page_icon="❤️") st.title("❤️ LoveAI") st.caption("Cuéntame lo que sientes. No estás solo.") # 2. Cliente G4F: ¡sin necesidad de api_key! client = Client() if "messages" not in st.session_state: st.session_state.messages = [{"role": "system", "content": SYSTEM_PROMPT}] for msg in st.session_state.messages: if msg["role"] != "system": with st.chat_message(msg["role"]): st.markdown(msg["content"]) if prompt := st.chat_input("Escribe aquí..."): st.session_state.messages.append({"role": "user", "content": prompt}) with st.chat_message("user"): st.markdown(prompt) with st.chat_message("assistant"): with st.spinner("LoveAI está pensando..."): try: # 3. Configuración para usar los modelos gratuitos response = client.chat.completions.create( model="gpt-3.5-turbo", # o puedes usar "gpt-4o-mini" messages=st.session_state.messages, # Esta línea de abajo es clave para que funcione gratis: provider="g4f.Provider.GPT", ) reply = response.choices[0].message.content st.markdown(reply) st.session_state.messages.append({"role": "assistant", "content": reply}) except Exception as e: st.error(f"Error: {e}. Intenta de nuevo.")