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