| import type { ProviderId, ProviderType } from '@/lib/types/provider'; |
| import type { ProviderSettings } from '@/lib/types/settings'; |
|
|
| interface NewCustomProviderConfig { |
| name: string; |
| type: ProviderType; |
| baseUrl: string; |
| icon: string; |
| requiresApiKey: boolean; |
| } |
|
|
| export function formatContextWindow(size?: number): string { |
| if (!size) return '-'; |
|
|
| |
| if (size >= 1000000) { |
| if (size % 1000000 === 0) { |
| return `${size / 1000000}M`; |
| } |
| return `${(size / 1000000).toFixed(1)}M`; |
| } |
|
|
| |
| if (size >= 1000) { |
| if (size % 1000 === 0) { |
| return `${size / 1000}K`; |
| } |
| return `${Math.floor(size / 1024)}K`; |
| } |
|
|
| return size.toString(); |
| } |
|
|
| export function getProviderTypeLabel(type: string, t: (key: string) => string): string { |
| const translationKey = `settings.providerTypes.${type}`; |
| const translated = t(translationKey); |
| |
| return translated !== translationKey ? translated : type; |
| } |
|
|
| export function createCustomProviderSettings( |
| providerData: NewCustomProviderConfig, |
| ): ProviderSettings { |
| return { |
| apiKey: '', |
| baseUrl: providerData.baseUrl || '', |
| models: [], |
| name: providerData.name, |
| type: providerData.type, |
| defaultBaseUrl: providerData.baseUrl || undefined, |
| icon: providerData.icon || undefined, |
| requiresApiKey: providerData.requiresApiKey, |
| isBuiltIn: false, |
| }; |
| } |
|
|
| interface VerifyModelRequestConfig { |
| providerId: ProviderId; |
| modelId: string; |
| apiKey?: string; |
| baseUrl?: string; |
| providerType?: ProviderType | string; |
| requiresApiKey?: boolean; |
| } |
|
|
| export function createVerifyModelRequest(config: VerifyModelRequestConfig) { |
| return { |
| apiKey: config.apiKey || '', |
| baseUrl: config.baseUrl || '', |
| model: `${config.providerId}:${config.modelId}`, |
| providerType: config.providerType, |
| requiresApiKey: config.requiresApiKey, |
| }; |
| } |
|
|