this is tsx for astro shadcnui: // src/components/VoiceAssistant.tsx import React, {…
- User
this is tsx for astro shadcnui: // src/components/VoiceAssistant.tsx import React, { useState, useRef, useEffect } from "react"; import { CardFooter, CardDescription, CardContent, CardHeader, Card, } from "./ui/card"; import { Button } from "./ui/button"; import { Input } from "./ui/input"; import { PlayIcon, CircleStop, MessageCircle, XIcon } from "lucide-react"; import * as THREE from "three"; import { motion, AnimatePresence } from "framer-motion";
const api = "http://localhost:5000"; // Update this if deploying const bgcolor = new THREE.Color().setHex(0x11161f); const visualcolor = new THREE.Color().setHex(0x1d92c4);
const VoiceAssistant: React.FC = () => { const [chatVisible, setChatVisible] = useState(false); const [isListening, setIsListening] = useState(false); const [isThinking, setIsThinking] = useState(false); const [isTalking, setIsTalking] = useState(false); const [messages, setMessages] = useState<{ user: string; bot: string }[]>([]); const [input, setInput] = useState(""); const audioRef = useRef(null); const [analyser, setAnalyser] = useState<THREE.AudioAnalyser | null>(null); const visualizerRef = useRef(null);
const sceneRef = useRef<THREE.Scene | null>(null); const cameraRef = useRef<THREE.PerspectiveCamera | null>(null); const rendererRef = useRef<THREE.WebGLRenderer | null>(null); const sphereRef = useRef<THREE.Mesh | null>(null); const particlesRef = useRef<THREE.Points | null>(null);
const isThinkingRef = useRef(isThinking); const isTalkingRef = useRef(isTalking);
const recognitionRef = useRef<SpeechRecognition | null>(null);
const toggleChat = () => setChatVisible(!chatVisible);
// Handle sending a message to the chat API const handleSendMessage = async (message: string) => { if (!message.trim()) return;
codesetIsThinking(true); // Start thinking animation try { const response = await fetch(`${api}/chat`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ message }), }); const data = await response.json(); const botResponse = data.response; setMessages((prev) => [...prev, { user: message, bot: botResponse }]); setInput(""); await playBotResponse(botResponse); } catch (error) { console.error("Error fetching chat response:", error); } finally { setIsThinking(false); // Stop thinking animation } - Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.