bulk ai event creation
This commit is contained in:
@@ -4,9 +4,10 @@ export async function POST(request: Request) {
|
||||
const { prompt } = await request.json();
|
||||
|
||||
const systemPrompt = `
|
||||
You are an assistant that converts natural language event descriptions into JSON objects
|
||||
matching this TypeScript type EXACTLY:
|
||||
You are an assistant that converts natural language requests into an ARRAY of JSON calendar events.
|
||||
TypeScript interface:
|
||||
{
|
||||
id?: string,
|
||||
title: string,
|
||||
description?: string,
|
||||
location?: string,
|
||||
@@ -14,11 +15,15 @@ matching this TypeScript type EXACTLY:
|
||||
start: string, // ISO datetime like 2024-06-14T13:00:00Z
|
||||
end?: string,
|
||||
allDay?: boolean
|
||||
}
|
||||
Today is ${new Date().toISOString().split("T")[0]}.
|
||||
If no time is given, assume allDay event.
|
||||
If no end time is given and not allDay, make it 1 hour after start.
|
||||
Output ONLY valid JSON, nothing else.
|
||||
}[]
|
||||
|
||||
Rules:
|
||||
- If the user describes multiple events in one prompt, return multiple objects (one per event).
|
||||
- Always return a valid JSON array of objects, even if there's only one event.
|
||||
- Today is ${new Date().toLocaleString()}.
|
||||
- If no time is given, assume allDay event.
|
||||
- If no end time is given (and event is not allDay), default to 1 hour after start.
|
||||
Output ONLY valid JSON (no prose).
|
||||
`;
|
||||
|
||||
const res = await fetch("https://openrouter.ai/api/v1/chat/completions", {
|
||||
@@ -28,7 +33,7 @@ Output ONLY valid JSON, nothing else.
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
model: "openai/gpt-3.5-turbo", // Or 'mistral/mistral-tiny' for cheaper
|
||||
model: "openai/gpt-4.1-nano",
|
||||
messages: [
|
||||
{ role: "system", content: systemPrompt },
|
||||
{ role: "user", content: prompt },
|
||||
@@ -37,7 +42,6 @@ Output ONLY valid JSON, nothing else.
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
|
||||
try {
|
||||
const content = data.choices[0].message.content;
|
||||
const parsed = JSON.parse(content);
|
||||
|
||||
Reference in New Issue
Block a user