init
This commit is contained in:
16
app/api/chat/route.ts
Normal file
16
app/api/chat/route.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { openai } from "@ai-sdk/openai";
|
||||
import { streamText } from "ai";
|
||||
|
||||
// Allow streaming responses up to 30 seconds
|
||||
export const maxDuration = 30;
|
||||
|
||||
export async function POST(req: Request) {
|
||||
const { messages } = await req.json();
|
||||
|
||||
const result = await streamText({
|
||||
model: openai("gpt-4-turbo"),
|
||||
messages,
|
||||
});
|
||||
|
||||
return result.toAIStreamResponse();
|
||||
}
|
||||
30
app/api/get-access-token/route.ts
Normal file
30
app/api/get-access-token/route.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
const HEYGEN_API_KEY = process.env.HEYGEN_API_KEY;
|
||||
|
||||
export async function POST() {
|
||||
try {
|
||||
if (!HEYGEN_API_KEY) {
|
||||
throw new Error("API key is missing from .env");
|
||||
}
|
||||
|
||||
const res = await fetch(
|
||||
"https://api.heygen.com/v1/streaming.create_token",
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"x-api-key": HEYGEN_API_KEY,
|
||||
},
|
||||
}
|
||||
);
|
||||
const data = await res.json();
|
||||
|
||||
return new Response(data.data.token, {
|
||||
status: 200,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error retrieving access token:", error);
|
||||
|
||||
return new Response("Failed to retrieve access token", {
|
||||
status: 500,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user