utils.ts 864 B

12345678910111213141516171819202122232425262728
  1. export function formatContextWindow(size?: number): string {
  2. if (!size) return '-';
  3. // For M: prefer decimal (use decimal for exact thousands)
  4. if (size >= 1000000) {
  5. if (size % 1000000 === 0) {
  6. return `${size / 1000000}M`;
  7. }
  8. return `${(size / 1000000).toFixed(1)}M`;
  9. }
  10. // For K: prefer decimal if divisible by 1000, otherwise use binary
  11. if (size >= 1000) {
  12. if (size % 1000 === 0) {
  13. return `${size / 1000}K`;
  14. }
  15. return `${Math.floor(size / 1024)}K`;
  16. }
  17. return size.toString();
  18. }
  19. export function getProviderTypeLabel(type: string, t: (key: string) => string): string {
  20. const translationKey = `settings.providerTypes.${type}`;
  21. const translated = t(translationKey);
  22. // If translation exists (not equal to key), use it; otherwise fallback to type
  23. return translated !== translationKey ? translated : type;
  24. }