Spaces:
Sleeping
Sleeping
Sync from enhance: d795216 feat: implement patch response parser for search and replace functionality
9bd4242 | import type { CustomApiConfig } from '../types' | |
| export function isGoogleOpenAICompatApiUrl(apiUrl: string): boolean { | |
| const normalized = apiUrl.trim().toLowerCase() | |
| return normalized.includes('generativelanguage.googleapis.com') || normalized.includes('/v1beta/openai') | |
| } | |
| export function normalizeModelForApiUrl(apiUrl: string, model: string): string { | |
| const normalizedModel = (model || '').trim() | |
| if (!normalizedModel) { | |
| return '' | |
| } | |
| if (isGoogleOpenAICompatApiUrl(apiUrl)) { | |
| return normalizedModel.replace(/^models\//i, '') | |
| } | |
| return normalizedModel | |
| } | |
| export function normalizeCustomApiConfig(config: CustomApiConfig): CustomApiConfig { | |
| const apiUrl = (config.apiUrl || '').trim().replace(/\/+$/, '') | |
| const apiKeyPool = Array.isArray(config.apiKeyPool) | |
| ? config.apiKeyPool | |
| .map((item) => item.trim()) | |
| .filter((item) => item.length > 0) | |
| : undefined | |
| const apiKey = (config.apiKey || '').trim() || apiKeyPool?.[0] || '' | |
| return { | |
| ...config, | |
| apiUrl, | |
| apiKey, | |
| apiKeyPool, | |
| model: normalizeModelForApiUrl(apiUrl, config.model || ''), | |
| rotationGroupId: (config.rotationGroupId || '').trim() || undefined, | |
| rotationMode: config.rotationMode === 'round-robin' ? 'round-robin' : undefined | |
| } | |
| } | |