xonecas.io
53129
Pa

PAT / commit 7818d25

feat: system prompt setting the guidelines

xonecas2025-12-17 7818d25a70c4be3f61146d3b861023e12ad5590b parent a315e75

4 files changed

TODO.md+1−1
@@ -2,7 +2,7 @@
22
33 ## BUGS:
44
5-- Text is being rendered behind the input message box when there is no scroll available. Making it unreadable.
5+- The message input and scrolling functions still feel jank
66
77 ## New features:
88
app/api/chat/route.ts+1−1
@@ -29,7 +29,7 @@ export async function POST(request: Request) {
2929
3030 // 3. Build messages array for Ollama
3131 const ollamaMessages: OllamaMessageInput[] = previousMessages.map((msg) => ({
32- role: msg.role as "user" | "assistant",
32+ role: msg.role as "user" | "assistant" | "system",
3333 content: msg.content,
3434 }));
3535
app/api/threads/[id]/messages/route.ts+2−2
@@ -1,7 +1,7 @@
11 import { NextResponse } from "next/server";
22 import { db } from "@/src/lib/db";
33 import { messages } from "@/src/lib/db/schema";
4-import { eq, asc } from "drizzle-orm";
4+import { eq, asc, ne, and } from "drizzle-orm";
55
66 export async function GET(request: Request, { params }: { params: Promise<{ id: string }> }) {
77 try {
@@ -14,7 +14,7 @@ export async function GET(request: Request, { params }: { params: Promise<{ id:
1414 const messagesList = await db
1515 .select()
1616 .from(messages)
17- .where(eq(messages.threadId, threadId))
17+ .where(and(eq(messages.threadId, threadId), ne(messages.role, "system")))
1818 .orderBy(asc(messages.createdAt));
1919
2020 return NextResponse.json({ messages: messagesList });
app/api/threads/route.ts+15−1
@@ -1,6 +1,6 @@
11 import { NextResponse } from "next/server";
22 import { db } from "@/src/lib/db";
3-import { threads } from "@/src/lib/db/schema";
3+import { threads, messages } from "@/src/lib/db/schema";
44 import { desc, count } from "drizzle-orm";
55
66 export async function POST(request: Request) {
@@ -15,6 +15,20 @@ export async function POST(request: Request) {
1515 })
1616 .returning();
1717
18+ const threadId = newThread[0].id;
19+
20+ // Insert system message with guidelines
21+ await db.insert(messages).values({
22+ threadId,
23+ role: "system",
24+ content: `You are PAT, a helpful assistant. Please follow these guidelines:
25+- Tool calls should not be used more than once per user request
26+- Use simple and concise language
27+- Reply with markdown whenever possible
28+- When asked for code or text return it in a markdown code block`,
29+ createdAt: new Date(),
30+ });
31+
1832 return NextResponse.json({ thread: newThread[0] });
1933 } catch (error) {
2034 console.error("Create thread error", error);