feat: use env variable to enable ai sdk
This commit is contained in:
parent
9b88c27373
commit
3eab50f3d1
1 changed files with 28 additions and 0 deletions
|
|
@ -63,7 +63,35 @@ function isHuggingFaceOpenAICompatible(url: string): boolean {
|
|||
return openAIPatterns.some((pattern) => normalizedUrl.includes(pattern));
|
||||
}
|
||||
|
||||
function createAiSdkApiForProvider(
|
||||
config: LLMConfig & { model?: string },
|
||||
provider: string,
|
||||
): AiSdkApi | undefined {
|
||||
if (!config.model) {
|
||||
return undefined;
|
||||
}
|
||||
return new AiSdkApi({
|
||||
provider: "ai-sdk",
|
||||
model: `${provider}/${config.model}`,
|
||||
apiKey: config.apiKey,
|
||||
apiBase: config.apiBase,
|
||||
requestOptions: config.requestOptions,
|
||||
});
|
||||
}
|
||||
|
||||
export function constructLlmApi(config: LLMConfig): BaseLlmApi | undefined {
|
||||
if (process.env.CONTINUE_USE_AI_SDK) {
|
||||
if (["openai", "anthropic"].includes(config.provider)) {
|
||||
const aiSdkApi = createAiSdkApiForProvider(
|
||||
config as LLMConfig & { model?: string },
|
||||
config.provider,
|
||||
);
|
||||
if (aiSdkApi) {
|
||||
return aiSdkApi;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (config.provider) {
|
||||
case "openai":
|
||||
return new OpenAIApi(config);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue