This commit is contained in:
hailin 2025-05-29 20:50:07 +08:00
parent e6164160ef
commit a6e77c12fe
1 changed files with 16 additions and 6 deletions

View File

@ -41,17 +41,26 @@ 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">
<MessageMarkdown content={visibleContent} /> <MessageMarkdown content={visibleContent} />
{thinkMatch && thinkContent && ( {thinkContent && (
<div className="mt-2 text-sm text-muted-foreground"> <div className="mt-2 text-sm text-muted-foreground">
<button <button
className="text-blue-500 hover:underline" className="text-blue-500 hover:underline"
@ -71,6 +80,7 @@ const MessageContent: React.FC<{ content: string }> = ({ content }) => {
) )
} }
export const Message: FC<MessageProps> = ({ export const Message: FC<MessageProps> = ({
message, message,
fileItems, fileItems,