MCPcopy Create free account
hub / github.com/celerforge/freenote / POST

Function POST

src/app/api/chat/route.ts:20–69  ·  view source on GitHub ↗
(req: Request)

Source from the content-addressed store, hash-verified

18`;
19
20export async function POST(req: Request) {
21 const { messages } = await req.json();
22 const provider = await getProvider();
23 if (!provider) {
24 return new Response(
25 "No provider found. Please set API credentials first.",
26 {
27 status: 400,
28 },
29 );
30 }
31 const result = streamText({
32 model: provider.chat("gpt-4o-mini"),
33 system: SYSTEM_PROMPT,
34 tools: {
35 retrieveNote: tool({
36 description: `retrieve information from your personal notes that EXACTLY matches the user's question. Only return information that directly answers the specific question asked. Filter out any unrelated information even if it appears in the same note.`,
37 parameters: z.object({
38 question: z.string().describe("the users question"),
39 filterUnrelated: z
40 .boolean()
41 .default(true)
42 .describe(
43 "whether to filter out unrelated information from the same note",
44 ),
45 }),
46 }),
47 },
48 experimental_telemetry: { isEnabled: true },
49 messages,
50 });
51
52 return result.toDataStreamResponse({
53 getErrorMessage: (error) => {
54 if (error == null) {
55 return "unknown error";
56 }
57
58 if (typeof error === "string") {
59 return error;
60 }
61
62 if (error instanceof Error) {
63 return error.message;
64 }
65
66 return JSON.stringify(error);
67 },
68 });
69}

Callers

nothing calls this directly

Calls 1

getProviderFunction · 0.90

Tested by

no test coverage detected