Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from lobehub:main #85

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@

# Changelog

### [Version 1.16.7](https://github.com/lobehub/lobe-chat/compare/v1.16.6...v1.16.7)

<sup>Released on **2024-09-11**</sup>

#### 💄 Styles

- **misc**: Optimize model token display method.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### Styles

- **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))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>

### [Version 1.16.6](https://github.com/lobehub/lobe-chat/compare/v1.16.5...v1.16.6)

<sup>Released on **2024-09-11**</sup>
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,14 @@ Our marketplace is not just a showcase platform but also a collaborative space.

<!-- AGENT LIST -->

| Recent Submits | Description |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [AI Agent Generator](https://chat-preview.lobehub.com/market?agent=ai-agent-generator)<br/><sup>By **[xyftw](https://github.com/xyftw)** on **2024-09-10**</sup> | Skilled at creating AI Agent character descriptions that meet the needs.<br/>`ai-agent` `character-creation` |
| [Desolate Friend](https://chat-preview.lobehub.com/market?agent=meu)<br/><sup>By **[adminewacc](https://github.com/adminewacc)** on **2024-09-10**</sup> | Skilled at comforting and supporting friends<br/>`friendship` `sadness` `support` |
| [NetMaster](https://chat-preview.lobehub.com/market?agent=net-master)<br/><sup>By **[erhuoyan](https://github.com/erhuoyan)** on **2024-09-10**</sup> | Network Engineer: Professional network topology construction and management<br/>`network-engineer` `network-configuration` `network-management` `network-topology` `network-security` |
| [HTML to React](https://chat-preview.lobehub.com/market?agent=web-react)<br/><sup>By **[xingwang02](https://github.com/xingwang02)** on **2024-09-10**</sup> | Input HTML snippets and convert them into React components<br/>`react` `html` |

> 📊 Total agents: [<kbd>**327**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
| Recent Submits | Description |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Resume Analysis Expert](https://chat-preview.lobehub.com/market?agent=resume-analyzer)<br/><sup>By **[Pandurangmopgar](https://github.com/Pandurangmopgar)** on **2024-09-11**</sup> | Expert AI assistant for comprehensive resume analysis and job-specific optimization. Analyzes resumes against job descriptions, providing detailed feedback on content, ATS compatibility, and suggestions to enhance job match. Helps tailor your resume for maximum impact across industries and career levels.<br/>`resume` `career` `job-search` `ats` `cv` `analysis` `optimization` `professional-development` `interview-prep` |
| [AI Agent Generator](https://chat-preview.lobehub.com/market?agent=ai-agent-generator)<br/><sup>By **[xyftw](https://github.com/xyftw)** on **2024-09-10**</sup> | Skilled at creating AI Agent character descriptions that meet the needs.<br/>`ai-agent` `character-creation` |
| [Desolate Friend](https://chat-preview.lobehub.com/market?agent=meu)<br/><sup>By **[adminewacc](https://github.com/adminewacc)** on **2024-09-10**</sup> | Skilled at comforting and supporting friends<br/>`friendship` `sadness` `support` |
| [NetMaster](https://chat-preview.lobehub.com/market?agent=net-master)<br/><sup>By **[erhuoyan](https://github.com/erhuoyan)** on **2024-09-10**</sup> | Network Engineer: Professional network topology construction and management<br/>`network-engineer` `network-configuration` `network-management` `network-topology` `network-security` |

> 📊 Total agents: [<kbd>**328**</kbd> ](https://github.com/lobehub/lobe-chat-agents)

<!-- AGENT LIST -->

Expand Down
16 changes: 8 additions & 8 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,14 @@ LobeChat 的插件生态系统是其核心功能的重要扩展,它极大地

<!-- AGENT LIST -->

| 最近新增 | 助手说明 |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------- |
| [AI 代理生成器](https://chat-preview.lobehub.com/market?agent=ai-agent-generator)<br/><sup>By **[xyftw](https://github.com/xyftw)** on **2024-09-10**</sup> | 擅长创建满足需求的 AI 代理角色描述。<br/>`ai-agent` `角色创建` |
| [孤独的朋友](https://chat-preview.lobehub.com/market?agent=meu)<br/><sup>By **[adminewacc](https://github.com/adminewacc)** on **2024-09-10**</sup> | 擅长安慰和支持朋友<br/>`友谊` `悲伤` `支持` |
| [NetMaster](https://chat-preview.lobehub.com/market?agent=net-master)<br/><sup>By **[erhuoyan](https://github.com/erhuoyan)** on **2024-09-10**</sup> | 网络工程师:专业网络拓扑搭建与管理<br/>`网络工程师` `网络配置` `网络管理` `网络拓扑` `网络安全` |
| [HTML to React](https://chat-preview.lobehub.com/market?agent=web-react)<br/><sup>By **[xingwang02](https://github.com/xingwang02)** on **2024-09-10**</sup> | 输入 HTML 片段,转化为 React 组件<br/>`react、-html` |

> 📊 Total agents: [<kbd>**327**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
| 最近新增 | 助手说明 |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [简历分析专家](https://chat-preview.lobehub.com/market?agent=resume-analyzer)<br/><sup>By **[Pandurangmopgar](https://github.com/Pandurangmopgar)** on **2024-09-11**</sup> | 专家级 AI 助手,提供全面的简历分析和职位特定优化。根据职位描述分析简历,提供关于内容、ATS 兼容性和增强职位匹配的详细反馈。帮助您量身定制简历,以在各行业和职业层次上产生最大影响。<br/>`简历` `职业` `求职` `ats` `cv` `分析` `优化` `职业发展` `面试准备` |
| [AI 代理生成器](https://chat-preview.lobehub.com/market?agent=ai-agent-generator)<br/><sup>By **[xyftw](https://github.com/xyftw)** on **2024-09-10**</sup> | 擅长创建满足需求的 AI 代理角色描述。<br/>`ai-agent` `角色创建` |
| [孤独的朋友](https://chat-preview.lobehub.com/market?agent=meu)<br/><sup>By **[adminewacc](https://github.com/adminewacc)** on **2024-09-10**</sup> | 擅长安慰和支持朋友<br/>`友谊` `悲伤` `支持` |
| [NetMaster](https://chat-preview.lobehub.com/market?agent=net-master)<br/><sup>By **[erhuoyan](https://github.com/erhuoyan)** on **2024-09-10**</sup> | 网络工程师:专业网络拓扑搭建与管理<br/>`网络工程师` `网络配置` `网络管理` `网络拓扑` `网络安全` |

> 📊 Total agents: [<kbd>**328**</kbd> ](https://github.com/lobehub/lobe-chat-agents)

<!-- AGENT LIST -->

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lobehub/chat",
"version": "1.16.6",
"version": "1.16.7",
"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.",
"keywords": [
"framework",
Expand Down
10 changes: 1 addition & 9 deletions src/components/ModelSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useTranslation } from 'react-i18next';
import { Center, Flexbox } from 'react-layout-kit';

import { ChatModelCard } from '@/types/llm';
import { formatTokenNumber } from '@/utils/format';

const useStyles = createStyles(({ css, token }) => ({
custom: css`
Expand Down Expand Up @@ -55,15 +56,6 @@ const useStyles = createStyles(({ css, token }) => ({
border-radius: 4px;
`,
}));
const formatTokenNumber = (num: number): string => {
if (num > 0 && num < 1024) return '1K';

let kiloToken = Math.floor(num / 1024);
if (num >= 128_000 && num < 1_024_000) {
kiloToken = Math.floor(num / 1000);
}
return kiloToken < 1000 ? `${kiloToken}K` : `${Math.floor(kiloToken / 1000)}M`;
};

interface ModelInfoTagsProps extends ChatModelCard {
directionReverse?: boolean;
Expand Down
43 changes: 42 additions & 1 deletion src/utils/format.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';

import { formatSize, formatSpeed, formatTime } from './format';
import { formatSize, formatSpeed, formatTime, formatTokenNumber } from './format';

describe('formatSize', () => {
it('should format bytes to KB correctly', () => {
Expand Down Expand Up @@ -73,3 +73,44 @@ describe('formatTime', () => {
expect(formatTime(3599.99)).toBe('60.0 min');
});
});

describe('formatTokenNumber', () => {
it('should return "1K" for numbers between 1 and 1023', () => {
expect(formatTokenNumber(500)).toBe('1K');
expect(formatTokenNumber(1000)).toBe('1K');
});

it('should format numbers between 1024 and 41,983 correctly', () => {
expect(formatTokenNumber(1024)).toBe('1K');
expect(formatTokenNumber(2000)).toBe('2K');
expect(formatTokenNumber(2048)).toBe('2K');
expect(formatTokenNumber(4000)).toBe('4K');
expect(formatTokenNumber(4096)).toBe('4K');
expect(formatTokenNumber(32000)).toBe('32K');
expect(formatTokenNumber(65536)).toBe('64K');
});

it('should format numbers between 41,984 and 127,999 correctly', () => {
expect(formatTokenNumber(41984)).toBe('41K');
expect(formatTokenNumber(100000)).toBe('97K');
expect(formatTokenNumber(127999)).toBe('124K');
});

it('should return "128K" for 131,072', () => {
expect(formatTokenNumber(131072)).toBe('128K'); // Qwen
});

it('should format numbers between 128,000 and 999,999 correctly', () => {
expect(formatTokenNumber(128000)).toBe('128K');
expect(formatTokenNumber(200000)).toBe('200K'); // Claude
expect(formatTokenNumber(999999)).toBe('999K');
});

it('should format numbers 1,000,000 and above correctly', () => {
expect(formatTokenNumber(1000000)).toBe('1M');
expect(formatTokenNumber(1024000)).toBe('1M');
expect(formatTokenNumber(1048576)).toBe('1M'); // Gemini Flash
expect(formatTokenNumber(2000000)).toBe('2M');
expect(formatTokenNumber(2097152)).toBe('2M'); // Gemini Pro
});
});
11 changes: 11 additions & 0 deletions src/utils/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,14 @@ export const formatTime = (timeInSeconds: number): string => {
export const formatNumber = (num: any) => {
return new Intl.NumberFormat('en-US').format(num);
};

export const formatTokenNumber = (num: number): string => {
if (num > 0 && num < 1024) return '1K';

let kiloToken = Math.floor(num / 1024);
if (num >= 1024 && num < 1024 * 41 || num >= 128_000) {
kiloToken = Math.floor(num / 1000);
}
if (num === 131_072) return '128K';
return kiloToken < 1000 ? `${kiloToken}K` : `${Math.floor(kiloToken / 1000)}M`;
};
Loading