Spaces:
Sleeping
Sleeping
File size: 1,330 Bytes
fff42e3 5fba58f fff42e3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import { NextResponse } from "next/server";
import { OpenAI } from "openai";
import { cultures } from '@/data/cultures';
const client = new OpenAI({
baseURL: "https://api-inference.huggingface.co/v1/",
apiKey: process.env.API_TOKEN,
});
export async function POST(request: Request) {
type RequestBody = {
cultureName: typeof cultures[number];
};
const body = await request.json() as RequestBody;
const { cultureName } = body;
try {
const chatCompletion = await client.chat.completions.create({
model: "meta-llama/Llama-3.1-70B-Instruct",
messages: [
{
role: "system",
content: "You are an expert in Indonesian culture. Provide detailed, accurate information in Indonesian language."
},
{
role: "user",
content: `Jelaskan tentang budaya Indonesia "${cultureName}" dalam 2-3 paragraf yang informatif. Berikan informasi tentang sejarah, makna, dan karakteristik uniknya.`
}
],
max_tokens: 500,
temperature: 0.7,
});
const description = chatCompletion.choices[0]?.message?.content || "";
return NextResponse.json({ description });
} catch (error) {
console.error("Error details:", error);
return NextResponse.json({ error: "Failed to generate description" }, { status: 500 });
}
}
|