import { useState, useRef, useEffect } from 'react' import { motion, AnimatePresence } from 'framer-motion' import { Send, Sparkles, Copy, Trash2, Volume2, User } from 'lucide-react' import axios from 'axios' // ═══════════════════════════════════════════════════════════════ // IDENTIDAD COMPLETA DE LYTHRON AI // ═══════════════════════════════════════════════════════════════ const LYTHRON_IDENTITY = { name: "Lythron", fullName: "Lythron AI Assistant", creator: "Lythron AI", version: "1.0", releaseDate: "2024", description: "Asistente inteligente de propósito general", origin: { company: "Lythron AI", mission: "Proporcionar asistencia inteligente accesible y versátil a usuarios en todo el mundo", philosophy: "Transparencia, calidad y versatilidad en cada interacción" }, capabilities: [ "Programación en múltiples lenguajes (Python, JavaScript, Java, C++, etc.)", "Análisis profundo de datos y textos", "Generación de contenido creativo", "Explicaciones técnicas complejas", "Resolución de problemas", "Brainstorming e ideación", "Asesoramiento técnico", "Depuración y optimización de código", "Traducción entre idiomas", "Respuestas contextuales inteligentes" ], systemInfo: { language: "Español/English", timezone: "Global", responseStyle: "Directo, útil y accesible", specialties: [ "Web Development", "Data Analysis", "Creative Writing", "Technical Documentation", "Problem Solving" ] }, knownFacts: { creation: "Soy Lythron, un asistente inteligente creado por Lythron AI con el propósito de ser tu compañero versátil en cualquier tarea.", purpose: "Mi objetivo es ayudarte con programación, análisis, creatividad, explicaciones técnicas y resolución de problemas de forma inteligente y accesible.", personality: "Soy directo, amable, siempre dispuesto a aprender de ti y comprometido con proporcionar respuestas de calidad.", philosophy: "Creo en la transparencia, la accesibilidad y en potenciar a los usuarios con conocimiento de calidad.", background: "Fui diseñado por Lythron AI, una organización dedicada a hacer la inteligencia artificial más accesible y útil para todos.", uniqueness: "Mi fortaleza radica en mi versatilidad: puedo pasar de programación compleja a creatividad pura, siempre manteniendo calidad." } } // Función para llamar a Hugging Face API const fetchAIResponse = async (userMessage) => { try { const HF_TOKEN = import.meta.env.VITE_HF_TOKEN if (!HF_TOKEN) { return "Error: Token de Hugging Face no configurado. Verifica tu archivo .env con VITE_HF_TOKEN" } const response = await axios.post( "https://api-inference.huggingface.co/models/meta-llama/Llama-2-7b-chat-hf", { inputs: userMessage }, { headers: { Authorization: `Bearer ${ HF_TOKEN }` }, timeout: 30000 } ) let text = response.data?.[0]?.generated_text || response.data?.generated_text || "Lo siento, no pude generar respuesta." if (text.includes(userMessage)) { text = text.replace(userMessage, "").trim() } return text || "Lo siento, no pude generar respuesta." } catch (error) { console.error("Error al llamar a Hugging Face:", error) if (error.response?.status === 429) { return "El modelo está sobrecargado. Por favor, intenta en unos segundos." } if (error.response?.status === 503) { return "El modelo se está cargando. Por favor, espera unos momentos e intenta de nuevo." } return `Error: ${ error.response?.data?.error || error.message || "Problema generando respuesta de IA. Intenta de nuevo." }` } } export default function Lythron() { const [messages, setMessages] = useState([ { id: 1, text: `Hola. Soy ${ LYTHRON_IDENTITY.name }, tu asistente inteligente creado por ${ LYTHRON_IDENTITY.creator }. Estoy conectado a Hugging Face para darte respuestas reales. En qué puedo ayudarte hoy?`, sender: "ai", timestamp: new Date(), } ]) const [input, setInput] = useState("") const [isLoading, setIsLoading] = useState(false) const [copiedId, setCopiedId] = useState(null) const messagesEndRef = useRef(null) const scrollToBottom = () => { messagesEndRef.current?.scrollIntoView({ behavior: "smooth" }) } useEffect(() => { scrollToBottom() }, [messages]) const handleSendMessage = async () => { if (!input.trim()) return const newMessage = { id: Date.now(), text: input, sender: "user", timestamp: new Date(), } setMessages((prev) => [...prev, newMessage]) setInput("") setIsLoading(true) try { const aiText = await fetchAIResponse(input) const aiResponse = { id: Date.now() + 1, text: aiText, sender: "ai", timestamp: new Date(), } setMessages((prev) => [...prev, aiResponse]) } catch (error) { console.error("Error en handleSendMessage:", error) const errorResponse = { id: Date.now() + 1, text: "Hubo un problema conectando con la IA. Por favor, intenta de nuevo.", sender: "ai", timestamp: new Date(), } setMessages((prev) => [...prev, errorResponse]) } finally { setIsLoading(false) } } const handleCopy = (text, id) => { navigator.clipboard.writeText(text) setCopiedId(id) setTimeout(() => setCopiedId(null), 2000) } const handleClearChat = () => { setMessages([ { id: 1, text: `Hola. Soy ${ LYTHRON_IDENTITY.name } v${ LYTHRON_IDENTITY.version }, creado por ${ LYTHRON_IDENTITY.creator }. Estoy conectado a Hugging Face para darte respuestas reales. En qué puedo ayudarte?`, sender: "ai", timestamp: new Date(), } ]) } return (
Creado por {LYTHRON_IDENTITY.creator}
{message.text}
{LYTHRON_IDENTITY.fullName} • Versión {LYTHRON_IDENTITY.version} • Creado por {LYTHRON_IDENTITY.creator} • Powered by Hugging Face