@lobehub/chat 1.16.5 → 1.16.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of @lobehub/chat might be problematic. Click here for more details.

package/CHANGELOG.md CHANGED
@@ -2,6 +2,56 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 1.16.7](https://github.com/lobehub/lobe-chat/compare/v1.16.6...v1.16.7)
6
+
7
+ <sup>Released on **2024-09-11**</sup>
8
+
9
+ #### 💄 Styles
10
+
11
+ - **misc**: Optimize model token display method.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### Styles
19
+
20
+ - **misc**: Optimize model token display method, closes [#3697](https://github.com/lobehub/lobe-chat/issues/3697) ([249795c](https://github.com/lobehub/lobe-chat/commit/249795c))
21
+
22
+ </details>
23
+
24
+ <div align="right">
25
+
26
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
27
+
28
+ </div>
29
+
30
+ ### [Version 1.16.6](https://github.com/lobehub/lobe-chat/compare/v1.16.5...v1.16.6)
31
+
32
+ <sup>Released on **2024-09-11**</sup>
33
+
34
+ #### 🐛 Bug Fixes
35
+
36
+ - **misc**: Pin `next@14.2.8` to fix Internal error.
37
+
38
+ <br/>
39
+
40
+ <details>
41
+ <summary><kbd>Improvements and Fixes</kbd></summary>
42
+
43
+ #### What's fixed
44
+
45
+ - **misc**: Pin `next@14.2.8` to fix Internal error, closes [#3905](https://github.com/lobehub/lobe-chat/issues/3905) ([1013652](https://github.com/lobehub/lobe-chat/commit/1013652))
46
+
47
+ </details>
48
+
49
+ <div align="right">
50
+
51
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
52
+
53
+ </div>
54
+
5
55
  ### [Version 1.16.5](https://github.com/lobehub/lobe-chat/compare/v1.16.4...v1.16.5)
6
56
 
7
57
  <sup>Released on **2024-09-11**</sup>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "1.16.5",
3
+ "version": "1.16.7",
4
4
  "description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
5
5
  "keywords": [
6
6
  "framework",
@@ -168,7 +168,7 @@
168
168
  "mammoth": "^1.8.0",
169
169
  "modern-screenshot": "^4.4.39",
170
170
  "nanoid": "^5.0.7",
171
- "next": "^14.2.8",
171
+ "next": "14.2.8",
172
172
  "next-auth": "5.0.0-beta.15",
173
173
  "next-sitemap": "^4.2.3",
174
174
  "numeral": "^2.0.6",
@@ -10,6 +10,7 @@ import { useTranslation } from 'react-i18next';
10
10
  import { Center, Flexbox } from 'react-layout-kit';
11
11
 
12
12
  import { ChatModelCard } from '@/types/llm';
13
+ import { formatTokenNumber } from '@/utils/format';
13
14
 
14
15
  const useStyles = createStyles(({ css, token }) => ({
15
16
  custom: css`
@@ -55,15 +56,6 @@ const useStyles = createStyles(({ css, token }) => ({
55
56
  border-radius: 4px;
56
57
  `,
57
58
  }));
58
- const formatTokenNumber = (num: number): string => {
59
- if (num > 0 && num < 1024) return '1K';
60
-
61
- let kiloToken = Math.floor(num / 1024);
62
- if (num >= 128_000 && num < 1_024_000) {
63
- kiloToken = Math.floor(num / 1000);
64
- }
65
- return kiloToken < 1000 ? `${kiloToken}K` : `${Math.floor(kiloToken / 1000)}M`;
66
- };
67
59
 
68
60
  interface ModelInfoTagsProps extends ChatModelCard {
69
61
  directionReverse?: boolean;
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, it } from 'vitest';
2
2
 
3
- import { formatSize, formatSpeed, formatTime } from './format';
3
+ import { formatSize, formatSpeed, formatTime, formatTokenNumber } from './format';
4
4
 
5
5
  describe('formatSize', () => {
6
6
  it('should format bytes to KB correctly', () => {
@@ -73,3 +73,44 @@ describe('formatTime', () => {
73
73
  expect(formatTime(3599.99)).toBe('60.0 min');
74
74
  });
75
75
  });
76
+
77
+ describe('formatTokenNumber', () => {
78
+ it('should return "1K" for numbers between 1 and 1023', () => {
79
+ expect(formatTokenNumber(500)).toBe('1K');
80
+ expect(formatTokenNumber(1000)).toBe('1K');
81
+ });
82
+
83
+ it('should format numbers between 1024 and 41,983 correctly', () => {
84
+ expect(formatTokenNumber(1024)).toBe('1K');
85
+ expect(formatTokenNumber(2000)).toBe('2K');
86
+ expect(formatTokenNumber(2048)).toBe('2K');
87
+ expect(formatTokenNumber(4000)).toBe('4K');
88
+ expect(formatTokenNumber(4096)).toBe('4K');
89
+ expect(formatTokenNumber(32000)).toBe('32K');
90
+ expect(formatTokenNumber(65536)).toBe('64K');
91
+ });
92
+
93
+ it('should format numbers between 41,984 and 127,999 correctly', () => {
94
+ expect(formatTokenNumber(41984)).toBe('41K');
95
+ expect(formatTokenNumber(100000)).toBe('97K');
96
+ expect(formatTokenNumber(127999)).toBe('124K');
97
+ });
98
+
99
+ it('should return "128K" for 131,072', () => {
100
+ expect(formatTokenNumber(131072)).toBe('128K'); // Qwen
101
+ });
102
+
103
+ it('should format numbers between 128,000 and 999,999 correctly', () => {
104
+ expect(formatTokenNumber(128000)).toBe('128K');
105
+ expect(formatTokenNumber(200000)).toBe('200K'); // Claude
106
+ expect(formatTokenNumber(999999)).toBe('999K');
107
+ });
108
+
109
+ it('should format numbers 1,000,000 and above correctly', () => {
110
+ expect(formatTokenNumber(1000000)).toBe('1M');
111
+ expect(formatTokenNumber(1024000)).toBe('1M');
112
+ expect(formatTokenNumber(1048576)).toBe('1M'); // Gemini Flash
113
+ expect(formatTokenNumber(2000000)).toBe('2M');
114
+ expect(formatTokenNumber(2097152)).toBe('2M'); // Gemini Pro
115
+ });
116
+ });
@@ -54,3 +54,14 @@ export const formatTime = (timeInSeconds: number): string => {
54
54
  export const formatNumber = (num: any) => {
55
55
  return new Intl.NumberFormat('en-US').format(num);
56
56
  };
57
+
58
+ export const formatTokenNumber = (num: number): string => {
59
+ if (num > 0 && num < 1024) return '1K';
60
+
61
+ let kiloToken = Math.floor(num / 1024);
62
+ if (num >= 1024 && num < 1024 * 41 || num >= 128_000) {
63
+ kiloToken = Math.floor(num / 1000);
64
+ }
65
+ if (num === 131_072) return '128K';
66
+ return kiloToken < 1000 ? `${kiloToken}K` : `${Math.floor(kiloToken / 1000)}M`;
67
+ };