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 [showThink, setShowThink] = useState(false)
const thinkMatch = content.match(/<think>([\s\S]*?)<\/think>/i)
const thinkContent = thinkMatch?.[1]?.trim() || ""
const visibleContent = thinkMatch
? content.replace(thinkMatch[0], "").trim()
: content.trim()
let thinkContent = ""
let visibleContent = content.trim()
const fullMatch = content.match(/<think>([\s\S]*?)<\/think>/i)
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 (
<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
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)}
>
{showThink ? "隐藏思考过程 ▲" : "显示思考过程 ▼"}
@ -108,6 +118,7 @@ const MessageContent: React.FC<{ content: string }> = ({ content }) => {
</div>
)}
{/* 主消息显示在折叠内容之后 */}
<MessageMarkdown content={visibleContent} />
</div>
)