38 lines
918 B
TypeScript
38 lines
918 B
TypeScript
import { AIOptions, AIOptionsObject, SiteConfig } from "../types";
|
|
|
|
type Params = {
|
|
userConfig?: SiteConfig | null;
|
|
};
|
|
|
|
export type GrabUserAIConfigReturn = {};
|
|
|
|
export default function grabUserAIInfo({
|
|
userConfig: passedConfig,
|
|
}: Params): AIOptionsObject | undefined {
|
|
const userConfig: SiteConfig | undefined = passedConfig
|
|
? passedConfig
|
|
: undefined;
|
|
|
|
if (!userConfig) return undefined;
|
|
|
|
const targetAI = userConfig?.main.target_ai;
|
|
|
|
if (!targetAI?.name || !userConfig?.main.api_keys) return undefined;
|
|
|
|
const targetAIAPIKey = userConfig.main.api_keys[targetAI.name].key;
|
|
|
|
if (!targetAIAPIKey) return undefined;
|
|
|
|
const targetAIOption = AIOptions.find(
|
|
(aiOpt) => aiOpt.name == targetAI.name
|
|
);
|
|
|
|
targetAI.apiKey = targetAIAPIKey;
|
|
|
|
if (targetAIOption?.baseUrl) {
|
|
targetAI.baseUrl = targetAIOption.baseUrl;
|
|
}
|
|
|
|
return targetAI;
|
|
}
|