Spaces:
Sleeping
Sleeping
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 }); | |
} | |
} | |