From daabce8a5fc7b6caab4a7541f53d85d16ff497fc Mon Sep 17 00:00:00 2001 From: Blame <17600160566@163.com> Date: Fri, 7 Mar 2025 17:32:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=B1=E5=BA=A6=E6=80=9D=E8=80=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 10244 -> 10244 bytes build/index.html | 4 +- .../bs-comp/chatComponent/ChatInput.tsx | 1 + .../bs-comp/chatComponent/MessageBs.tsx | 55 ++++++++++++++++-- .../bs-comp/chatComponent/MessagePanne.tsx | 1 - .../bs-comp/chatComponent/messageStore.ts | 7 ++- src/style/zk.scss | 19 ++++++ src/types/chat/index.ts | 1 + 8 files changed, 78 insertions(+), 10 deletions(-) diff --git a/.DS_Store b/.DS_Store index a7906735060df2323e4a56fb3059a01faa59c806..7caf9775adc0c587f6b46fc2bb01d11c1d244b81 100644 GIT binary patch delta 222 zcmZn(XbG6$FDk>pz`)4BAi&_6lb@WFlb;0S3v4W$#y+uucQZQ&3r8qO1q*{7Lpnny zLkY4fpvIp-T=yRgfT|c6xM1plYSS6=81fm47*bL7Fr|a^Ox6<+n=B<@D!e_ZASbi9 z#K7PhBNHZ+`RnG$%PW~j9r^K1()z`W>@&dvU#}(Gcy2^H8;rs delta 83 zcmV-Z0IdInP=rvBPZJsd0003101yBGWJzpqV`6M?VzF_S2a$jevj+$S2muGdDRbATcvJlQ0t;lTa5Vvt|*Y4v~Obvj-sh1hZQe0|TPa7bE}x diff --git a/build/index.html b/build/index.html index 1e61506..14dad9f 100644 --- a/build/index.html +++ b/build/index.html @@ -8,12 +8,12 @@ NPCs - + - + diff --git a/src/components/bs-comp/chatComponent/ChatInput.tsx b/src/components/bs-comp/chatComponent/ChatInput.tsx index e1dbf16..6dfea4c 100644 --- a/src/components/bs-comp/chatComponent/ChatInput.tsx +++ b/src/components/bs-comp/chatComponent/ChatInput.tsx @@ -200,6 +200,7 @@ export default function ChatInput({ clear, form, questions, inputForm, wsUrl, on flow_id: data.flow_id, chat_id: data.chat_id, message: data.message, + reasoning_content: data.reasoning_content, thought: data.intermediate_steps }) } else if (['end', 'end_cover'].includes(data.type)) { diff --git a/src/components/bs-comp/chatComponent/MessageBs.tsx b/src/components/bs-comp/chatComponent/MessageBs.tsx index dfd21dc..9ef11f6 100644 --- a/src/components/bs-comp/chatComponent/MessageBs.tsx +++ b/src/components/bs-comp/chatComponent/MessageBs.tsx @@ -3,7 +3,7 @@ import { LoadIcon } from "@/components/bs-icons/loading"; import { CodeBlock } from "@/modals/formModal/chatMessage/codeBlock"; import { ChatMessageType } from "@/types/chat"; import { copyText } from "@/utils"; -import { useMemo, useRef } from "react"; +import { useMemo, useRef, useState } from "react"; import ReactMarkdown from "react-markdown"; import rehypeMathjax from "rehype-mathjax"; import remarkGfm from "remark-gfm"; @@ -81,11 +81,50 @@ export default function MessageBs({ data, onUnlike = () => { }, flow_type, onSou [data.message, data.message.toString()] ) + const mkdownReasoning = useMemo( + () => ( + { + if (children.length) { + if (children[0] === "▍") { + return (); + } + + children[0] = (children[0] as string).replace("`▍`", "▍"); + } + + const match = /language-(\w+)/.exec(className || ""); + + return !inline ? ( + + ) : ( + {children} + ); + }, + }} + > + {data.reasoning_content ? data.reasoning_content.toString() : ""} + + ), + [data.reasoning_content, data.reasoning_content ? data.reasoning_content.toString() : ""] + ) + const messageRef = useRef(null) const handleCopyMessage = () => { copyText(messageRef.current) } - // console.log(data) + // let shenduOff = useRef(true) + const [shenduOff, setShenduOff] = useState(true) const chatId = useMessageStore(state => state.chatId) return
@@ -115,15 +154,19 @@ export default function MessageBs({ data, onUnlike = () => { }, flow_type, onSou
:
} */} - {data.message.toString() && data.message.toString().includes('```chart') && } - {data.message.toString() && !data.message.toString().includes('```chart') &&
- {mkdown} + {(data.message.toString() || (data.reasoning_content && data.reasoning_content.toString())) && data.message.toString().includes('```chart') && } + {(data.message.toString() || (data.reasoning_content && data.reasoning_content.toString())) && !data.message.toString().includes('```chart') &&
+ {(data.reasoning_content && data.reasoning_content.toString()) &&
+
{setShenduOff(!shenduOff)}}>深度思考
+ {shenduOff &&
{mkdownReasoning}
} +
} +
{mkdown}
{/* @user */} {data.receiver &&

@ {data.receiver.user_name}

} {/* 光标 */} {/* {data.message.toString() && !data.end &&
} */}
} - {!data.message.toString() &&
} + {(!data.message.toString() && !data.reasoning_content.toString()) &&
} {/* 赞 踩 */} {!!data.id && data.end && ; diff --git a/src/components/bs-comp/chatComponent/messageStore.ts b/src/components/bs-comp/chatComponent/messageStore.ts index 2b13410..f15ffad 100644 --- a/src/components/bs-comp/chatComponent/messageStore.ts +++ b/src/components/bs-comp/chatComponent/messageStore.ts @@ -50,9 +50,10 @@ const handleHistoryMsg = (data: any[]): ChatMessageType[] => { .replace(/'/g, '"'); // 将单引号替换为双引号 return data.map(item => { // let count = 0 - let { message, files, is_bot, intermediate_steps, ...other } = item + let { message,reasoning_content, files, is_bot, intermediate_steps, ...other } = item try { message = message && message[0] === '{' ? JSON.parse(message) : message || '' + reasoning_content = reasoning_content && reasoning_content[0] === '{' ? JSON.parse(reasoning_content) : reasoning_content || '' } catch (e) { // 未考虑的情况暂不处理 console.error('消息 to JSON error :>> ', e); @@ -64,6 +65,7 @@ const handleHistoryMsg = (data: any[]): ChatMessageType[] => { files: files ? JSON.parse(files) : [], isSend: !is_bot, message, + reasoning_content, thought: intermediate_steps, noAccess: true } @@ -134,6 +136,7 @@ export const useMessageStore = create((set, get) => ({ newChat.push({ isSend: false, message: runLogsTypes.includes(data.category) ? JSON.parse(data.message) : '', + reasoning_content: runLogsTypes.includes(data.category) ? JSON.parse(data.reasoning_content) : '', chatKey: '', thought: data.intermediate_steps || '', category: data.category || '', @@ -165,6 +168,7 @@ export const useMessageStore = create((set, get) => ({ ...wsdata, id: isRunLog ? wsdata.extra : wsdata.messageId, // 每条消息必唯一 message: isRunLog ? JSON.parse(wsdata.message) : currentMessage.message + wsdata.message, + reasoning_content: isRunLog ? JSON.parse(wsdata.reasoning_content) : currentMessage.reasoning_content + wsdata.reasoning_content, thought: currentMessage.thought + (wsdata.thought ? `${wsdata.thought}\n` : ''), files: wsdata.files || null, category: wsdata.category || '', @@ -243,6 +247,7 @@ const bsMsgItem = { id: Math.random() * 1000000, isSend: false, message: '', + reasoning_content: '', chatKey: '', thought: '', category: '', diff --git a/src/style/zk.scss b/src/style/zk.scss index 2ba65db..5b795f9 100644 --- a/src/style/zk.scss +++ b/src/style/zk.scss @@ -4214,4 +4214,23 @@ } } } + } + .shenduBtn{ + width: 100px; + padding: 7px 14px; + background: rgba(255, 255, 255, 0.05); + display: flex; + align-items: center; + border-radius: 10px; + cursor: pointer; + color: #999999; + } + .transform180{ + transform: rotate(180deg); + } + .shenduText{ + color: #999999; + margin-top: 10px; + line-height: 26px; + margin-bottom: 10px; } \ No newline at end of file diff --git a/src/types/chat/index.ts b/src/types/chat/index.ts index bc9fcf9..5f7689b 100644 --- a/src/types/chat/index.ts +++ b/src/types/chat/index.ts @@ -3,6 +3,7 @@ import { FlowType } from "../flow"; export type ChatType = { flow: FlowType; reactFlowInstance: ReactFlowInstance }; export type ChatMessageType = { + reasoning_content: string | Object; message: string | Object; template?: string; isSend: boolean;