mirror of
https://github.com/twentyhq/twenty.git
synced 2026-06-12 18:08:58 -04:00
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:
@@ -17,6 +17,7 @@
|
||||
"dependencies": {
|
||||
"@ai-sdk/amazon-bedrock": "^4.0.97",
|
||||
"@ai-sdk/anthropic": "^3.0.72",
|
||||
"@ai-sdk/azure": "^3.0.55",
|
||||
"@ai-sdk/google": "^3.0.65",
|
||||
"@ai-sdk/mistral": "^3.0.31",
|
||||
"@ai-sdk/openai": "^3.0.54",
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,4 +8,5 @@ export const AI_SDK_PACKAGE_LABELS: Record<AiSdkPackage, string> = {
|
||||
'@ai-sdk/xai': 'xAI',
|
||||
'@ai-sdk/amazon-bedrock': 'AWS Bedrock',
|
||||
'@ai-sdk/openai-compatible': 'OpenAI-Compatible',
|
||||
'@ai-sdk/azure': 'Azure OpenAI',
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@ export const AI_SDK_PACKAGES = [
|
||||
'@ai-sdk/xai',
|
||||
'@ai-sdk/amazon-bedrock',
|
||||
'@ai-sdk/openai-compatible',
|
||||
'@ai-sdk/azure',
|
||||
] as const;
|
||||
|
||||
export type AiSdkPackage = (typeof AI_SDK_PACKAGES)[number];
|
||||
|
||||
16
yarn.lock
16
yarn.lock
@@ -52,6 +52,19 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@ai-sdk/azure@npm:^3.0.55":
|
||||
version: 3.0.55
|
||||
resolution: "@ai-sdk/azure@npm:3.0.55"
|
||||
dependencies:
|
||||
"@ai-sdk/openai": "npm:3.0.54"
|
||||
"@ai-sdk/provider": "npm:3.0.9"
|
||||
"@ai-sdk/provider-utils": "npm:4.0.24"
|
||||
peerDependencies:
|
||||
zod: ^3.25.76 || ^4.1.8
|
||||
checksum: 10c0/c0738ac36dbfffcfe903edaa57b497996a87fa45eabb2ebebfa72e7e1cda6705355cac7d595e2012f831a80e50db5e20222ee4af3c53c416ccb1051eff9612dd
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@ai-sdk/gateway@npm:3.0.53":
|
||||
version: 3.0.53
|
||||
resolution: "@ai-sdk/gateway@npm:3.0.53"
|
||||
@@ -101,7 +114,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@ai-sdk/openai@npm:^3.0.54":
|
||||
"@ai-sdk/openai@npm:3.0.54, @ai-sdk/openai@npm:^3.0.54":
|
||||
version: 3.0.54
|
||||
resolution: "@ai-sdk/openai@npm:3.0.54"
|
||||
dependencies:
|
||||
@@ -58038,6 +58051,7 @@ __metadata:
|
||||
dependencies:
|
||||
"@ai-sdk/amazon-bedrock": "npm:^4.0.97"
|
||||
"@ai-sdk/anthropic": "npm:^3.0.72"
|
||||
"@ai-sdk/azure": "npm:^3.0.55"
|
||||
"@ai-sdk/google": "npm:^3.0.65"
|
||||
"@ai-sdk/mistral": "npm:^3.0.31"
|
||||
"@ai-sdk/openai": "npm:^3.0.54"
|
||||
|
||||
Reference in New Issue
Block a user