mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-10 23:59:45 +08:00
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:
parent
f206d4ec4c
commit
456e6c068e
@ -12,7 +12,7 @@ import { type ProviderId, type ProviderSettingsMap } from './types'
|
|||||||
// 客户端配置接口
|
// 客户端配置接口
|
||||||
export interface ClientConfig {
|
export interface ClientConfig {
|
||||||
providerId: string
|
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(
|
static async createImageClient(
|
||||||
providerId: string,
|
providerId: string,
|
||||||
modelId: string = 'default',
|
modelId: string,
|
||||||
options: ProviderOptions
|
options: ProviderSettingsMap['openai-compatible']
|
||||||
): Promise<ImageModelV1> {
|
): Promise<ImageModelV1>
|
||||||
|
|
||||||
|
static async createImageClient(providerId: string, modelId: string = 'default', options: any): Promise<ImageModelV1> {
|
||||||
try {
|
try {
|
||||||
if (!aiProviderRegistry.isSupported(providerId)) {
|
if (!aiProviderRegistry.isSupported(providerId)) {
|
||||||
throw new ClientFactoryError(`Provider "${providerId}" is not supported`, 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)
|
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 getSupportedProviders = () => ApiClientFactory.getSupportedProviders()
|
||||||
|
|
||||||
export const getClientInfo = (providerId: string) => ApiClientFactory.getClientInfo(providerId)
|
export const getClientInfo = (providerId: string) => ApiClientFactory.getClientInfo(providerId)
|
||||||
|
|
||||||
export const createImageClient = (providerId: string, modelId?: string, options?: any) =>
|
|
||||||
ApiClientFactory.createImageClient(providerId, modelId, options)
|
|
||||||
|
|||||||
@ -38,7 +38,8 @@ function mapProviderTypeToAiSdkId(providerType: string): string {
|
|||||||
// 需要转换的映射
|
// 需要转换的映射
|
||||||
grok: 'xai', // grok -> xai
|
grok: 'xai', // grok -> xai
|
||||||
'azure-openai': 'azure', // azure-openai -> azure
|
'azure-openai': 'azure', // azure-openai -> azure
|
||||||
gemini: 'google' // gemini -> google
|
gemini: 'google', // gemini -> google
|
||||||
|
vertexai: 'google-vertex' // vertexai -> google-vertex
|
||||||
}
|
}
|
||||||
|
|
||||||
return typeMapping[providerType]
|
return typeMapping[providerType]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user