From cbe8ff9941d91a22d19afe470fbab2ecb9b59b6c Mon Sep 17 00:00:00 2001 From: cfngc4594 Date: Mon, 24 Mar 2025 21:24:20 +0800 Subject: [PATCH] feat(ai-bot): integrate problem data into AI bot page initialization --- src/app/(app)/problems/[id]/@ai/@bot/page.tsx | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/app/(app)/problems/[id]/@ai/@bot/page.tsx b/src/app/(app)/problems/[id]/@ai/@bot/page.tsx index fdfb994..4a21788 100644 --- a/src/app/(app)/problems/[id]/@ai/@bot/page.tsx +++ b/src/app/(app)/problems/[id]/@ai/@bot/page.tsx @@ -3,6 +3,7 @@ import { useChat } from "@ai-sdk/react"; import { SendHorizonal } from "lucide-react"; import { Button } from "@/components/ui/button"; +import { useProblem } from "@/hooks/use-problem"; import MdxPreview from "@/components/mdx-preview"; import { Textarea } from "@/components/ui/textarea"; import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"; @@ -10,21 +11,32 @@ import { ChatMessageList } from "@/components/ui/chat/chat-message-list"; import { ChatBubble, ChatBubbleAvatar, ChatBubbleMessage } from "@/components/ui/chat/chat-bubble"; export default function AiBotPage() { - const { messages, input, handleInputChange, handleSubmit } = useChat(); + const { problemId, problem } = useProblem(); + const { messages, input, handleInputChange, handleSubmit } = useChat({ + initialMessages: [ + { + id: problemId, + role: "system", + content: `Problem description:\n${problem.description}`, + }, + ], + }); return (
- {messages.map((message, index) => ( - - - - - - - ))} + {messages + .filter((message) => message.role === "user" || message.role === "assistant") + .map((message, index) => ( + + + + + + + ))}