33 lines
744 B
TypeScript
33 lines
744 B
TypeScript
|
|
export type AiRuntimeConfig = {
|
|
baseUrl: string;
|
|
apiKey: string;
|
|
chatModel: string;
|
|
};
|
|
|
|
export type AiRuntimeConfigResult =
|
|
| { success: true; config: AiRuntimeConfig }
|
|
| { success: false; reason: string };
|
|
|
|
const DEFAULT_CHAT_MODEL = "gpt-4.1-mini";
|
|
|
|
function readOptionalEnv(name: string): string {
|
|
return process.env[name]?.trim() ?? "";
|
|
}
|
|
|
|
export function getAiRuntimeConfig(): AiRuntimeConfigResult {
|
|
const apiKey = readOptionalEnv("AI_API_KEY");
|
|
if (!apiKey) {
|
|
return { success: false, reason: "AI_API_KEY 未配置" };
|
|
}
|
|
|
|
return {
|
|
success: true,
|
|
config: {
|
|
baseUrl: readOptionalEnv("AI_BASE_URL"),
|
|
apiKey,
|
|
chatModel: readOptionalEnv("AI_CHAT_MODEL") || DEFAULT_CHAT_MODEL,
|
|
},
|
|
};
|
|
}
|