Spaces:
Sleeping
Sleeping
File size: 733 Bytes
9fdb075 32aacff 9fdb075 32aacff 9fdb075 32aacff 9fdb075 32aacff 9fdb075 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | /**
* Code Retry Service - OpenAI 客户端管理
*/
import OpenAI from 'openai'
import type { CustomApiConfig } from '../../types'
import {
createCustomOpenAIClient,
initializeDefaultOpenAIClient
} from '../openai-client-factory'
const defaultClient: OpenAI | null = initializeDefaultOpenAIClient((error) => {
console.warn('[CodeRetry] OpenAI 客户端初始化失败', error)
})
/**
* 获取 OpenAI 客户端
*/
export function getClient(customApiConfig?: CustomApiConfig): OpenAI | null {
if (customApiConfig) {
return createCustomOpenAIClient(customApiConfig)
}
return defaultClient
}
/**
* 检查客户端是否可用
*/
export function isClientAvailable(): boolean {
return defaultClient !== null
}
|