This commit is contained in:
parent
e1d22386a1
commit
fa170db990
|
|
@ -62,6 +62,8 @@ export const Message: FC<MessageProps> = ({
|
||||||
models
|
models
|
||||||
} = useContext(ChatbotUIContext)
|
} = useContext(ChatbotUIContext)
|
||||||
|
|
||||||
|
const [showThink, setShowThink] = useState(false) //添加Think的状态
|
||||||
|
|
||||||
const { handleSendMessage } = useChatHandler()
|
const { handleSendMessage } = useChatHandler()
|
||||||
|
|
||||||
const editInputRef = useRef<HTMLTextAreaElement>(null)
|
const editInputRef = useRef<HTMLTextAreaElement>(null)
|
||||||
|
|
@ -305,7 +307,46 @@ export const Message: FC<MessageProps> = ({
|
||||||
maxRows={20}
|
maxRows={20}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<MessageMarkdown content={message.content} />
|
|
||||||
|
|
||||||
|
|
||||||
|
// <MessageMarkdown content={message.content} />
|
||||||
|
|
||||||
|
|
||||||
|
(() => {
|
||||||
|
const thinkMatch = message.content.match(/<think>([\s\S]*?)<\/think>/i)
|
||||||
|
const thinkContent = thinkMatch?.[1] || ""
|
||||||
|
const visibleContent = message.content.replace(/<think>[\s\S]*?<\/think>/i, "").trim()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-2">
|
||||||
|
<MessageMarkdown content={visibleContent} />
|
||||||
|
|
||||||
|
{thinkMatch && (
|
||||||
|
<div className="mt-2 text-sm text-muted-foreground">
|
||||||
|
<button
|
||||||
|
className="text-blue-500 hover:underline"
|
||||||
|
onClick={() => setShowThink(prev => !prev)}
|
||||||
|
>
|
||||||
|
{showThink ? "隐藏思考过程 ▲" : "显示思考过程 ▼"}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{showThink && (
|
||||||
|
<div className="mt-2 rounded bg-gray-100 p-3 text-sm dark:bg-gray-800">
|
||||||
|
<MessageMarkdown content={thinkContent.trim()} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
})()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue