Last active
May 1, 2025 12:03
-
-
Save samuelkarani/dd16524bce3d73c71e01ba3906487d7e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { openai } from "@ai-sdk/openai"; | |
import { streamText } from "ai"; | |
export function OPTIONS() { | |
return new Response("OK", { | |
status: 200, | |
headers: { | |
"Access-Control-Allow-Credentials": "true", | |
"Access-Control-Allow-Origin": "*", | |
"Access-Control-Allow-Methods": "GET,OPTIONS,PATCH,DELETE,POST,PUT", | |
"Access-Control-Allow-Headers": | |
"X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version", | |
}, | |
}); | |
} | |
export async function GET() { | |
const response = streamText({ | |
model: openai("gpt-4o-mini"), | |
messages: [{ role: "user", content: "Write a short poem" }], | |
}); | |
return response.toTextStreamResponse({ | |
headers: { | |
"Content-Type": "text/event-stream", | |
"Access-Control-Allow-Credentials": "true", | |
"Access-Control-Allow-Origin": "*", | |
"Access-Control-Allow-Methods": "GET,OPTIONS,PATCH,DELETE,POST,PUT", | |
"Access-Control-Allow-Headers": | |
"X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version", | |
}, | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment