Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to allow CORS #44

Open
AshishBarvaliya opened this issue May 28, 2023 · 0 comments
Open

How to allow CORS #44

AshishBarvaliya opened this issue May 28, 2023 · 0 comments

Comments

@AshishBarvaliya
Copy link

AshishBarvaliya commented May 28, 2023

I tried implementing CORS based on the documentation provided in edge-functions-cors
but unfortunately, it's not functioning as expected.

import { OpenAIStream } from "@/utils/OpenAIStream";
import cors from "@/utils/cors";
import { NextRequest } from "next/server";

export const config = {
  runtime: "edge",
};

const handler = async (req: NextRequest): Promise<Response> => {
  const { prompt } = (await req.json()) as {
    prompt?: string;
  };

  const payload = {
    model: "gpt-3.5-turbo",
    messages: [{ role: 'user', content: prompt }],
    temperature: 0.9,
    stream: true,
    // max_tokens: maxWordLimit,
  };

  const stream = await OpenAIStream(payload);
  
  return cors(req, new Response(stream, {
    headers: {
      'Content-Type': 'application/octet-stream',
      'Access-Control-Allow-Origin': '*',
      'Access-Control-Allow-Headers': 'Content-Type',
    }
  }))
};

export default handler;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant