From 456e6c068e6d92008df09f3cca095a9e588bbf0d Mon Sep 17 00:00:00 2001 From: MyPrototypeWhat Date: Fri, 20 Jun 2025 20:25:19 +0800 Subject: [PATCH] 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. --- .../aiCore/src/clients/ApiClientFactory.ts | 22 +++++++++++++------ src/renderer/src/aiCore/index_new.ts | 3 ++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/aiCore/src/clients/ApiClientFactory.ts b/packages/aiCore/src/clients/ApiClientFactory.ts index edcb80046e..4fed041b99 100644 --- a/packages/aiCore/src/clients/ApiClientFactory.ts +++ b/packages/aiCore/src/clients/ApiClientFactory.ts @@ -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( + providerId: T, + modelId: string, + options: ProviderSettingsMap[T] + ): Promise + static async createImageClient( providerId: string, - modelId: string = 'default', - options: ProviderOptions - ): Promise { + modelId: string, + options: ProviderSettingsMap['openai-compatible'] + ): Promise + + static async createImageClient(providerId: string, modelId: string = 'default', options: any): Promise { 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 => + 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) diff --git a/src/renderer/src/aiCore/index_new.ts b/src/renderer/src/aiCore/index_new.ts index 206d8cd761..c448a3318b 100644 --- a/src/renderer/src/aiCore/index_new.ts +++ b/src/renderer/src/aiCore/index_new.ts @@ -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]