peddi-cronprompt.web.val.run
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { OpenAI } from "https://esm.town/v/std/openai";
export default async function(req: Request): Promise<Response> {
const query = new URL(req.url).searchParams;
const prompt = query.get("prompt");
if (!prompt) {
return new Response("Missing prompt query param in the request", { status: 400 });
}
const openai = new OpenAI();
const functionExpression = await openai.chat.completions.create({
messages: [
{
role: "system",
content:
"You are a helpful assistant that converts the user's prompt into a valid crontab expression. You only reply with valid crontab expressions.",
},
{ role: "user", content: "On Juneteenth every hour" },
{ role: "assistant", content: "0 * 19 6 * *" },
{ role: "user", content: "At midnight on christmas" },
{ role: "assistant", content: "0 0 25 12 * *" },
{ role: "user", content: prompt },
],
model: "gpt-4o",
max_tokens: 30,
});
const result = functionExpression.choices[0].message.content;
return Response.json({ result });
}
v3
May 15, 2024