This commit is contained in:
hailin 2025-05-29 21:08:42 +08:00
parent f17d6aca22
commit 6ee23bebb5
1 changed files with 19 additions and 8 deletions

View File

@ -83,18 +83,28 @@ interface MessageProps {
const MessageContent: React.FC<{ content: string }> = ({ content }) => { const MessageContent: React.FC<{ content: string }> = ({ content }) => {
const [showThink, setShowThink] = useState(false) const [showThink, setShowThink] = useState(false)
const thinkMatch = content.match(/<think>([\s\S]*?)<\/think>/i) let thinkContent = ""
const thinkContent = thinkMatch?.[1]?.trim() || "" let visibleContent = content.trim()
const visibleContent = thinkMatch
? content.replace(thinkMatch[0], "").trim() const fullMatch = content.match(/<think>([\s\S]*?)<\/think>/i)
: content.trim() if (fullMatch) {
thinkContent = fullMatch[1].trim()
visibleContent = content.replace(fullMatch[0], "").trim()
} else {
const endOnlyMatch = content.match(/([\s\S]*?)<\/think>/i)
if (endOnlyMatch) {
thinkContent = endOnlyMatch[1].trim()
visibleContent = content.replace(endOnlyMatch[0], "").trim()
}
}
return ( return (
<div className="space-y-2"> <div className="space-y-2">
{thinkMatch && thinkContent && ( {/* 折叠内容提前显示 */}
<div className="mt-2 text-sm text-muted-foreground"> {thinkContent && (
<div className="text-sm text-muted-foreground">
<button <button
className="text-sm font-medium text-foreground/70 hover:text-foreground underline-offset-2 hover:underline" className="text-sm font-medium text-foreground/70 hover:text-foreground underline underline-offset-2"
onClick={() => setShowThink(prev => !prev)} onClick={() => setShowThink(prev => !prev)}
> >
{showThink ? "隐藏思考过程 ▲" : "显示思考过程 ▼"} {showThink ? "隐藏思考过程 ▲" : "显示思考过程 ▼"}
@ -108,6 +118,7 @@ const MessageContent: React.FC<{ content: string }> = ({ content }) => {
</div> </div>
)} )}
{/* 主消息显示在折叠内容之后 */}
<MessageMarkdown content={visibleContent} /> <MessageMarkdown content={visibleContent} />
</div> </div>
) )