import React, { useState, useRef, useEffect } from 'react'; import { getRoboticsChatResponse } from '../services/geminiService'; import { Message } from '../types'; import { BrainIcon } from './SVGIcons'; const ChatBot: React.FC = () => { const [messages, setMessages] = useState([]); const [input, setInput] = useState(''); const [isLoading, setIsLoading] = useState(false); const scrollRef = useRef(null); useEffect(() => { if (scrollRef.current) { scrollRef.current.scrollTop = scrollRef.current.scrollHeight; } }, [messages, isLoading]); const handleSend = async () => { if (!input.trim() || isLoading) return; const userMsg: Message = { role: 'user', text: input }; setMessages(prev => [...prev, userMsg]); setInput(''); setIsLoading(true); const botResponse = await getRoboticsChatResponse(messages, input); setMessages(prev => [...prev, { role: 'model', text: botResponse }]); setIsLoading(false); }; return (

机器人专家助手

由 CodingRoom AI 驱动

{messages.length === 0 && (
"你可以问我关于 ROS2、逆运动学,或者如何为你的下一个机器人编程。"
)} {messages.map((msg, i) => (
{msg.text}
))} {isLoading && (
)}
setInput(e.target.value)} onKeyPress={(e) => e.key === 'Enter' && handleSend()} placeholder="输入你的机器人技术问题..." className="flex-1 bg-slate-800 border border-slate-700 rounded-lg px-4 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 text-white" />
); }; export default ChatBot;