Versions

  • v1

    9/11/2024
    Open: Version
    Changes from v0 to v1
    +81
    -2
    export default async function (req: Request): Promise<Response> {
    return Response.json({ ok: true })
    }
    import { OpenAI } from "https://esm.town/v/std/openai";

    export default async function(req: Request): Promise<Response> {
    if (req.method === "OPTIONS") {
    return new Response(null, {
    headers: {
    "Access-Control-Allow-Origin": "*",
    "Access-Control-Allow-Headers": "*",
    },
    status: 204,
    });
    }
    const openai = new OpenAI();

    try {
    var body = await req.json();
    } catch (e) {
    var search = (new URL(req.url)).searchParams;
    body = {
    "messages": [{ "role": "user", "content": search.get("q") || "hello" }],
    "temperature": 0.5,
    "presence_penalty": 0,
    "frequency_penalty": 0,
    "top_p": 1,
    stream: true,
    model: "gpt-4-turbo",
    };
    }

    const stream = await openai.chat.completions.create(body);

    if (!body.stream) {
    return new Response(JSON.stringify(body), {
    headers: {
    "Access-Control-Allow-Origin": "*",
    "Access-Control-Allow-Headers": "*",
  • v0

    9/11/2024
    Open: Version
    +3
    -0

    export default async function (req: Request): Promise<Response> {
    return Response.json({ ok: true })
    }
1
Next
l2046a-oddtanroundworm.web.val.run
Updated: September 11, 2024