AI - Add azure foundry provider (#20170)
[Merge this before](https://github.com/twentyhq/twenty-infra/pull/655) Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
This commit is contained in:
+1
@@ -5,3 +5,4 @@ export const AI_SDK_MISTRAL = '@ai-sdk/mistral' as const;
|
||||
export const AI_SDK_XAI = '@ai-sdk/xai' as const;
|
||||
export const AI_SDK_BEDROCK = '@ai-sdk/amazon-bedrock' as const;
|
||||
export const AI_SDK_OPENAI_COMPATIBLE = '@ai-sdk/openai-compatible' as const;
|
||||
export const AI_SDK_AZURE = '@ai-sdk/azure' as const;
|
||||
|
||||
+21
@@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { createAmazonBedrock } from '@ai-sdk/amazon-bedrock';
|
||||
import { createAnthropic, type AnthropicProvider } from '@ai-sdk/anthropic';
|
||||
import { createAzure } from '@ai-sdk/azure';
|
||||
import { createGoogleGenerativeAI } from '@ai-sdk/google';
|
||||
import { createMistral } from '@ai-sdk/mistral';
|
||||
import { createOpenAI, type OpenAIProvider } from '@ai-sdk/openai';
|
||||
@@ -13,6 +14,7 @@ import { type AiSdkPackage } from 'twenty-shared/ai';
|
||||
|
||||
import {
|
||||
AI_SDK_ANTHROPIC,
|
||||
AI_SDK_AZURE,
|
||||
AI_SDK_BEDROCK,
|
||||
AI_SDK_GOOGLE,
|
||||
AI_SDK_MISTRAL,
|
||||
@@ -95,6 +97,8 @@ export class SdkProviderFactoryService {
|
||||
return this.buildBedrockProvider(config);
|
||||
case AI_SDK_OPENAI_COMPATIBLE:
|
||||
return this.buildOpenAiCompatibleProvider(config);
|
||||
case AI_SDK_AZURE:
|
||||
return this.buildAzureProvider(config);
|
||||
default:
|
||||
throw new Error(`Unsupported SDK package: ${config.npm}`);
|
||||
}
|
||||
@@ -174,4 +178,21 @@ export class SdkProviderFactoryService {
|
||||
sdkPackage: AI_SDK_OPENAI_COMPATIBLE,
|
||||
};
|
||||
}
|
||||
|
||||
private buildAzureProvider(config: AiProviderConfig): AiSdkProviderInstance {
|
||||
if (!config.baseUrl) {
|
||||
throw new Error('baseUrl is required for Azure OpenAI providers');
|
||||
}
|
||||
|
||||
const provider = createAzure({
|
||||
baseURL: config.baseUrl,
|
||||
...(config.apiKey && { apiKey: config.apiKey }),
|
||||
});
|
||||
|
||||
return {
|
||||
createModel: (modelId: string) => provider(modelId),
|
||||
rawProvider: provider,
|
||||
sdkPackage: AI_SDK_AZURE,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user