@lobehub/chat 0.86.4 → 0.87.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,56 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ## [Version 0.87.0](https://github.com/lobehub/lobe-chat/compare/v0.86.5...v0.87.0)
6
+
7
+ <sup>Released on **2023-10-11**</sup>
8
+
9
+ #### ✨ Features
10
+
11
+ - **misc**: Support custom model name.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's improved
19
+
20
+ - **misc**: Support custom model name, closes [#305](https://github.com/lobehub/lobe-chat/issues/305) ([84a066a](https://github.com/lobehub/lobe-chat/commit/84a066a))
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.86.5](https://github.com/lobehub/lobe-chat/compare/v0.86.4...v0.86.5)
31
+
32
+ <sup>Released on **2023-10-11**</sup>
33
+
34
+ #### 🐛 Bug Fixes
35
+
36
+ - **misc**: Fix clear session error.
37
+
38
+ <br/>
39
+
40
+ <details>
41
+ <summary><kbd>Improvements and Fixes</kbd></summary>
42
+
43
+ #### What's fixed
44
+
45
+ - **misc**: Fix clear session error, closes [#303](https://github.com/lobehub/lobe-chat/issues/303) ([09512fc](https://github.com/lobehub/lobe-chat/commit/09512fc))
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 0.86.4](https://github.com/lobehub/lobe-chat/compare/v0.86.3...v0.86.4)
6
56
 
7
57
  <sup>Released on **2023-10-11**</sup>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.86.4",
3
+ "version": "0.87.0",
4
4
  "description": "An open-source, extensible (Function Calling), high-performance chatbot framework. It supports one-click free deployment of your private ChatGPT/LLM web application",
5
5
  "keywords": [
6
6
  "chatbot",
@@ -5,6 +5,7 @@ import { memo } from 'react';
5
5
  import { useTranslation } from 'react-i18next';
6
6
  import { Flexbox } from 'react-layout-kit';
7
7
 
8
+ import { settingsSelectors, useGlobalStore } from '@/store/global';
8
9
  import { useSessionStore } from '@/store/session';
9
10
  import { agentSelectors } from '@/store/session/selectors';
10
11
  import { LanguageModel } from '@/types/llm';
@@ -23,12 +24,14 @@ const ActionLeft = memo(() => {
23
24
  ];
24
25
  });
25
26
 
27
+ const modelList = useGlobalStore(settingsSelectors.modelList);
28
+
26
29
  return (
27
30
  <>
28
31
  <Dropdown
29
32
  menu={{
30
33
  activeKey: model,
31
- items: Object.values(LanguageModel).map((i) => ({ key: i, label: i })),
34
+ items: modelList.map((i) => ({ key: i, label: i })),
32
35
  onClick: (e) => {
33
36
  updateAgentConfig({ model: e.key as LanguageModel });
34
37
  },
@@ -6,6 +6,7 @@ import { ModelTokens } from '@/const/modelTokens';
6
6
  import { useTokenCount } from '@/hooks/useTokenCount';
7
7
  import { useSessionStore } from '@/store/session';
8
8
  import { agentSelectors, chatSelectors } from '@/store/session/selectors';
9
+ import { LanguageModel } from '@/types/llm';
9
10
 
10
11
  const Token = memo<{ input: string }>(({ input }) => {
11
12
  const { t } = useTranslation('common');
@@ -15,7 +16,7 @@ const Token = memo<{ input: string }>(({ input }) => {
15
16
  const [messageString, systemRole, model] = useSessionStore((s) => [
16
17
  chatSelectors.chatsMessageString(s),
17
18
  agentSelectors.currentAgentSystemRole(s),
18
- agentSelectors.currentAgentModel(s),
19
+ agentSelectors.currentAgentModel(s) as LanguageModel,
19
20
  ]);
20
21
 
21
22
  const systemRoleToken = useTokenCount(systemRole);
@@ -6,6 +6,7 @@ import { useTranslation } from 'react-i18next';
6
6
 
7
7
  import { CHAT_TEXTAREA_HEIGHT } from '@/const/layoutTokens';
8
8
  import { useSessionStore } from '@/store/session';
9
+ import { agentSelectors } from '@/store/session/selectors';
9
10
 
10
11
  import ActionLeft from './ActionBar/ActionLeft';
11
12
  import ActionsRight from './ActionBar/ActionRight';
@@ -28,10 +29,11 @@ const ChatInputContent = memo<ChatContentProps>(
28
29
 
29
30
  const mobile = runtimeMobile || defaultMobile;
30
31
 
31
- const [isLoading, sendMessage, stopGenerateMessage] = useSessionStore((s) => [
32
+ const [isLoading, sendMessage, stopGenerateMessage, showTokenTag] = useSessionStore((s) => [
32
33
  !!s.chatLoadingId,
33
34
  s.sendMessage,
34
35
  s.stopGenerateMessage,
36
+ agentSelectors.showTokenTag(s),
35
37
  ]);
36
38
 
37
39
  return (
@@ -39,9 +41,11 @@ const ChatInputContent = memo<ChatContentProps>(
39
41
  actions={
40
42
  <>
41
43
  <ActionLeft />
42
- <Suspense>
43
- <Token input={message} />
44
- </Suspense>
44
+ {showTokenTag && (
45
+ <Suspense>
46
+ <Token input={message} />
47
+ </Suspense>
48
+ )}
45
49
  </>
46
50
  }
47
51
  actionsRight={<ActionsRight />}
@@ -70,11 +70,15 @@ const LLM = memo(() => {
70
70
  />
71
71
  ),
72
72
  desc: useAzure ? t('llm.AzureOpenAI.endpoint.desc') : t('llm.OpenAI.endpoint.desc'),
73
-
74
73
  label: useAzure ? t('llm.AzureOpenAI.endpoint.title') : t('llm.OpenAI.endpoint.title'),
75
-
76
74
  name: [configKey, 'openAI', 'endpoint'],
77
75
  },
76
+ {
77
+ children: <Input allowClear placeholder={t('llm.OpenAI.customModelName.placeholder')} />,
78
+ desc: t('llm.OpenAI.customModelName.desc'),
79
+ label: t('llm.OpenAI.customModelName.title'),
80
+ name: [configKey, 'openAI', 'customModelName'],
81
+ },
78
82
  {
79
83
  children: (
80
84
  <Switch />
@@ -8,7 +8,7 @@ import { memo, useEffect } from 'react';
8
8
  import { useTranslation } from 'react-i18next';
9
9
 
10
10
  import { FORM_STYLE } from '@/const/layoutTokens';
11
- import { LanguageModel } from '@/types/llm';
11
+ import { settingsSelectors, useGlobalStore } from '@/store/global';
12
12
 
13
13
  import { useStore } from '../store';
14
14
 
@@ -16,9 +16,11 @@ const AgentConfig = memo(() => {
16
16
  const { t } = useTranslation('setting');
17
17
  const updateConfig = useStore((s) => s.setAgentConfig);
18
18
  const [form] = AFrom.useForm();
19
+ const { isDarkMode } = useThemeMode();
20
+
19
21
  const config = useStore((s) => s.config, isEqual);
20
22
 
21
- const { isDarkMode } = useThemeMode();
23
+ const modelList = useGlobalStore(settingsSelectors.modelList);
22
24
 
23
25
  useEffect(() => {
24
26
  form.setFieldsValue(config);
@@ -96,14 +98,7 @@ const AgentConfig = memo(() => {
96
98
  const model: ItemGroup = {
97
99
  children: [
98
100
  {
99
- children: (
100
- <Select
101
- options={Object.values(LanguageModel).map((value) => ({
102
- label: value,
103
- value,
104
- }))}
105
- />
106
- ),
101
+ children: <Select options={modelList.map((value) => ({ label: value, value }))} />,
107
102
  desc: t('settingModel.model.desc'),
108
103
  label: t('settingModel.model.title'),
109
104
  name: 'model',
@@ -9,6 +9,7 @@ import { Flexbox } from 'react-layout-kit';
9
9
  import { FORM_STYLE } from '@/const/layoutTokens';
10
10
  import { ModelTokens } from '@/const/modelTokens';
11
11
  import { useTokenCount } from '@/hooks/useTokenCount';
12
+ import { LanguageModel } from '@/types/llm';
12
13
 
13
14
  import { useStore } from '../store';
14
15
 
@@ -29,21 +30,25 @@ const AgentPrompt = memo(() => {
29
30
  const [systemRole, model] = useStore((s) => [s.config.systemRole, s.config.model]);
30
31
  const systemTokenCount = useTokenCount(systemRole);
31
32
 
33
+ const showTag = model in ModelTokens;
34
+
32
35
  return (
33
36
  <FormGroup
34
37
  extra={
35
38
  <Flexbox align={'center'} gap={8} horizontal>
36
- <TokenTag
37
- displayMode={'used'}
38
- maxValue={ModelTokens[model]}
39
- shape={'square'}
40
- text={{
41
- overload: t('tokenTag.overload', { ns: 'common' }),
42
- remained: t('tokenTag.remained', { ns: 'common' }),
43
- used: t('tokenTag.used', { ns: 'common' }),
44
- }}
45
- value={systemTokenCount}
46
- />
39
+ {showTag && (
40
+ <TokenTag
41
+ displayMode={'used'}
42
+ maxValue={ModelTokens[model as LanguageModel]}
43
+ shape={'square'}
44
+ text={{
45
+ overload: t('tokenTag.overload', { ns: 'common' }),
46
+ remained: t('tokenTag.remained', { ns: 'common' }),
47
+ used: t('tokenTag.used', { ns: 'common' }),
48
+ }}
49
+ value={systemTokenCount}
50
+ />
51
+ )}
47
52
  </Flexbox>
48
53
  }
49
54
  icon={Bot}
@@ -50,6 +50,11 @@ export default {
50
50
  pass: '检查通过',
51
51
  title: '连通性检查',
52
52
  },
53
+ customModelName: {
54
+ desc: '增加自定义模型,多个模型使用逗号(,) 隔开',
55
+ placeholder: 'model1,model2,model3',
56
+ title: '自定义模型名称',
57
+ },
53
58
  endpoint: {
54
59
  desc: '除默认地址外,必须包含 http(s)://',
55
60
  placeholder: 'https://api.openai.com/v1',
@@ -1,3 +1,4 @@
1
+ import { DEFAULT_OPENAI_MODEL_LIST } from '@/const/llm';
1
2
  import { DEFAULT_AGENT_META } from '@/const/meta';
2
3
  import { DEFAULT_AGENT, DEFAULT_AGENT_CONFIG, DEFAULT_SETTINGS } from '@/const/settings';
3
4
  import { Locales } from '@/locales/resources';
@@ -19,6 +20,11 @@ const openAIAPIKeySelectors = (s: GlobalStore) =>
19
20
 
20
21
  const openAIProxyUrlSelectors = (s: GlobalStore) => s.settings.languageModel.openAI.endpoint;
21
22
 
23
+ const modelListSelectors = (s: GlobalStore) => [
24
+ ...DEFAULT_OPENAI_MODEL_LIST,
25
+ ...(s.settings.languageModel.openAI.customModelName || '').split(',').filter(Boolean),
26
+ ];
27
+
22
28
  export const exportSettings = (s: GlobalStore) => {
23
29
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
24
30
  const { OPENAI_API_KEY: _, password: __, ...settings } = s.settings;
@@ -42,6 +48,7 @@ export const settingsSelectors = {
42
48
  defaultAgentConfig,
43
49
  defaultAgentMeta,
44
50
  exportSettings,
51
+ modelList: modelListSelectors,
45
52
  openAIAPI: openAIAPIKeySelectors,
46
53
  openAIProxyUrl: openAIProxyUrlSelectors,
47
54
  };
@@ -1,5 +1,6 @@
1
1
  import { t } from 'i18next';
2
2
 
3
+ import { DEFAULT_OPENAI_MODEL_LIST } from '@/const/llm';
3
4
  import { DEFAULT_AVATAR, DEFAULT_BACKGROUND_COLOR } from '@/const/meta';
4
5
  import { SessionStore } from '@/store/session';
5
6
  import { LanguageModel } from '@/types/llm';
@@ -42,7 +43,7 @@ const currentAgentAvatar = (s: SessionStore) => {
42
43
  return session.meta.avatar || DEFAULT_AVATAR;
43
44
  };
44
45
 
45
- const currentAgentModel = (s: SessionStore): LanguageModel => {
46
+ const currentAgentModel = (s: SessionStore): LanguageModel | string => {
46
47
  const config = currentAgentConfig(s);
47
48
 
48
49
  return config?.model || LanguageModel.GPT3_5;
@@ -66,6 +67,12 @@ const getTitle = (s: MetaData) => s.title || t('defaultSession', { ns: 'common'
66
67
  export const getDescription = (s: MetaData) =>
67
68
  s.description || t('noDescription', { ns: 'common' });
68
69
 
70
+ const showTokenTag = (s: SessionStore) => {
71
+ const model = currentAgentModel(s);
72
+
73
+ return DEFAULT_OPENAI_MODEL_LIST.includes(model);
74
+ };
75
+
69
76
  export const agentSelectors = {
70
77
  currentAgentAvatar,
71
78
  currentAgentBackgroundColor,
@@ -80,4 +87,5 @@ export const agentSelectors = {
80
87
  getDescription,
81
88
  getTitle,
82
89
  hasSystemRole,
90
+ showTokenTag,
83
91
  };
@@ -11,7 +11,7 @@ import { LobeAgentSession, LobeAgentSettings, LobeSessions } from '@/types/sessi
11
11
  import { setNamespace } from '@/utils/storeDebug';
12
12
  import { uuid } from '@/utils/uuid';
13
13
 
14
- import { initLobeSession } from './initialState';
14
+ import { initInbox, initLobeSession } from './initialState';
15
15
  import { SessionDispatch, sessionsReducer } from './reducers/session';
16
16
 
17
17
  const t = setNamespace('session');
@@ -76,7 +76,7 @@ export const createSessionSlice: StateCreator<
76
76
  },
77
77
 
78
78
  clearSessions: () => {
79
- set({ sessions: {} }, false, t('clearSessions'));
79
+ set({ inbox: initInbox, sessions: {} }, false, t('clearSessions'));
80
80
  },
81
81
 
82
82
  createSession: async (agent) => {
@@ -58,7 +58,7 @@ export interface LobeAgentConfig {
58
58
  * 角色所使用的语言模型
59
59
  * @default gpt-3.5-turbo
60
60
  */
61
- model: LanguageModel;
61
+ model: LanguageModel | string;
62
62
  /**
63
63
  * 语言模型参数
64
64
  */
@@ -48,6 +48,10 @@ export type GlobalDefaultAgent = Pick<LobeAgentSession, 'config' | 'meta'>;
48
48
  export interface OpenAIConfig {
49
49
  OPENAI_API_KEY: string;
50
50
  azureApiVersion?: string;
51
+ /**
52
+ * custom mode name for fine-tuning or openai like model
53
+ */
54
+ customModelName?: string;
51
55
  endpoint?: string;
52
56
  models?: string[];
53
57
  useAzure?: boolean;