|
| 1 | +import type { ProviderId, ProviderType } from '@/lib/types/provider'; |
| 2 | +import type { ProviderSettings } from '@/lib/types/settings'; |
| 3 | + |
| 4 | +interface NewCustomProviderConfig { |
| 5 | + name: string; |
| 6 | + type: ProviderType; |
| 7 | + baseUrl: string; |
| 8 | + icon: string; |
| 9 | + requiresApiKey: boolean; |
| 10 | +} |
| 11 | + |
1 | 12 | export function formatContextWindow(size?: number): string { |
2 | 13 | if (!size) return '-'; |
3 | 14 |
|
@@ -26,3 +37,38 @@ export function getProviderTypeLabel(type: string, t: (key: string) => string): |
26 | 37 | // If translation exists (not equal to key), use it; otherwise fallback to type |
27 | 38 | return translated !== translationKey ? translated : type; |
28 | 39 | } |
| 40 | + |
| 41 | +export function createCustomProviderSettings( |
| 42 | + providerData: NewCustomProviderConfig, |
| 43 | +): ProviderSettings { |
| 44 | + return { |
| 45 | + apiKey: '', |
| 46 | + baseUrl: providerData.baseUrl || '', |
| 47 | + models: [], |
| 48 | + name: providerData.name, |
| 49 | + type: providerData.type, |
| 50 | + defaultBaseUrl: providerData.baseUrl || undefined, |
| 51 | + icon: providerData.icon || undefined, |
| 52 | + requiresApiKey: providerData.requiresApiKey, |
| 53 | + isBuiltIn: false, |
| 54 | + }; |
| 55 | +} |
| 56 | + |
| 57 | +interface VerifyModelRequestConfig { |
| 58 | + providerId: ProviderId; |
| 59 | + modelId: string; |
| 60 | + apiKey?: string; |
| 61 | + baseUrl?: string; |
| 62 | + providerType?: ProviderType | string; |
| 63 | + requiresApiKey?: boolean; |
| 64 | +} |
| 65 | + |
| 66 | +export function createVerifyModelRequest(config: VerifyModelRequestConfig) { |
| 67 | + return { |
| 68 | + apiKey: config.apiKey || '', |
| 69 | + baseUrl: config.baseUrl || '', |
| 70 | + model: `${config.providerId}:${config.modelId}`, |
| 71 | + providerType: config.providerType, |
| 72 | + requiresApiKey: config.requiresApiKey, |
| 73 | + }; |
| 74 | +} |
0 commit comments