@lobehub/chat 0.105.2 → 0.106.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,31 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ## [Version 0.106.0](https://github.com/lobehub/lobe-chat/compare/v0.105.2...v0.106.0)
6
+
7
+ <sup>Released on **2023-11-29**</sup>
8
+
9
+ #### ✨ Features
10
+
11
+ - **misc**: Support custom deletion, addition, and renaming of models.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's improved
19
+
20
+ - **misc**: Support custom deletion, addition, and renaming of models, closes [#521](https://github.com/lobehub/lobe-chat/issues/521) [#518](https://github.com/lobehub/lobe-chat/issues/518) [#518](https://github.com/lobehub/lobe-chat/issues/518) ([65e0824](https://github.com/lobehub/lobe-chat/commit/65e0824))
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
+
5
30
  ### [Version 0.105.2](https://github.com/lobehub/lobe-chat/compare/v0.105.1...v0.105.2)
6
31
 
7
32
  <sup>Released on **2023-11-27**</sup>
package/README.md CHANGED
@@ -51,6 +51,7 @@ Supports one-click free deployment of your private ChatGPT/LLM web application.
51
51
  - [🛳 Self Hosting](#-self-hosting)
52
52
  - [`A` Deploying with Vercel](#a-deploying-with-vercel)
53
53
  - [`B` Deploying with Docker](#b-deploying-with-docker)
54
+ - [`C` Deploying with Zeabur](#c-deploying-with-zeabur)
54
55
  - [Environment Variable](#environment-variable)
55
56
  - [📦 Ecosystem](#-ecosystem)
56
57
  - [🧩 Plugins](#-plugins)
@@ -379,6 +380,21 @@ $ docker run -d -p 3210:3210 \
379
380
 
380
381
  <br/>
381
382
 
383
+ ### `C` Deploying with Zeabur
384
+
385
+ If you want to deploy this service yourself on Zeabur, you can follow these steps:
386
+
387
+ - Prepare your [OpenAI API Key](https://platform.openai.com/account/api-keys).
388
+ - Click the button below to start deployment: Deploy with Zeabur.
389
+ - You can start using it after the deployment.
390
+ - You can bind a custom domain or use the subdomain provided by Zeabur.
391
+
392
+ <div align="center">
393
+
394
+ [![][deploy-on-zeabur-button-image]][deploy-on-zeabur-link]
395
+
396
+ </div>
397
+
382
398
  ### Environment Variable
383
399
 
384
400
  This project provides some additional configuration items set with environment variables:
@@ -518,6 +534,8 @@ This project is [MIT](./LICENSE) licensed.
518
534
  [contributors-link]: https://github.com/lobehub/lobe-chat/graphs/contributors
519
535
  [deploy-button-image]: https://vercel.com/button
520
536
  [deploy-link]: https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Flobehub%2Flobe-chat&env=OPENAI_API_KEY&envDescription=Find%20your%20OpenAI%20API%20Key%20by%20click%20the%20right%20Learn%20More%20button.&envLink=https%3A%2F%2Fplatform.openai.com%2Faccount%2Fapi-keys&project-name=lobe-chat&repository-name=lobe-chat
537
+ [deploy-on-zeabur-button-image]: https://zeabur.com/button.svg
538
+ [deploy-on-zeabur-link]: https://zeabur.com/templates/VZGGTI
521
539
  [discord-link]: https://discord.gg/AYFPHvv2jT
522
540
  [discord-shield]: https://img.shields.io/discord/1127171173982154893?color=5865F2&label=discord&labelColor=black&logo=discord&logoColor=white&style=flat-square
523
541
  [discord-shield-badge]: https://img.shields.io/discord/1127171173982154893?color=5865F2&label=discord&labelColor=black&logo=discord&logoColor=white&style=for-the-badge
package/README.zh-CN.md CHANGED
@@ -50,6 +50,7 @@ LobeChat 是开源的高性能聊天机器人框架,支持语音合成、多
50
50
  - [🛳 开箱即用](#-开箱即用)
51
51
  - [`A` 使用 Vercel 部署](#a-使用-vercel-部署)
52
52
  - [`B` 使用 Docker 部署](#b-使用-docker-部署)
53
+ - [`C` 使用 Zeabur 部署](#c-使用-zeabur-部署)
53
54
  - [环境变量](#环境变量)
54
55
  - [📦 生态系统](#-生态系统)
55
56
  - [🧩 插件体系](#-插件体系)
@@ -353,6 +354,21 @@ $ docker run -d -p 3210:3210 \
353
354
 
354
355
  <br/>
355
356
 
357
+ ### `C` 使用 Zeabur 部署
358
+
359
+ 如果想在 Zeabur 上部署该服务,可以按照以下步骤进行操作:
360
+
361
+ - 准备好你的 [OpenAI API Key](https://platform.openai.com/account/api-keys) 。
362
+ - 点击下方按钮开始部署: Deploy to Zeabur
363
+ - 部署完毕后,即可开始使用;
364
+ - 绑定自定义域名(可选):你可以使用 Zeabur 提供的子域名,也可以选择绑定自定义域名。目前 Zeabur 提供的域名还未被污染,大多数地区都可以直连。
365
+
366
+ <div align="center">
367
+
368
+ [![][deploy-on-zeabur-button-image]][deploy-on-zeabur-link]
369
+
370
+ </div>
371
+
356
372
  ### 环境变量
357
373
 
358
374
  本项目提供了一些额外的配置项,使用环境变量进行设置:
@@ -492,6 +508,8 @@ This project is [MIT](./LICENSE) licensed.
492
508
  [contributors-link]: https://github.com/lobehub/lobe-chat/graphs/contributors
493
509
  [deploy-button-image]: https://vercel.com/button
494
510
  [deploy-link]: https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Flobehub%2Flobe-chat&env=OPENAI_API_KEY&envDescription=Find%20your%20OpenAI%20API%20Key%20by%20click%20the%20right%20Learn%20More%20button.&envLink=https%3A%2F%2Fplatform.openai.com%2Faccount%2Fapi-keys&project-name=lobe-chat&repository-name=lobe-chat
511
+ [deploy-on-zeabur-button-image]: https://zeabur.com/button.svg
512
+ [deploy-on-zeabur-link]: https://zeabur.com/templates/VZGGTI
495
513
  [discord-link]: https://discord.gg/AYFPHvv2jT
496
514
  [discord-shield]: https://img.shields.io/discord/1127171173982154893?color=5865F2&label=discord&labelColor=black&logo=discord&logoColor=white&style=flat-square
497
515
  [discord-shield-badge]: https://img.shields.io/discord/1127171173982154893?color=5865F2&label=discord&labelColor=black&logo=discord&logoColor=white&style=for-the-badge
@@ -34,9 +34,11 @@ LobeChat provides additional configuration options during deployment, which can
34
34
  ### `NEXT_PUBLIC_CUSTOM_MODELS`
35
35
 
36
36
  - Type: Optional
37
- - Description: add your custom model name, multi model seperate by comma. for example: `gpt-3.5-1106,gpt-4-1106`
37
+ - Description: Used to control the model list. Use `+` to add a model, `-` to hide a model, and `model_name=display_name` to customize the display name of a model, separated by commas.
38
38
  - Default: `-`
39
- - Example: `model1,model2,model3`
39
+ - Example: `+qwen-7b-chat,+glm-6b,-gpt-3.5-turbo,gpt-4-1106-preview=gpt-4-turbo`
40
+
41
+ The above example adds `qwen-7b-chat` and `glm-6b` to the model list, removes `gpt-3.5-turbo` from the list, and displays the model name `gpt-4-1106-preview` as `gpt-4-turbo`. If you want to disable all models first and then enable specific models, you can use `-all,+gpt-3.5-turbo`, which means only `gpt-3.5-turbo` will be enabled.
40
42
 
41
43
  ## OpenAI
42
44
 
@@ -34,9 +34,11 @@ LobeChat 在部署时提供了一些额外的配置项,使用环境变量进
34
34
  ### `NEXT_PUBLIC_CUSTOM_MODELS`
35
35
 
36
36
  - 类型:可选
37
- - 描述:添加自定义模型名称,多个模型需要使用逗号 `,` 隔开。 比如: `gpt-3.5-1106,gpt-4-1106`
37
+ - 描述:用来控制模型列表,使用 `+` 增加一个模型,使用 `-` 来隐藏一个模型,使用 `模型名=展示名` 来自定义模型的展示名,用英文逗号隔开。
38
38
  - 默认值:`-`
39
- - 示例:`model1,model2,model3`
39
+ - 示例:`+qwen-7b-chat,+glm-6b,-gpt-3.5-turbo,gpt-4-1106-preview=gpt-4-turbo`
40
+
41
+ 上面示例表示增加 `qwen-7b-chat` 和 `glm-6b` 到模型列表,而从列表中删除 `gpt-3.5-turbo`,并将 `gpt-4-1106-preview` 模型名字展示为 `gpt-4-turbo`。如果你想先禁用所有模型,再启用指定模型,可以使用 `-all,+gpt-3.5-turbo`,则表示仅启用 `gpt-3.5-turbo`。
40
42
 
41
43
  ## OpenAI
42
44
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.105.2",
3
+ "version": "0.106.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",
@@ -22,7 +22,7 @@ const ModelSwitch = memo(() => {
22
22
  <Dropdown
23
23
  menu={{
24
24
  activeKey: model,
25
- items: modelList.map((i) => ({ key: i, label: i })),
25
+ items: modelList.map(({ name, displayName }) => ({ key: name, label: displayName })),
26
26
  onClick: (e) => {
27
27
  updateAgentConfig({ model: e.key as LanguageModel });
28
28
  },
@@ -114,7 +114,14 @@ const AgentConfig = memo(() => {
114
114
  const model: ItemGroup = {
115
115
  children: [
116
116
  {
117
- children: <Select options={modelList.map((value) => ({ label: value, value }))} />,
117
+ children: (
118
+ <Select
119
+ options={modelList.map(({ name, displayName }) => ({
120
+ label: displayName,
121
+ value: name,
122
+ }))}
123
+ />
124
+ ),
118
125
  desc: t('settingModel.model.desc'),
119
126
  label: t('settingModel.model.title'),
120
127
  name: 'model',
@@ -1,5 +1,104 @@
1
1
  // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
2
 
3
+ exports[`settingsSelectors > CUSTOM_MODELS > custom deletion, addition, and renaming of models 1`] = `
4
+ [
5
+ {
6
+ "displayName": "llama",
7
+ "name": "llama",
8
+ },
9
+ {
10
+ "displayName": "claude-2",
11
+ "name": "claude-2",
12
+ },
13
+ {
14
+ "displayName": "gpt-4-32k",
15
+ "name": "gpt-4-1106-preview",
16
+ },
17
+ ]
18
+ `;
19
+
20
+ exports[`settingsSelectors > CUSTOM_MODELS > duplicate naming model 1`] = `
21
+ [
22
+ {
23
+ "displayName": "gpt-3.5-turbo",
24
+ "name": "gpt-3.5-turbo",
25
+ },
26
+ {
27
+ "displayName": "gpt-3.5-turbo-1106",
28
+ "name": "gpt-3.5-turbo-1106",
29
+ },
30
+ {
31
+ "displayName": "gpt-3.5-turbo-16k",
32
+ "name": "gpt-3.5-turbo-16k",
33
+ },
34
+ {
35
+ "displayName": "gpt-4",
36
+ "name": "gpt-4",
37
+ },
38
+ {
39
+ "displayName": "gpt-4-32k",
40
+ "name": "gpt-4-32k",
41
+ },
42
+ {
43
+ "displayName": "gpt-4-vision-preview",
44
+ "name": "gpt-4-vision-preview",
45
+ },
46
+ {
47
+ "displayName": "gpt-4-32k",
48
+ "name": "gpt-4-1106-preview",
49
+ },
50
+ ]
51
+ `;
52
+
53
+ exports[`settingsSelectors > CUSTOM_MODELS > only add the model 1`] = `
54
+ [
55
+ {
56
+ "displayName": "gpt-3.5-turbo",
57
+ "name": "gpt-3.5-turbo",
58
+ },
59
+ {
60
+ "displayName": "gpt-3.5-turbo-1106",
61
+ "name": "gpt-3.5-turbo-1106",
62
+ },
63
+ {
64
+ "displayName": "gpt-3.5-turbo-16k",
65
+ "name": "gpt-3.5-turbo-16k",
66
+ },
67
+ {
68
+ "displayName": "gpt-4",
69
+ "name": "gpt-4",
70
+ },
71
+ {
72
+ "displayName": "gpt-4-32k",
73
+ "name": "gpt-4-32k",
74
+ },
75
+ {
76
+ "displayName": "gpt-4-1106-preview",
77
+ "name": "gpt-4-1106-preview",
78
+ },
79
+ {
80
+ "displayName": "gpt-4-vision-preview",
81
+ "name": "gpt-4-vision-preview",
82
+ },
83
+ {
84
+ "displayName": "model1",
85
+ "name": "model1",
86
+ },
87
+ {
88
+ "displayName": "model2",
89
+ "name": "model2",
90
+ },
91
+ {
92
+ "displayName": "model3",
93
+ "name": "model3",
94
+ },
95
+ {
96
+ "displayName": "model4",
97
+ "name": "model4",
98
+ },
99
+ ]
100
+ `;
101
+
3
102
  exports[`settingsSelectors > currentSettings > should merge DEFAULT_SETTINGS and s.settings correctly 1`] = `
4
103
  {
5
104
  "avatar": "avatar.jpg",
@@ -58,6 +58,57 @@ describe('settingsSelectors', () => {
58
58
  });
59
59
  });
60
60
 
61
+ describe('CUSTOM_MODELS', () => {
62
+ it('custom deletion, addition, and renaming of models', () => {
63
+ const s = {
64
+ settings: {
65
+ languageModel: {
66
+ openAI: {
67
+ customModelName:
68
+ '-all,+llama,+claude-2,-gpt-3.5-turbo,gpt-4-1106-preview=gpt-4-turbo,gpt-4-1106-preview=gpt-4-32k',
69
+ },
70
+ },
71
+ },
72
+ } as unknown as GlobalStore;
73
+
74
+ const result = settingsSelectors.modelList(s);
75
+
76
+ expect(result).toMatchSnapshot();
77
+ });
78
+
79
+ it('duplicate naming model', () => {
80
+ const s = {
81
+ settings: {
82
+ languageModel: {
83
+ openAI: {
84
+ customModelName: 'gpt-4-1106-preview=gpt-4-turbo,gpt-4-1106-preview=gpt-4-32k',
85
+ },
86
+ },
87
+ },
88
+ } as unknown as GlobalStore;
89
+
90
+ const result = settingsSelectors.modelList(s);
91
+
92
+ expect(result).toMatchSnapshot();
93
+ });
94
+
95
+ it('only add the model', () => {
96
+ const s = {
97
+ settings: {
98
+ languageModel: {
99
+ openAI: {
100
+ customModelName: 'model1,model2,model3,model4',
101
+ },
102
+ },
103
+ },
104
+ } as unknown as GlobalStore;
105
+
106
+ const result = settingsSelectors.modelList(s);
107
+
108
+ expect(result).toMatchSnapshot();
109
+ });
110
+ });
111
+
61
112
  // describe('defaultAgent', () => {
62
113
  // it('should merge DEFAULT_AGENT and s.settings.defaultAgent correctly', () => {
63
114
  // const s: GlobalStore = {
@@ -8,7 +8,7 @@ import {
8
8
  DEFAULT_TTS_CONFIG,
9
9
  } from '@/const/settings';
10
10
  import { Locales } from '@/locales/resources';
11
- import { GlobalSettings } from '@/types/settings';
11
+ import { CustomModels, GlobalSettings } from '@/types/settings';
12
12
  import { isOnServerSide } from '@/utils/env';
13
13
  import { merge } from '@/utils/merge';
14
14
 
@@ -29,10 +29,41 @@ const openAIAPIKeySelectors = (s: GlobalStore) =>
29
29
 
30
30
  const openAIProxyUrlSelectors = (s: GlobalStore) => s.settings.languageModel.openAI.endpoint;
31
31
 
32
- const modelListSelectors = (s: GlobalStore) => [
33
- ...DEFAULT_OPENAI_MODEL_LIST,
34
- ...(s.settings.languageModel.openAI.customModelName || '').split(',').filter(Boolean),
35
- ];
32
+ const modelListSelectors = (s: GlobalStore) => {
33
+ let models: CustomModels = [];
34
+
35
+ const modelNames = [
36
+ ...DEFAULT_OPENAI_MODEL_LIST,
37
+ ...(s.settings.languageModel.openAI.customModelName || '').split(/[,,]/).filter(Boolean),
38
+ ];
39
+
40
+ for (const item of modelNames) {
41
+ const disable = item.startsWith('-');
42
+ const nameConfig = item.startsWith('+') || item.startsWith('-') ? item.slice(1) : item;
43
+ const [name, displayName] = nameConfig.split('=');
44
+
45
+ if (disable) {
46
+ // Disable all models.
47
+ if (name === 'all') {
48
+ models = [];
49
+ }
50
+ continue;
51
+ }
52
+
53
+ // Remove duplicate model entries.
54
+ const existingIndex = models.findIndex(({ name: n }) => n === name);
55
+ if (existingIndex !== -1) {
56
+ models.splice(existingIndex, 1);
57
+ }
58
+
59
+ models.push({
60
+ displayName: displayName || name,
61
+ name,
62
+ });
63
+ }
64
+
65
+ return models;
66
+ };
36
67
 
37
68
  export const exportSettings = (s: GlobalStore) => {
38
69
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -45,6 +45,8 @@ export interface GlobalBaseSettings {
45
45
 
46
46
  export type GlobalDefaultAgent = Pick<LobeAgentSession, 'config' | 'meta'>;
47
47
 
48
+ export type CustomModels = { displayName: string; name: string }[];
49
+
48
50
  export interface OpenAIConfig {
49
51
  OPENAI_API_KEY: string;
50
52
  azureApiVersion?: string;