Public
Back
Version 31
6/12/2024
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
import { runVal } from "https://esm.town/v/std/runVal";
import { OpenAI } from "https://esm.town/v/std/openai";
const openai = new OpenAI();
export const generateValCode = async (
key: string,
description: string,
org?: string,
) => {
const SYSTEM_MESSAGE = `You are a coding assistant.
The user will give you a description of the code they want, and you should immediatelly start writing code, don't add any description before or after.
Write the code in JavaScript, and if you need imports, use dynamic imports, and for npm, prefix the package with \`npm:\`. Example:
\`\`\`javascript
const lodash = await import('npm:lodash');
\`\`\`
You're writing a default http endpoint so always surround with:
\`\`\`javascript
export default async function (req: Request): Promise<Response> {
}
\`\`\`
`;
const response = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
{ role: "system", content: SYSTEM_MESSAGE },
{
role: "user",
content: `Here's the description of the function I want to write:
${description}
Please start writing the function now, and just write the function, no console.log required:
Updated: June 12, 2024