
import { Ingestion } from "@polar-sh/ingestion";
import { LLMStrategy } from "@polar-sh/ingestion/strategies/LLM";
import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";
const llmIngestion = Ingestion({ accessToken: 'xxx' })
.strategy(new LLMStrategy(openai("gpt-4o")))
.ingest("openai-usage");
export async function POST(req: Request) {
const { prompt }: { prompt: string } = await req.json();
const model = llmIngestion.client({
externalCustomerId: "<USER_ID_FROM_YOUR_DATABASE>",
});
const { text } = await generateText({
model,
system: "You are a helpful assistant.",
prompt,
});
return Response.json({ text });
}