From 891a09e667e6be2fe9e9f73421cf31a0d202289e Mon Sep 17 00:00:00 2001 From: Color2333 <1552429809@qq.com> Date: Thu, 19 Mar 2026 17:51:14 +0800 Subject: [PATCH 1/4] =?UTF-8?q?chore:=20=E5=88=A0=E9=99=A4=E5=AD=A4?= =?UTF-8?q?=E7=AB=8B=E7=9A=84=20Chat.tsx=20=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/Chat.tsx | 254 ------------------------------------ 1 file changed, 254 deletions(-) delete mode 100644 frontend/src/pages/Chat.tsx diff --git a/frontend/src/pages/Chat.tsx b/frontend/src/pages/Chat.tsx deleted file mode 100644 index 8b4cbc9..0000000 --- a/frontend/src/pages/Chat.tsx +++ /dev/null @@ -1,254 +0,0 @@ -/** - * AI Chat - RAG 问答 (Claude 对话风格) - * 覆盖 API: POST /rag/ask - * @author Color2333 - */ -import { useState, useRef, useEffect } from "react"; -import { Card, Button } from "@/components/ui"; -import { ragApi } from "@/services/api"; -import type { ChatMessage } from "@/types"; -import { uid } from "@/lib/utils"; -import { Send, Sparkles, User, BookOpen, Trash2 } from "lucide-react"; - -export default function Chat() { - const [messages, setMessages] = useState([]); - const [input, setInput] = useState(""); - const [loading, setLoading] = useState(false); - const scrollRef = useRef(null); - const inputRef = useRef(null); - - useEffect(() => { - if (scrollRef.current) { - scrollRef.current.scrollTop = scrollRef.current.scrollHeight; - } - }, [messages]); - - const handleSend = async () => { - const question = input.trim(); - if (!question || loading) return; - - const userMsg: ChatMessage = { - id: uid(), - role: "user", - content: question, - timestamp: new Date(), - }; - setMessages((prev) => [...prev, userMsg]); - setInput(""); - setLoading(true); - - try { - const res = await ragApi.ask({ question, top_k: 5 }); - const botMsg: ChatMessage = { - id: uid(), - role: "assistant", - content: res.answer, - cited_paper_ids: res.cited_paper_ids, - evidence: res.evidence, - timestamp: new Date(), - }; - setMessages((prev) => [...prev, botMsg]); - } catch (err) { - const errorMsg: ChatMessage = { - id: uid(), - role: "assistant", - content: `抱歉,查询时出现错误: ${err instanceof Error ? err.message : "未知错误"}`, - timestamp: new Date(), - }; - setMessages((prev) => [...prev, errorMsg]); - } finally { - setLoading(false); - inputRef.current?.focus(); - } - }; - - const handleKeyDown = (e: React.KeyboardEvent) => { - if (e.key === "Enter" && !e.shiftKey) { - e.preventDefault(); - handleSend(); - } - }; - - const clearChat = () => { - setMessages([]); - }; - - return ( -
- {/* 标题栏 */} -
-
-

AI Chat

-

基于 RAG 的跨论文智能问答

-
- {messages.length > 0 && ( - - )} -
- - {/* 消息区域 */} -
- {messages.length === 0 ? ( -
-
- -
-

PaperMind AI

-

- 基于你收录的论文进行智能问答。 支持跨文档检索,自动引用来源论文。 -

-
- {[ - "这些论文中关于 Transformer 的主要创新是什么?", - "有哪些论文讨论了模型压缩的方法?", - "总结一下近期在多模态学习方面的进展", - ].map((q) => ( - - ))} -
-
- ) : ( - messages.map((msg) => ( -
- {msg.role === "assistant" && ( -
- -
- )} -
- {msg.role === "user" ? ( -

{msg.content}

- ) : ( - <> -
-

- {msg.content} -

-
- {/* 引用论文 */} - {msg.cited_paper_ids && msg.cited_paper_ids.length > 0 && ( -
- {msg.cited_paper_ids.map((cid) => ( - - - {cid.slice(0, 8)}... - - ))} -
- )} - {/* Evidence */} - {msg.evidence && msg.evidence.length > 0 && ( -
- - 查看 {msg.evidence.length} 条证据 - -
- {msg.evidence.map((ev, i) => ( -
- {JSON.stringify(ev, null, 2)} -
- ))} -
-
- )} - - )} -
- {msg.role === "user" && ( -
- -
- )} -
- )) - )} - - {/* 加载中提示 */} - {loading && ( -
-
- -
-
-
-
- - - -
- 正在思考... -
-
-
- )} -
- - {/* 输入区域 */} -
-
-