From c08424a4dcca4f298fe77cb6540ffad938129f57 Mon Sep 17 00:00:00 2001 From: fyah Date: Sat, 9 May 2026 13:33:12 +0800 Subject: [PATCH] =?UTF-8?q?PWA=E5=AF=B9=E8=AF=9D=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E9=87=8D=E6=9E=84=20+=20=E8=AE=B0=E5=BF=86=E5=BA=93=E6=A1=A5?= =?UTF-8?q?=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 纯对话界面:消息气泡、深灰输入框 - 桥接服务接入 DeepSeek API - 记忆库文件纳入 mao1 仓库(含沈晏身份/对话规则) - 移除 ModelSelector、光晕效果等无关元素 Co-Authored-By: Claude Opus 4.7 --- PWA/src/App.tsx | 52 +++++++- PWA/src/components/ChatArea.tsx | 40 ++++-- PWA/src/components/InputArea.tsx | 40 +++++- PWA/src/components/ModelSelector.tsx | 31 ----- PWA/src/index.css | 13 -- shenyan-room/.gitignore | 2 + .../316c2a59-14d5-4c10-b498-fe411a8fba29.png | Bin 0 -> 154421 bytes shenyan-room/_library.md | 15 +++ .../attention is all you need/4-28-2026.md | 126 ++++++++++++++++++ .../4-30-2026/编码器-解码器-q k v.md | 22 +++ shenyan-room/工作周报/工作周报.md | 9 ++ shenyan-room/记忆库规范.md | 43 ++++++ 12 files changed, 325 insertions(+), 68 deletions(-) delete mode 100644 PWA/src/components/ModelSelector.tsx create mode 100644 shenyan-room/.gitignore create mode 100644 shenyan-room/316c2a59-14d5-4c10-b498-fe411a8fba29.png create mode 100644 shenyan-room/_library.md create mode 100644 shenyan-room/attention is all you need/4-28-2026.md create mode 100644 shenyan-room/attention is all you need/4-30-2026/编码器-解码器-q k v.md create mode 100644 shenyan-room/工作周报/工作周报.md create mode 100644 shenyan-room/记忆库规范.md diff --git a/PWA/src/App.tsx b/PWA/src/App.tsx index 9ce8e52..0217f4f 100644 --- a/PWA/src/App.tsx +++ b/PWA/src/App.tsx @@ -1,18 +1,58 @@ import { useState } from 'react' -import ModelSelector from './components/ModelSelector' import ChatArea from './components/ChatArea' import InputArea from './components/InputArea' -export type Model = 'Omni' | 'Qwen3.5' | 'Deepseek' +export type Message = { + id: number + role: 'user' | 'shenyan' + text: string +} + +const API = 'http://localhost:3001/api/chat' + +let nextId = 0 export default function App() { - const [activeModel, setActiveModel] = useState('Deepseek') + const [messages, setMessages] = useState([]) + const [loading, setLoading] = useState(false) + + const handleSend = async (text: string) => { + const userMsg: Message = { id: nextId++, role: 'user', text } + setMessages((prev) => [...prev, userMsg]) + setLoading(true) + + try { + const apiMessages = [ + ...messages.map((m) => ({ + role: m.role === 'user' ? 'user' : 'assistant', + content: m.text, + })), + { role: 'user', content: userMsg.text }, + ] + + const res = await fetch(API, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ model: 'deepseek-chat', messages: apiMessages }), + }) + + const data = await res.json() + const reply = data.choices?.[0]?.message?.content || '(no response)' + setMessages((prev) => [...prev, { id: nextId++, role: 'shenyan', text: reply }]) + } catch { + setMessages((prev) => [...prev, { id: nextId++, role: 'shenyan', text: '连接失败' }]) + } finally { + setLoading(false) + } + } return (
- - - +
+ 沈晏 +
+ +
) } diff --git a/PWA/src/components/ChatArea.tsx b/PWA/src/components/ChatArea.tsx index 6d6009a..cff4dcf 100644 --- a/PWA/src/components/ChatArea.tsx +++ b/PWA/src/components/ChatArea.tsx @@ -1,15 +1,33 @@ -export default function ChatArea() { +import { useRef, useEffect } from 'react' +import type { Message } from '../App' + +export default function ChatArea({ messages }: { messages: Message[] }) { + const bottom = useRef(null) + + useEffect(() => { + bottom.current?.scrollIntoView({ behavior: 'smooth' }) + }, [messages]) + return ( -
-
-
-

- 1. 示例文字: -

-

- 2. -

-
+
+
+ {messages.map((m) => ( +
+
+ {m.text} +
+
+ ))} +
) diff --git a/PWA/src/components/InputArea.tsx b/PWA/src/components/InputArea.tsx index 908502b..f458931 100644 --- a/PWA/src/components/InputArea.tsx +++ b/PWA/src/components/InputArea.tsx @@ -1,13 +1,39 @@ -export default function InputArea() { +import { useState } from 'react' + +export default function InputArea({ onSend, disabled }: { onSend: (text: string) => void; disabled?: boolean }) { + const [value, setValue] = useState('') + + const handleSubmit = () => { + const trimmed = value.trim() + if (!trimmed) return + onSend(trimmed) + setValue('') + } + return ( -
-
- +
+