Skip to content

Commit caac0b2

Browse files
committed
feat (chat): fixed chat history! no more hallucinations
1 parent 9e75b9a commit caac0b2

8 files changed

Lines changed: 355 additions & 260 deletions

File tree

src/client/app/chat/page.js

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -596,41 +596,6 @@ export default function ChatPage() {
596596
return "Good Evening"
597597
}
598598

599-
const getFinalAnswer = (content) => {
600-
if (!content || typeof content !== "string") return ""
601-
602-
const answerParts = []
603-
const regex =
604-
/(<think(?:ing)?>[\s\S]*?<\/think(?:ing)?>|<tool_code[^>]*>[\s\S]*?<\/tool_code>|<tool_result[^>]*>[\s\S]*?<\/tool_result>|<answer>[\s\S]*?<\/answer>)/g
605-
let lastIndex = 0
606-
let inToolCallPhase = false
607-
608-
for (const match of content.matchAll(regex)) {
609-
const precedingText = content.substring(lastIndex, match.index)
610-
if (precedingText.trim() && !inToolCallPhase) {
611-
answerParts.push(precedingText.trim())
612-
}
613-
614-
const tag = match[0]
615-
if (tag.startsWith("<tool_code")) inToolCallPhase = true
616-
else if (tag.startsWith("<tool_result")) inToolCallPhase = false
617-
else if (tag.startsWith("<answer>")) {
618-
const answerContent =
619-
tag.match(/<answer>([\s\S]*?)<\/answer>/)?.[1] || ""
620-
if (answerContent) answerParts.push(answerContent.trim())
621-
}
622-
lastIndex = match.index + tag.length
623-
}
624-
const remainingText = content.substring(lastIndex)
625-
if (remainingText.trim() && !inToolCallPhase) {
626-
answerParts.push(remainingText.trim())
627-
}
628-
629-
const plainText = answerParts.join("\n\n")
630-
if (plainText) return plainText
631-
return content.replace(/<[^>]+>/g, "").trim()
632-
}
633-
634599
// --- Voice Mode Handlers ---
635600
const handleStatusChange = useCallback((status) => {
636601
setConnectionStatus(status)
@@ -918,7 +883,7 @@ export default function ChatPage() {
918883
: "the assistant"}
919884
</p>
920885
<p className="text-sm text-neutral-200 mt-1 truncate">
921-
{getFinalAnswer(replyingTo.content)}
886+
{replyingTo.content.replace(/<[^>]+>/g, "").trim()}
922887
</p>
923888
</div>
924889
<button
@@ -1480,9 +1445,7 @@ export default function ChatPage() {
14801445
duration: 0.3
14811446
}}
14821447
>
1483-
{getFinalAnswer(
1484-
msg.content
1485-
)}
1448+
{msg.content}
14861449
</motion.div>
14871450
))}
14881451
</AnimatePresence>
@@ -1533,6 +1496,9 @@ export default function ChatPage() {
15331496
role={msg.role}
15341497
content={msg.content}
15351498
tools={msg.tools || []}
1499+
thoughts={msg.thoughts || []}
1500+
tool_calls={msg.tool_calls || []}
1501+
tool_results={msg.tool_results || []}
15361502
onReply={handleReply}
15371503
message={msg}
15381504
allMessages={displayedMessages}

0 commit comments

Comments
 (0)