mirror of
https://github.com/massbug/judge4c.git
synced 2026-05-20 13:18:52 +00:00
30 lines
610 B
TypeScript
30 lines
610 B
TypeScript
import "server-only";
|
|
|
|
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
|
|
const getRequiredEnv = (
|
|
name: "AI_API_KEY" | "AI_BASE_URL" | "AI_MODEL",
|
|
): string => {
|
|
const value = process.env[name];
|
|
|
|
if (!value) {
|
|
throw new Error(`Missing required environment variable: ${name}`);
|
|
}
|
|
|
|
return value;
|
|
};
|
|
|
|
const apiKey = getRequiredEnv("AI_API_KEY");
|
|
|
|
const baseURL = getRequiredEnv("AI_BASE_URL");
|
|
|
|
export const modelId = getRequiredEnv("AI_MODEL");
|
|
|
|
export const aiProvider = createOpenAICompatible({
|
|
name: "ai",
|
|
apiKey,
|
|
baseURL,
|
|
});
|
|
|
|
export const model = aiProvider(modelId);
|