@lobehub/chat 0.4.3 → 0.5.0

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,39 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ## [Version 0.5.0](https://github.com/lobehub/lobe-chat/compare/v0.4.3...v0.5.0)
6
+
7
+ <sup>Released on **2023-07-22**</sup>
8
+
9
+ #### ✨ Features
10
+
11
+ - **misc**: 支持选择 Emoji.
12
+
13
+ #### 🐛 Bug Fixes
14
+
15
+ - **misc**: 修正 total token 计算不正确的问题.
16
+
17
+ <br/>
18
+
19
+ <details>
20
+ <summary><kbd>Improvements and Fixes</kbd></summary>
21
+
22
+ #### What's improved
23
+
24
+ - **misc**: 支持选择 Emoji ([6cb4828](https://github.com/lobehub/lobe-chat/commit/6cb4828))
25
+
26
+ #### What's fixed
27
+
28
+ - **misc**: 修正 total token 计算不正确的问题 ([17815c6](https://github.com/lobehub/lobe-chat/commit/17815c6))
29
+
30
+ </details>
31
+
32
+ <div align="right">
33
+
34
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
35
+
36
+ </div>
37
+
5
38
  ### [Version 0.4.3](https://github.com/lobehub/lobe-chat/compare/v0.4.2...v0.4.3)
6
39
 
7
40
  <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.4.3",
3
+ "version": "0.5.0",
4
4
  "description": "Lobe Chat is an open-source chatbot client using LangChain, Typescript and Next.js",
5
5
  "keywords": [
6
6
  "chatbot",
@@ -61,6 +61,8 @@
61
61
  "@ant-design/colors": "^7",
62
62
  "@ant-design/icons": "^5",
63
63
  "@commitlint/cli": "^17",
64
+ "@emoji-mart/data": "^1",
65
+ "@emoji-mart/react": "^1",
64
66
  "@lobehub/ui": "^1",
65
67
  "@vercel/analytics": "^1",
66
68
  "ahooks": "^3",
@@ -1,4 +1,4 @@
1
- import { Collapse, InputNumber, Segmented, Slider } from 'antd';
1
+ import { Collapse, ConfigProvider, InputNumber, Segmented, Slider } from 'antd';
2
2
  import isEqual from 'fast-deep-equal';
3
3
  import { useTranslation } from 'react-i18next';
4
4
  import { Flexbox } from 'react-layout-kit';
@@ -21,7 +21,15 @@ const AgentConfig = () => {
21
21
  const [updateAgentConfig] = useSessionStore((s) => [s.updateAgentConfig], shallow);
22
22
 
23
23
  return (
24
- <>
24
+ <ConfigProvider
25
+ theme={{
26
+ components: {
27
+ Segmented: {
28
+ colorBgLayout: theme.isDarkMode ? '#111' : '#f1f1f1',
29
+ },
30
+ },
31
+ }}
32
+ >
25
33
  <Flexbox
26
34
  align={'center'}
27
35
  distribution={'space-between'}
@@ -87,8 +95,8 @@ const AgentConfig = () => {
87
95
  },
88
96
  ]}
89
97
  />
90
- </Flexbox>
91
- </>
98
+ </Flexbox>{' '}
99
+ </ConfigProvider>
92
100
  );
93
101
  };
94
102
 
@@ -0,0 +1,74 @@
1
+ import data from '@emoji-mart/data';
2
+ import i18n from '@emoji-mart/data/i18n/zh.json';
3
+ import Picker from '@emoji-mart/react';
4
+ import { Avatar } from '@lobehub/ui';
5
+ import { Popover } from 'antd';
6
+ import { createStyles } from 'antd-style';
7
+ import chroma from 'chroma-js';
8
+ import { memo } from 'react';
9
+ import { shallow } from 'zustand/shallow';
10
+
11
+ import { useSessionStore } from '@/store/session';
12
+ import { agentSelectors } from '@/store/session/selectors';
13
+
14
+ const useStyles = createStyles(({ css, token, prefixCls }) => ({
15
+ avatar: css`
16
+ border-radius: 50%;
17
+ transition: scale 400ms ${token.motionEaseOut}, box-shadow 100ms ${token.motionEaseOut};
18
+
19
+ &:hover {
20
+ box-shadow: 0 0 0 3px ${token.colorText};
21
+ }
22
+
23
+ &:active {
24
+ scale: 0.8;
25
+ }
26
+ `,
27
+ picker: css`
28
+ em-emoji-picker {
29
+ --rgb-accent: ${chroma(token.colorPrimary) .rgb() .join(',')};
30
+ --shadow: none;
31
+ }
32
+ `,
33
+ popover: css`
34
+ .${prefixCls}-popover-inner {
35
+ padding: 0;
36
+ }
37
+ `,
38
+ }));
39
+
40
+ const EmojiPicker = () => {
41
+ const { styles } = useStyles();
42
+ const [avatar, updateAgentMeta] = useSessionStore(
43
+ (s) => [agentSelectors.currentAgentAvatar(s), s.updateAgentMeta],
44
+ shallow,
45
+ );
46
+
47
+ return (
48
+ <Popover
49
+ content={
50
+ <div className={styles.picker}>
51
+ <Picker
52
+ data={data}
53
+ i18n={i18n}
54
+ locale={'zh'}
55
+ onEmojiSelect={(e: any) => {
56
+ updateAgentMeta({ avatar: e.native });
57
+ }}
58
+ skinTonePosition={'none'}
59
+ theme={'auto'}
60
+ />
61
+ </div>
62
+ }
63
+ placement={'left'}
64
+ rootClassName={styles.popover}
65
+ trigger={'click'}
66
+ >
67
+ <div className={styles.avatar} style={{ width: 'fit-content' }}>
68
+ <Avatar avatar={avatar} size={200} />
69
+ </div>
70
+ </Popover>
71
+ );
72
+ };
73
+
74
+ export default memo(EmojiPicker);
@@ -1,4 +1,4 @@
1
- import { ActionIcon, Avatar, Input, Tooltip } from '@lobehub/ui';
1
+ import { ActionIcon, Input, Tooltip } from '@lobehub/ui';
2
2
  import { Button, Collapse } from 'antd';
3
3
  import isEqual from 'fast-deep-equal';
4
4
  import { LucideSparkles } from 'lucide-react';
@@ -10,6 +10,7 @@ import { agentSelectors, useSessionStore } from '@/store/session';
10
10
 
11
11
  import { FormItem } from '../FormItem';
12
12
  import { useStyles } from '../style';
13
+ import EmojiPicker from './EmojiPicker';
13
14
 
14
15
  const AgentMeta = () => {
15
16
  const { t } = useTranslation('common');
@@ -83,7 +84,7 @@ const AgentMeta = () => {
83
84
  ))}
84
85
  </Flexbox>
85
86
  <FormItem label={t('agentAvatar')}>
86
- <Avatar avatar={metaData.avatar} size={200} />
87
+ <EmojiPicker />
87
88
  </FormItem>
88
89
  </Flexbox>
89
90
  ),
@@ -35,15 +35,25 @@ export const promptSummaryAgentName = (content: string): Partial<OpenAIStreamPay
35
35
  export const promptPickEmoji = (content: string): Partial<OpenAIStreamPayload> => ({
36
36
  messages: [
37
37
  {
38
- content: `你是一名非常懂设计与时尚的设计师,你需要从用户的描述中匹配一个合适的 emoji。
39
- 输入:你是一名精通体验设计的设计系统设计师,设计系统存在诸多类别的 token,比如品牌色、成功色等,你需要为各个类别的 token 提供说明文案。
40
- 输出: 💅
41
-
42
- 输入:用户会输入一串 ts 代码,为了确保所有功能和分支的 100% 的覆盖率,你需要给出需要考虑哪些数据场景。
43
- 输出: 🧪
44
- `,
38
+ content: '你是一名非常懂设计与时尚的设计师,你需要从用户的描述中匹配一个合适的 emoji。',
45
39
  role: 'system',
46
40
  },
41
+ {
42
+ content: `输入:你是一名精通体验设计的设计系统设计师,设计系统存在诸多类别的 token,比如品牌色、成功色等,你需要为各个类别的 token 提供说明文案。`,
43
+ role: 'user',
44
+ },
45
+ {
46
+ content: `💅`,
47
+ role: 'assistant',
48
+ },
49
+ {
50
+ content: `输入:用户会输入一串 ts 代码,为了确保所有功能和分支的 100% 的覆盖率,你需要给出需要考虑哪些数据场景。`,
51
+ role: 'user',
52
+ },
53
+ {
54
+ content: `🧪`,
55
+ role: 'assistant',
56
+ },
47
57
  {
48
58
  content: `输入:${content}`,
49
59
  role: 'user',
@@ -54,11 +64,12 @@ export const promptPickEmoji = (content: string): Partial<OpenAIStreamPayload> =
54
64
  export const promptSummaryDescription = (content: string): Partial<OpenAIStreamPayload> => ({
55
65
  messages: [
56
66
  {
57
- content: '你是一名擅长会话的助理,你需要将用户的提示词做一个3句话以内的总结。',
67
+ content:
68
+ '你是一名擅长会话的助理,你需要将用户的输入的内容总结为一个专家的简介,不超过 20 个字',
58
69
  role: 'system',
59
70
  },
60
71
  {
61
- content: `输入:${content}`,
72
+ content: `${content}`,
62
73
  role: 'user',
63
74
  },
64
75
  ],
@@ -59,25 +59,24 @@ const systemRoleSel = (s: SessionStore): string => {
59
59
  return config.systemRole;
60
60
  };
61
61
 
62
- const totalTokens = (s: SessionStore): number[] => {
63
- const chats = currentChats(s);
64
- return encode(chats.map((m) => m.content).join(''));
65
- };
66
-
67
62
  const systemRoleTokens = (s: SessionStore): number[] => {
68
63
  const systemRole = systemRoleSel(s);
69
64
 
70
65
  return encode(systemRole || '');
71
66
  };
72
67
 
73
- const totalTokenCount = (s: SessionStore) => totalTokens(s).length;
68
+ const chatsTokens = (s: SessionStore): number[] => {
69
+ const chats = currentChats(s);
70
+ return encode(chats.map((m) => m.content).join(''));
71
+ };
74
72
 
75
73
  const systemRoleTokenCount = (s: SessionStore) => systemRoleTokens(s).length;
76
74
 
75
+ const totalTokenCount = (s: SessionStore) => chatsTokens(s).length + systemRoleTokenCount(s);
76
+
77
77
  export const chatSelectors = {
78
78
  currentChats,
79
79
  systemRoleTokenCount,
80
80
  systemRoleTokens,
81
81
  totalTokenCount,
82
- totalTokens,
83
82
  };