refactor: update ApiClientFactory and index_new for improved type handling and provider mapping

- Changed the type of options in ClientConfig to 'any' for flexibility.
- Overloaded createImageClient method to support different provider settings.
- Added vertexai mapping to the provider type mapping in index_new.ts for enhanced compatibility.
This commit is contained in:
MyPrototypeWhat 2025-06-20 20:25:19 +08:00
parent f206d4ec4c
commit 456e6c068e
2 changed files with 17 additions and 8 deletions

View File

@ -12,7 +12,7 @@ import { type ProviderId, type ProviderSettingsMap } from './types'
// 客户端配置接口
export interface ClientConfig {
providerId: string
options?: ProviderOptions
options?: any
}
// 错误类型
@ -108,11 +108,19 @@ export class ApiClientFactory {
}
}
static async createImageClient<T extends ProviderId>(
providerId: T,
modelId: string,
options: ProviderSettingsMap[T]
): Promise<ImageModelV1>
static async createImageClient(
providerId: string,
modelId: string = 'default',
options: ProviderOptions
): Promise<ImageModelV1> {
modelId: string,
options: ProviderSettingsMap['openai-compatible']
): Promise<ImageModelV1>
static async createImageClient(providerId: string, modelId: string = 'default', options: any): Promise<ImageModelV1> {
try {
if (!aiProviderRegistry.isSupported(providerId)) {
throw new ClientFactoryError(`Provider "${providerId}" is not supported`, providerId)
@ -207,9 +215,9 @@ export function createClient(providerId: string, modelId: string = 'default', op
return ApiClientFactory.createClient(providerId, modelId, options)
}
export const createImageClient = (providerId: string, modelId: string, options: any): Promise<ImageModelV1> =>
ApiClientFactory.createImageClient(providerId, modelId, options)
export const getSupportedProviders = () => ApiClientFactory.getSupportedProviders()
export const getClientInfo = (providerId: string) => ApiClientFactory.getClientInfo(providerId)
export const createImageClient = (providerId: string, modelId?: string, options?: any) =>
ApiClientFactory.createImageClient(providerId, modelId, options)

View File

@ -38,7 +38,8 @@ function mapProviderTypeToAiSdkId(providerType: string): string {
// 需要转换的映射
grok: 'xai', // grok -> xai
'azure-openai': 'azure', // azure-openai -> azure
gemini: 'google' // gemini -> google
gemini: 'google', // gemini -> google
vertexai: 'google-vertex' // vertexai -> google-vertex
}
return typeMapping[providerType]