stevekrouse-cronprompt.web.val.run
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
33
import { OpenAI } from "https://esm.town/v/std/openai";
export async function cronprompt(prompt: string) {
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-4",
max_tokens: 30,
});
return functionExpression.choices[0].message.content;
}
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 result = await cronprompt(prompt);
return Response.json({ result });
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
v3
April 24, 2024