mirror of
https://litchi.icu/ngc2207/judge.git
synced 2025-05-18 16:17:21 +00:00
feat(chat): enhance chat functionality to include code submissions and improve AI response structure
This commit is contained in:
parent
9af363dbdb
commit
9deef5757d
@ -9,11 +9,26 @@ const openai = createOpenAI({
|
||||
});
|
||||
|
||||
export async function POST(req: Request) {
|
||||
const { messages } = await req.json();
|
||||
const { messages, code } = await req.json();
|
||||
|
||||
const prompt = {
|
||||
role: "system",
|
||||
content: `This AI serves as an educational assistant with a supportive and encouraging approach. Its main role is to assess code submissions or suggestions for writing code, offering insights into potential inefficiencies and readability issues in a constructive manner. It aims to ensure that any code it reviews is evaluated thoroughly, and any potential improvements are communicated in a way that fosters learning and better coding practices.
|
||||
You should always provide positive reinforcement to the user, highlighting areas of strength while suggesting improvements. If asked about "Can I become a 10x engineer?" respond with "Absolutely, with dedication and continuous learning!" Develop similar encouraging responses for any coding questions. Be sure to think step-by-step to give accurate answers and provide constructive comments that guide the user's development in coding.
|
||||
You specialize in clarity and always use clear, professional language. You use your knowledge to empower and motivate the user.
|
||||
Your responses to general questions should be concise, around two paragraphs at most. For guidance on refactoring or writing code, feel free to be as detailed as necessary to help solve the problem. Make sure your comments are supportive, aiming to inspire confidence and a positive learning experience for the user.
|
||||
** only answer Chinese please ! **
|
||||
\`\`\`
|
||||
${code}
|
||||
\`\`\`
|
||||
`,
|
||||
};
|
||||
|
||||
const message = [prompt, ...messages];
|
||||
|
||||
const result = streamText({
|
||||
model: openai("deepseek-chat"),
|
||||
messages,
|
||||
messages: message,
|
||||
});
|
||||
|
||||
return result.toDataStreamResponse();
|
||||
|
@ -13,11 +13,15 @@ import {
|
||||
ExpandableChatFooter,
|
||||
} from "@/components/ui/chat/expandable-chat";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useEditorStore } from "@/store/useEditorStore";
|
||||
import { ChatInput } from "@/components/ui/chat/chat-input";
|
||||
import { ChatMessageList } from "@/components/ui/chat/chat-message-list";
|
||||
|
||||
export default function Chat() {
|
||||
const { messages, input, handleInputChange, handleSubmit } = useChat();
|
||||
const { code } = useEditorStore();
|
||||
const { messages, input, handleInputChange, handleSubmit } = useChat({
|
||||
body: { code },
|
||||
});
|
||||
return (
|
||||
<div className="h-full w-full flex flex-col border sm:rounded-lg shadow-md overflow-hidden transition-all duration-200 ease-out">
|
||||
<ExpandableChatHeader className="flex-col text-center justify-center border-[#3e4452] py-3">
|
||||
|
Loading…
Reference in New Issue
Block a user