深度思考
This commit is contained in:
@@ -8,12 +8,12 @@
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
<script src="/node_modules/ace-builds/src-min-noconflict/ace.js" type="text/javascript"></script>
|
||||
<title>NPCs</title>
|
||||
<script type="module" crossorigin src="/assets/index-13a97ef6.js"></script>
|
||||
<script type="module" crossorigin src="/assets/index-e0228455.js"></script>
|
||||
<link rel="modulepreload" crossorigin href="/assets/acebuilds-fbc0ccc6.js">
|
||||
<link rel="modulepreload" crossorigin href="/assets/reactflow-c250d835.js">
|
||||
<link rel="modulepreload" crossorigin href="/assets/reactdrop-be699031.js">
|
||||
<link rel="modulepreload" crossorigin href="/assets/pdfjs-36654f0a.js">
|
||||
<link rel="stylesheet" href="/assets/index-1055532c.css">
|
||||
<link rel="stylesheet" href="/assets/index-e06d93b0.css">
|
||||
</head>
|
||||
|
||||
<body id='body' style="width: 100%; height:100%">
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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(
|
||||
() => (
|
||||
<ReactMarkdown
|
||||
remarkPlugins={[remarkGfm, remarkMath]}
|
||||
rehypePlugins={[rehypeMathjax]}
|
||||
linkTarget="_blank"
|
||||
className="bs-mkdown inline-block break-all max-w-full text-sm text-text-answer "
|
||||
components={{
|
||||
code: ({ node, inline, className, children, ...props }) => {
|
||||
if (children.length) {
|
||||
if (children[0] === "▍") {
|
||||
return (<span className="form-modal-markdown-span"> ▍ </span>);
|
||||
}
|
||||
|
||||
children[0] = (children[0] as string).replace("`▍`", "▍");
|
||||
}
|
||||
|
||||
const match = /language-(\w+)/.exec(className || "");
|
||||
|
||||
return !inline ? (
|
||||
<CodeBlock
|
||||
key={Math.random()}
|
||||
language={(match && match[1]) || ""}
|
||||
value={String(children).replace(/\n$/, "")}
|
||||
{...props}
|
||||
/>
|
||||
) : (
|
||||
<code className={className} {...props}> {children} </code>
|
||||
);
|
||||
},
|
||||
}}
|
||||
>
|
||||
{data.reasoning_content ? data.reasoning_content.toString() : ""}
|
||||
</ReactMarkdown>
|
||||
),
|
||||
[data.reasoning_content, data.reasoning_content ? data.reasoning_content.toString() : ""]
|
||||
)
|
||||
|
||||
const messageRef = useRef<HTMLDivElement>(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 <div className="flex w-full py-1">
|
||||
<div className="w-[100%]">
|
||||
@@ -115,15 +154,19 @@ export default function MessageBs({ data, onUnlike = () => { }, flow_type, onSou
|
||||
</div>
|
||||
: <div><LoadIcon className="text-gray-400" /></div>
|
||||
} */}
|
||||
{data.message.toString() && data.message.toString().includes('```chart') && <Chart options={data.message} />}
|
||||
{data.message.toString() && !data.message.toString().includes('```chart') && <div className="chat-start-zk relative">
|
||||
{mkdown}
|
||||
{(data.message.toString() || (data.reasoning_content && data.reasoning_content.toString())) && data.message.toString().includes('```chart') && <Chart options={data.message} />}
|
||||
{(data.message.toString() || (data.reasoning_content && data.reasoning_content.toString())) && !data.message.toString().includes('```chart') && <div className="chat-start-zk relative">
|
||||
{(data.reasoning_content && data.reasoning_content.toString()) && <div className="shendu">
|
||||
<div className="shenduBtn" onClick={() => {setShenduOff(!shenduOff)}}>深度思考 <svg className={`${!shenduOff && 'transform180'}`} width="10" height="6" viewBox="0 0 10 6" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M5.786 4.167L2.765 1.259c-.416-.4-.985-.482-1.273-.183-.287.298-.183.864.233 1.264l3.021 2.908c.416.4.986.482 1.273.184.287-.299.183-.865-.233-1.265z" fill="currentColor"></path><path d="M8.197 1.206L5.288 4.208c-.4.413-.484.982-.187 1.27.298.289.864.187 1.265-.227L9.274 2.25c.401-.414.485-.983.187-1.271-.297-.288-.863-.187-1.264.227z" fill="currentColor"></path></svg></div>
|
||||
{shenduOff && <div className="shenduText">{mkdownReasoning}</div>}
|
||||
</div>}
|
||||
<div className="mt-[10px]">{mkdown}</div>
|
||||
{/* @user */}
|
||||
{data.receiver && <p className="text-blue-500 text-sm">@ {data.receiver.user_name}</p>}
|
||||
{/* 光标 */}
|
||||
{/* {data.message.toString() && !data.end && <div className="animate-cursor absolute w-2 h-5 ml-1 bg-gray-600" style={{ left: cursor.x, top: cursor.y }}></div>} */}
|
||||
</div>}
|
||||
{!data.message.toString() && <div><LoadIcon className="text-gray-400" /></div>}
|
||||
{(!data.message.toString() && !data.reasoning_content.toString()) && <div><LoadIcon className="text-gray-400" /></div>}
|
||||
|
||||
{/* 赞 踩 */}
|
||||
{!!data.id && data.end && <Thumbs
|
||||
|
||||
@@ -75,7 +75,6 @@ export default function MessagePanne({ useName, guideWord, loadMore, flow_type }
|
||||
} else if (msg.thought) {
|
||||
type = 'system'
|
||||
}
|
||||
console.log(type)
|
||||
switch (type) {
|
||||
case 'user':
|
||||
return <MessageUser key={msg.id} useName={useName} data={msg} />;
|
||||
|
||||
@@ -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<State & Actions>((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<State & Actions>((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: '',
|
||||
|
||||
@@ -4215,3 +4215,22 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
.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;
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user