@lobehub/chat 0.5.0 → 0.6.1

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,64 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 0.6.1](https://github.com/lobehub/lobe-chat/compare/v0.6.0...v0.6.1)
6
+
7
+ <sup>Released on **2023-07-22**</sup>
8
+
9
+ #### 🐛 Bug Fixes
10
+
11
+ - **misc**: Add deps.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's fixed
19
+
20
+ - **misc**: Add deps ([3dc45fe](https://github.com/lobehub/lobe-chat/commit/3dc45fe))
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 0.6.0](https://github.com/lobehub/lobe-chat/compare/v0.5.0...v0.6.0)
31
+
32
+ <sup>Released on **2023-07-22**</sup>
33
+
34
+ #### ♻ Code Refactoring
35
+
36
+ - **misc**: 重构 selector 文件组织.
37
+
38
+ #### ✨ Features
39
+
40
+ - **misc**: 补充 token 详情.
41
+
42
+ <br/>
43
+
44
+ <details>
45
+ <summary><kbd>Improvements and Fixes</kbd></summary>
46
+
47
+ #### Code refactoring
48
+
49
+ - **misc**: 重构 selector 文件组织 ([2ad0ef9](https://github.com/lobehub/lobe-chat/commit/2ad0ef9))
50
+
51
+ #### What's improved
52
+
53
+ - **misc**: 补充 token 详情 ([098f7ff](https://github.com/lobehub/lobe-chat/commit/098f7ff))
54
+
55
+ </details>
56
+
57
+ <div align="right">
58
+
59
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
60
+
61
+ </div>
62
+
5
63
  ## [Version 0.5.0](https://github.com/lobehub/lobe-chat/compare/v0.4.3...v0.5.0)
6
64
 
7
65
  <sup>Released on **2023-07-22**</sup>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
4
4
  "description": "Lobe Chat is an open-source chatbot client using LangChain, Typescript and Next.js",
5
5
  "keywords": [
6
6
  "chatbot",
@@ -71,6 +71,7 @@
71
71
  "antd-style": "^3",
72
72
  "brotli-wasm": "^1",
73
73
  "chroma-js": "^2",
74
+ "emoji-mart": "^5",
74
75
  "fast-deep-equal": "^3",
75
76
  "gpt-tokenizer": "^2",
76
77
  "i18next": "^23",
@@ -12,10 +12,13 @@ export default {
12
12
  'agentTag': '标签',
13
13
  'agentTagPlaceholder': '请输入标签',
14
14
  'archive': '归档',
15
+ 'archiveCurrentMessages': '归档当前会话',
15
16
  'autoGenerate': '自动补全',
16
17
  'autoGenerateTooltip': '基于提示词自动补全助手描述',
17
18
  'cancel': '取消',
19
+ 'clearCurrentMessages': '清空当前会话消息',
18
20
  'close': '关闭',
21
+ 'confirmClearCurrentMessages': '即将清空当前会话消息,清空后将无法找回,请确认你的操作',
19
22
  'confirmRemoveSessionItemAlert': '即将删除该助手,删除后该将无法找回,请确认你的操作',
20
23
  'defaultAgent': '默认助手',
21
24
  'edit': '编辑',
@@ -36,6 +39,7 @@ export default {
36
39
  'sessionSetting': '会话设置',
37
40
  'setting': '设置',
38
41
  'share': '分享',
42
+ 'tokenDetail': '系统设定: {{systemRoleToken}} 历史消息: {{chatsToken}}',
39
43
  'updateAgent': '更新助理信息',
40
44
  'updatePrompt': '更新提示词',
41
45
  };
@@ -1,8 +1,9 @@
1
- import { ActionIcon, ChatInputArea, DraggablePanel, Icon, TokenTag } from '@lobehub/ui';
2
- import { Button } from 'antd';
1
+ import { ActionIcon, ChatInputArea, DraggablePanel, Icon, TokenTag, Tooltip } from '@lobehub/ui';
2
+ import { Button, Popconfirm } from 'antd';
3
3
  import { encode } from 'gpt-tokenizer';
4
4
  import { Archive, Eraser, Languages } from 'lucide-react';
5
5
  import { memo, useMemo, useState } from 'react';
6
+ import { useTranslation } from 'react-i18next';
6
7
  import { shallow } from 'zustand/shallow';
7
8
 
8
9
  import { CHAT_TEXTAREA_HEIGHT, HEADER_HEIGHT } from '@/const/layoutTokens';
@@ -11,20 +12,24 @@ import { agentSelectors, chatSelectors, useSessionStore } from '@/store/session'
11
12
  import { useSettings } from '@/store/settings';
12
13
 
13
14
  const ChatInput = () => {
15
+ const { t } = useTranslation();
14
16
  const [expand, setExpand] = useState<boolean>(false);
15
17
  const [text, setText] = useState('');
16
- const textTokenCount = useMemo(() => encode(text).length, [text]);
18
+ const inputTokenCount = useMemo(() => encode(text).length, [text]);
17
19
 
18
20
  const [inputHeight] = useSettings((s) => [s.inputHeight], shallow);
19
- const [totalToken, model, sendMessage, clearMessage] = useSessionStore(
20
- (s) => [
21
- chatSelectors.totalTokenCount(s),
22
- agentSelectors.currentAgentModel(s),
23
- s.createOrSendMsg,
24
- s.clearMessage,
25
- ],
26
- shallow,
27
- );
21
+ const [totalToken, systemRoleToken, chatsToken, model, sendMessage, clearMessage] =
22
+ useSessionStore(
23
+ (s) => [
24
+ chatSelectors.totalTokenCount(s),
25
+ chatSelectors.systemRoleTokenCount(s),
26
+ chatSelectors.chatsTokenCount(s),
27
+ agentSelectors.currentAgentModel(s),
28
+ s.createOrSendMsg,
29
+ s.clearMessage,
30
+ ],
31
+ shallow,
32
+ );
28
33
 
29
34
  return (
30
35
  <DraggablePanel
@@ -46,12 +51,16 @@ const ChatInput = () => {
46
51
  actions={
47
52
  <>
48
53
  <ActionIcon icon={Languages} />
49
- <ActionIcon icon={Eraser} onClick={clearMessage} />
50
- <TokenTag maxValue={ModelTokens[model]} value={totalToken + textTokenCount} />
54
+ <Popconfirm onConfirm={() => clearMessage()} title={t('confirmClearCurrentMessages')}>
55
+ <ActionIcon icon={Eraser} title={t('clearCurrentMessages')} />
56
+ </Popconfirm>
57
+ <Tooltip title={t('tokenDetail', { chatsToken, systemRoleToken })}>
58
+ <TokenTag maxValue={ModelTokens[model]} value={totalToken + inputTokenCount} />
59
+ </Tooltip>
51
60
  </>
52
61
  }
53
62
  expand={expand}
54
- footer={<Button icon={<Icon icon={Archive} />} />}
63
+ footer={<Button icon={<Icon icon={Archive} title={t('archiveCurrentMessages')} />} />}
55
64
  minHeight={CHAT_TEXTAREA_HEIGHT}
56
65
  onExpandChange={setExpand}
57
66
  onInputChange={setText}
@@ -1,13 +1,11 @@
1
- import { encode } from 'gpt-tokenizer';
2
-
3
1
  import { agentSelectors } from '@/store/session';
4
2
  import { ChatMessage } from '@/types/chatMessage';
5
3
 
6
- import type { SessionStore } from '../../store';
7
- import { sessionSelectors } from '../session';
4
+ import type { SessionStore } from '../../../store';
5
+ import { sessionSelectors } from '../../session';
8
6
 
9
7
  // 展示在聊天框中的消息
10
- const currentChats = (s: SessionStore): ChatMessage[] => {
8
+ export const currentChats = (s: SessionStore): ChatMessage[] => {
11
9
  const session = sessionSelectors.currentSession(s);
12
10
  if (!session) return [];
13
11
 
@@ -53,30 +51,8 @@ const currentChats = (s: SessionStore): ChatMessage[] => {
53
51
  return finalList;
54
52
  };
55
53
 
56
- const systemRoleSel = (s: SessionStore): string => {
54
+ export const systemRoleSel = (s: SessionStore): string => {
57
55
  const config = agentSelectors.currentAgentConfigSafe(s);
58
56
 
59
57
  return config.systemRole;
60
58
  };
61
-
62
- const systemRoleTokens = (s: SessionStore): number[] => {
63
- const systemRole = systemRoleSel(s);
64
-
65
- return encode(systemRole || '');
66
- };
67
-
68
- const chatsTokens = (s: SessionStore): number[] => {
69
- const chats = currentChats(s);
70
- return encode(chats.map((m) => m.content).join(''));
71
- };
72
-
73
- const systemRoleTokenCount = (s: SessionStore) => systemRoleTokens(s).length;
74
-
75
- const totalTokenCount = (s: SessionStore) => chatsTokens(s).length + systemRoleTokenCount(s);
76
-
77
- export const chatSelectors = {
78
- currentChats,
79
- systemRoleTokenCount,
80
- systemRoleTokens,
81
- totalTokenCount,
82
- };
@@ -0,0 +1,9 @@
1
+ import { currentChats } from './chat';
2
+ import { chatsTokenCount, systemRoleTokenCount, totalTokenCount } from './token';
3
+
4
+ export const chatSelectors = {
5
+ chatsTokenCount,
6
+ currentChats,
7
+ systemRoleTokenCount,
8
+ totalTokenCount,
9
+ };
@@ -0,0 +1,21 @@
1
+ import { encode } from 'gpt-tokenizer';
2
+
3
+ import type { SessionStore } from '../../../store';
4
+ import { currentChats, systemRoleSel } from './chat';
5
+
6
+ const systemRoleTokens = (s: SessionStore): number[] => {
7
+ const systemRole = systemRoleSel(s);
8
+
9
+ return encode(systemRole || '');
10
+ };
11
+
12
+ const chatsTokens = (s: SessionStore): number[] => {
13
+ const chats = currentChats(s);
14
+ return encode(chats.map((m) => m.content).join(''));
15
+ };
16
+
17
+ export const chatsTokenCount = (s: SessionStore) => chatsTokens(s).length;
18
+
19
+ export const systemRoleTokenCount = (s: SessionStore) => systemRoleTokens(s).length;
20
+
21
+ export const totalTokenCount = (s: SessionStore) => chatsTokens(s).length + systemRoleTokenCount(s);