@lobehub/chat 0.122.9 → 0.123.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.
Files changed (227) hide show
  1. package/.env.example +22 -2
  2. package/.eslintrc.js +1 -0
  3. package/CHANGELOG.md +25 -0
  4. package/README.md +11 -9
  5. package/README.zh-CN.md +11 -9
  6. package/docs/Deployment/Environment-Variable.md +65 -23
  7. package/docs/Deployment/Environment-Variable.zh-CN.md +64 -22
  8. package/locales/ar/chat.json +12 -1
  9. package/locales/ar/common.json +16 -0
  10. package/locales/ar/error.json +35 -6
  11. package/locales/ar/setting.json +53 -6
  12. package/locales/de-DE/chat.json +12 -1
  13. package/locales/de-DE/common.json +16 -0
  14. package/locales/de-DE/error.json +35 -6
  15. package/locales/de-DE/setting.json +53 -6
  16. package/locales/en-US/chat.json +13 -2
  17. package/locales/en-US/common.json +16 -0
  18. package/locales/en-US/error.json +35 -6
  19. package/locales/en-US/setting.json +53 -6
  20. package/locales/es-ES/chat.json +12 -1
  21. package/locales/es-ES/common.json +16 -0
  22. package/locales/es-ES/error.json +35 -6
  23. package/locales/es-ES/setting.json +53 -6
  24. package/locales/fr-FR/chat.json +13 -2
  25. package/locales/fr-FR/common.json +16 -0
  26. package/locales/fr-FR/error.json +35 -6
  27. package/locales/fr-FR/setting.json +53 -6
  28. package/locales/it-IT/chat.json +12 -1
  29. package/locales/it-IT/common.json +16 -0
  30. package/locales/it-IT/error.json +35 -6
  31. package/locales/it-IT/setting.json +53 -6
  32. package/locales/ja-JP/chat.json +12 -1
  33. package/locales/ja-JP/common.json +16 -0
  34. package/locales/ja-JP/error.json +35 -6
  35. package/locales/ja-JP/setting.json +53 -6
  36. package/locales/ko-KR/chat.json +12 -1
  37. package/locales/ko-KR/common.json +16 -0
  38. package/locales/ko-KR/error.json +35 -6
  39. package/locales/ko-KR/setting.json +53 -6
  40. package/locales/nl-NL/chat.json +12 -1
  41. package/locales/nl-NL/common.json +16 -0
  42. package/locales/nl-NL/error.json +35 -6
  43. package/locales/nl-NL/setting.json +53 -6
  44. package/locales/pl-PL/chat.json +12 -1
  45. package/locales/pl-PL/common.json +16 -0
  46. package/locales/pl-PL/error.json +35 -6
  47. package/locales/pl-PL/setting.json +53 -6
  48. package/locales/pt-BR/chat.json +12 -1
  49. package/locales/pt-BR/common.json +16 -0
  50. package/locales/pt-BR/error.json +35 -6
  51. package/locales/pt-BR/setting.json +53 -6
  52. package/locales/ru-RU/chat.json +12 -1
  53. package/locales/ru-RU/common.json +16 -0
  54. package/locales/ru-RU/error.json +35 -6
  55. package/locales/ru-RU/setting.json +53 -6
  56. package/locales/tr-TR/chat.json +12 -1
  57. package/locales/tr-TR/common.json +16 -0
  58. package/locales/tr-TR/error.json +35 -6
  59. package/locales/tr-TR/setting.json +53 -6
  60. package/locales/vi-VN/chat.json +12 -1
  61. package/locales/vi-VN/common.json +16 -0
  62. package/locales/vi-VN/error.json +35 -6
  63. package/locales/vi-VN/setting.json +53 -6
  64. package/locales/zh-CN/chat.json +12 -1
  65. package/locales/zh-CN/common.json +16 -0
  66. package/locales/zh-CN/error.json +34 -5
  67. package/locales/zh-CN/setting.json +59 -12
  68. package/locales/zh-TW/chat.json +12 -1
  69. package/locales/zh-TW/common.json +16 -0
  70. package/locales/zh-TW/error.json +35 -6
  71. package/locales/zh-TW/setting.json +53 -6
  72. package/next.config.mjs +8 -2
  73. package/package.json +8 -1
  74. package/src/app/api/chat/[provider]/agentRuntime.ts +129 -0
  75. package/src/app/api/chat/[provider]/route.ts +64 -0
  76. package/src/app/api/chat/auth.ts +42 -0
  77. package/src/app/api/chat/google/route.ts +86 -0
  78. package/src/app/api/config/route.ts +6 -1
  79. package/src/app/api/config.ts +3 -3
  80. package/src/app/api/errorResponse.test.ts +8 -8
  81. package/src/app/api/errorResponse.ts +43 -6
  82. package/src/app/api/openai/createBizOpenAI/createAzureOpenai.ts +1 -1
  83. package/src/app/api/openai/createBizOpenAI/createOpenai.ts +1 -1
  84. package/src/app/api/openai/createBizOpenAI/index.ts +2 -2
  85. package/src/app/chat/(desktop)/features/ChatHeader.tsx +6 -4
  86. package/src/app/chat/(desktop)/features/ChatInput/Footer/index.tsx +13 -3
  87. package/src/app/chat/(desktop)/features/ChatInput/Header/index.tsx +16 -24
  88. package/src/app/chat/(desktop)/features/SideBar/index.tsx +1 -0
  89. package/src/app/chat/features/ChatHeader/ShareButton/Preview.tsx +3 -3
  90. package/src/app/chat/features/SessionListContent/List/Item/index.tsx +2 -3
  91. package/src/app/settings/llm/Azure/index.tsx +145 -0
  92. package/src/app/settings/llm/Bedrock/index.tsx +109 -0
  93. package/src/app/settings/llm/{LLM/Checker.tsx → Checker.tsx} +11 -14
  94. package/src/app/settings/llm/Google/index.tsx +74 -0
  95. package/src/app/settings/llm/{LLM → OpenAI}/index.tsx +26 -44
  96. package/src/app/settings/llm/Zhipu/index.tsx +78 -0
  97. package/src/app/settings/llm/const.ts +13 -0
  98. package/src/app/settings/llm/page.tsx +42 -2
  99. package/src/app/settings/llm/useSyncSettings.ts +23 -0
  100. package/src/chains/__tests__/langDetect.test.ts +2 -2
  101. package/src/chains/__tests__/pickEmoji.test.ts +2 -2
  102. package/src/chains/langDetect.ts +2 -2
  103. package/src/chains/pickEmoji.ts +2 -2
  104. package/src/chains/summaryAgentName.ts +2 -2
  105. package/src/chains/summaryDescription.ts +2 -2
  106. package/src/chains/summaryTags.ts +2 -2
  107. package/src/chains/summaryTitle.ts +2 -2
  108. package/src/chains/translate.ts +2 -2
  109. package/src/components/ModelIcon/index.tsx +37 -0
  110. package/src/components/ModelProviderIcon/index.tsx +44 -0
  111. package/src/components/ModelSelect/index.tsx +133 -0
  112. package/src/components/ModelTag/ModelIcon.tsx +35 -0
  113. package/src/components/ModelTag/index.tsx +13 -0
  114. package/src/config/modelProviders/bedrock.ts +43 -0
  115. package/src/config/modelProviders/google.ts +20 -0
  116. package/src/config/modelProviders/index.ts +18 -0
  117. package/src/config/modelProviders/openai.ts +102 -0
  118. package/src/config/modelProviders/zhipu.ts +34 -0
  119. package/src/config/{server.ts → server/app.ts} +1 -24
  120. package/src/config/server/index.ts +13 -0
  121. package/src/config/server/provider.ts +78 -0
  122. package/src/const/auth.ts +30 -0
  123. package/src/const/fetch.ts +3 -0
  124. package/src/const/settings.ts +24 -4
  125. package/src/database/core/migrations/migrateSettingsToUser/index.test.ts +2 -1
  126. package/src/database/core/migrations/migrateSettingsToUser/index.ts +1 -18
  127. package/src/database/core/migrations/migrateSettingsToUser/type.ts +100 -0
  128. package/src/database/models/message.ts +3 -1
  129. package/src/database/schemas/message.ts +1 -0
  130. package/src/database/schemas/session.ts +1 -0
  131. package/src/features/AgentSetting/AgentConfig/ModelSelect.tsx +71 -0
  132. package/src/features/AgentSetting/AgentConfig/index.tsx +171 -161
  133. package/src/features/AgentSetting/AgentConfig/useSyncConfig.ts +23 -0
  134. package/src/features/AgentSetting/AgentPrompt/TokenTag.tsx +39 -0
  135. package/src/features/AgentSetting/AgentPrompt/index.tsx +4 -26
  136. package/src/features/AgentSetting/store/index.ts +10 -2
  137. package/src/features/ChatInput/ActionBar/FileUpload.tsx +11 -4
  138. package/src/features/ChatInput/ActionBar/ModelSwitch.tsx +56 -14
  139. package/src/features/ChatInput/ActionBar/Token/TokenTag.tsx +42 -7
  140. package/src/features/ChatInput/ActionBar/Token/index.tsx +5 -2
  141. package/src/features/ChatInput/ActionBar/Tools/index.tsx +11 -1
  142. package/src/features/ChatInput/useChatInput.ts +5 -1
  143. package/src/features/Conversation/Error/APIKeyForm/Bedrock.tsx +80 -0
  144. package/src/features/Conversation/Error/APIKeyForm/Google.tsx +61 -0
  145. package/src/features/Conversation/Error/APIKeyForm/OpenAI.tsx +63 -0
  146. package/src/features/Conversation/Error/APIKeyForm/Zhipu.tsx +62 -0
  147. package/src/features/Conversation/Error/APIKeyForm/index.tsx +72 -0
  148. package/src/features/Conversation/Error/AccessCodeForm.tsx +63 -0
  149. package/src/features/Conversation/Error/ErrorJsonViewer.tsx +26 -0
  150. package/src/features/Conversation/Error/InvalidAPIKey.tsx +16 -0
  151. package/src/features/Conversation/Error/InvalidAccessCode.tsx +50 -0
  152. package/src/features/Conversation/Error/OpenAiBizError.tsx +9 -17
  153. package/src/features/Conversation/Error/{Plugin/PluginSettings.tsx → PluginSettings.tsx} +8 -3
  154. package/src/features/Conversation/Error/index.tsx +75 -70
  155. package/src/features/Conversation/Error/style.tsx +9 -3
  156. package/src/features/Conversation/Extras/Assistant.tsx +2 -3
  157. package/src/features/Conversation/Plugins/Inspector/index.tsx +8 -2
  158. package/src/features/Conversation/components/ChatItem/index.tsx +9 -24
  159. package/src/features/Conversation/types/index.tsx +2 -5
  160. package/src/hooks/_header.ts +35 -0
  161. package/src/libs/agent-runtime/BaseAI.ts +9 -0
  162. package/src/libs/agent-runtime/azureOpenai/index.ts +72 -0
  163. package/src/libs/agent-runtime/bedrock/index.ts +134 -0
  164. package/src/libs/agent-runtime/error.ts +26 -0
  165. package/src/libs/agent-runtime/google/index.ts +160 -0
  166. package/src/libs/agent-runtime/index.ts +9 -0
  167. package/src/libs/agent-runtime/openai/index.test.ts +176 -0
  168. package/src/libs/agent-runtime/openai/index.ts +107 -0
  169. package/src/libs/agent-runtime/types/chat.ts +119 -0
  170. package/src/libs/agent-runtime/types/index.ts +2 -0
  171. package/src/libs/agent-runtime/types/type.ts +34 -0
  172. package/src/libs/agent-runtime/utils/createError.ts +10 -0
  173. package/src/libs/agent-runtime/utils/debugStream.ts +18 -0
  174. package/src/libs/agent-runtime/utils/env.ts +1 -0
  175. package/src/libs/agent-runtime/utils/handleOpenAIError.ts +39 -0
  176. package/src/libs/agent-runtime/utils/uriParser.ts +16 -0
  177. package/src/libs/agent-runtime/zhipu/authToken.ts +22 -0
  178. package/src/libs/agent-runtime/zhipu/index.ts +125 -0
  179. package/src/locales/default/chat.ts +12 -2
  180. package/src/locales/default/common.ts +16 -0
  181. package/src/locales/default/error.ts +42 -5
  182. package/src/locales/default/setting.ts +61 -12
  183. package/src/services/__tests__/chat.test.ts +8 -2
  184. package/src/services/__tests__/message.test.ts +1 -1
  185. package/src/services/_auth.ts +106 -0
  186. package/src/services/_header.ts +1 -0
  187. package/src/services/_url.ts +0 -2
  188. package/src/services/chat.ts +32 -14
  189. package/src/store/chat/slices/message/action.ts +9 -6
  190. package/src/store/global/slices/common/action.ts +8 -2
  191. package/src/store/global/slices/settings/action.test.ts +2 -2
  192. package/src/store/global/slices/settings/action.ts +11 -4
  193. package/src/store/global/slices/settings/selectors/__snapshots__/modelProvider.test.ts.snap +242 -78
  194. package/src/store/global/slices/settings/selectors/__snapshots__/selectors.test.ts.snap +2 -0
  195. package/src/store/global/slices/settings/selectors/modelProvider.test.ts +171 -47
  196. package/src/store/global/slices/settings/selectors/modelProvider.ts +136 -43
  197. package/src/store/session/slices/agent/selectors.test.ts +0 -48
  198. package/src/store/session/slices/agent/selectors.ts +7 -12
  199. package/src/types/agent/index.ts +6 -2
  200. package/src/types/fetch.ts +4 -2
  201. package/src/types/files.ts +3 -3
  202. package/src/types/llm.ts +27 -0
  203. package/src/types/message/index.ts +7 -3
  204. package/src/types/openai/chat.ts +6 -11
  205. package/src/types/settings/index.ts +1 -0
  206. package/src/types/settings/modelProvider.ts +37 -1
  207. package/src/utils/__snapshots__/parseModels.test.ts.snap +63 -0
  208. package/src/utils/parseModels.test.ts +24 -0
  209. package/src/utils/parseModels.ts +37 -0
  210. package/src/app/api/openai/chat/createChatCompletion.test.ts +0 -166
  211. package/src/app/api/openai/chat/createChatCompletion.ts +0 -76
  212. package/src/app/api/openai/chat/route.ts +0 -19
  213. package/src/app/api/openai/models/route.ts +0 -17
  214. package/src/app/settings/llm/LLM/ModelList.tsx +0 -51
  215. package/src/app/settings/llm/LLM/getModelList.ts +0 -9
  216. package/src/app/settings/llm/index.tsx +0 -36
  217. package/src/const/llm.ts +0 -32
  218. package/src/features/Conversation/Error/ApiKeyForm.tsx +0 -87
  219. package/src/features/Conversation/Error/ErrorActionContainer.tsx +0 -23
  220. package/src/features/Conversation/Error/InvalidAccess.tsx +0 -90
  221. package/src/features/Conversation/Error/OpenAPIKey.tsx +0 -13
  222. package/src/features/Conversation/Error/Plugin/PluginError.tsx +0 -30
  223. package/src/services/modelList.ts +0 -15
  224. /package/src/app/chat/(desktop)/features/ChatInput/{Header → Footer}/DragUpload.tsx +0 -0
  225. /package/src/{app/api/openai/chat → libs/agent-runtime/utils}/desensitizeUrl.test.ts +0 -0
  226. /package/src/{app/api/openai/chat → libs/agent-runtime/utils}/desensitizeUrl.ts +0 -0
  227. /package/src/types/{translate.ts → message/translate.ts} +0 -0
@@ -5,14 +5,6 @@ declare global {
5
5
  namespace NodeJS {
6
6
  interface ProcessEnv {
7
7
  ACCESS_CODE?: string;
8
- CUSTOM_MODELS?: string;
9
-
10
- OPENAI_API_KEY?: string;
11
- OPENAI_PROXY_URL?: string;
12
-
13
- AZURE_API_KEY?: string;
14
- AZURE_API_VERSION?: string;
15
- USE_AZURE_OPENAI?: string;
16
8
 
17
9
  IMGUR_CLIENT_ID?: string;
18
10
 
@@ -30,35 +22,20 @@ declare global {
30
22
  // refs: https://apidocs.imgur.com/
31
23
  const DEFAULT_IMAGUR_CLIENT_ID = 'e415f320d6e24f9';
32
24
 
33
- export const getServerConfig = () => {
25
+ export const getAppConfig = () => {
34
26
  if (typeof process === 'undefined') {
35
27
  throw new Error('[Server Config] you are importing a server-only module outside of server');
36
28
  }
37
29
 
38
- // region format: iad1,sfo1
39
- let regions: string[] = [];
40
- if (process.env.OPENAI_FUNCTION_REGIONS) {
41
- regions = process.env.OPENAI_FUNCTION_REGIONS.split(',');
42
- }
43
-
44
30
  const ACCESS_CODES = process.env.ACCESS_CODE?.split(',').filter(Boolean) || [];
45
31
 
46
32
  return {
47
33
  ACCESS_CODES,
48
- CUSTOM_MODELS: process.env.CUSTOM_MODELS,
49
34
 
50
35
  SHOW_ACCESS_CODE_CONFIG: !!ACCESS_CODES.length,
51
36
 
52
- OPENAI_API_KEY: process.env.OPENAI_API_KEY,
53
- OPENAI_PROXY_URL: process.env.OPENAI_PROXY_URL,
54
- OPENAI_FUNCTION_REGIONS: regions,
55
-
56
37
  METADATA_BASE_URL: process.env.METADATA_BASE_URL,
57
38
 
58
- AZURE_API_KEY: process.env.AZURE_API_KEY,
59
- AZURE_API_VERSION: process.env.AZURE_API_VERSION,
60
- USE_AZURE_OPENAI: process.env.USE_AZURE_OPENAI === '1',
61
-
62
39
  IMGUR_CLIENT_ID: process.env.IMGUR_CLIENT_ID || DEFAULT_IMAGUR_CLIENT_ID,
63
40
 
64
41
  AGENTS_INDEX_URL: !!process.env.AGENTS_INDEX_URL
@@ -0,0 +1,13 @@
1
+ import { getAppConfig } from './app';
2
+ import { getProviderConfig } from './provider';
3
+
4
+ export const getServerConfig = () => {
5
+ if (typeof process === 'undefined') {
6
+ throw new Error('[Server Config] you are importing a server-only module outside of server');
7
+ }
8
+
9
+ const provider = getProviderConfig();
10
+ const app = getAppConfig();
11
+
12
+ return { ...provider, ...app };
13
+ };
@@ -0,0 +1,78 @@
1
+ /* eslint-disable sort-keys-fix/sort-keys-fix , typescript-sort-keys/interface */
2
+
3
+ declare global {
4
+ // eslint-disable-next-line @typescript-eslint/no-namespace
5
+ namespace NodeJS {
6
+ interface ProcessEnv {
7
+ CUSTOM_MODELS?: string;
8
+
9
+ // OpenAI Provider
10
+ OPENAI_API_KEY?: string;
11
+ OPENAI_PROXY_URL?: string;
12
+ OPENAI_FUNCTION_REGIONS?: string;
13
+
14
+ // Azure OpenAI Provider
15
+ AZURE_API_KEY?: string;
16
+ AZURE_ENDPOINT?: string;
17
+ AZURE_API_VERSION?: string;
18
+ USE_AZURE_OPENAI?: string;
19
+
20
+ // ZhiPu Provider
21
+ ZHIPU_API_KEY?: string;
22
+ ZHIPU_PROXY_URL?: string;
23
+
24
+ // Google Provider
25
+ GOOGLE_API_KEY?: string;
26
+
27
+ // AWS Credentials
28
+ AWS_REGION?: string;
29
+ AWS_ACCESS_KEY_ID?: string;
30
+ AWS_SECRET_ACCESS_KEY?: string;
31
+
32
+ DEBUG_CHAT_COMPLETION?: string;
33
+ }
34
+ }
35
+ }
36
+
37
+ export const getProviderConfig = () => {
38
+ if (typeof process === 'undefined') {
39
+ throw new Error('[Server Config] you are importing a server-only module outside of server');
40
+ }
41
+
42
+ const ZHIPU_API_KEY = process.env.ZHIPU_API_KEY || '';
43
+ const AWS_ACCESS_KEY_ID = process.env.AWS_ACCESS_KEY_ID || '';
44
+
45
+ const GOOGLE_API_KEY = process.env.GOOGLE_API_KEY || '';
46
+
47
+ // region format: iad1,sfo1
48
+ let regions: string[] = [];
49
+ if (process.env.OPENAI_FUNCTION_REGIONS) {
50
+ regions = process.env.OPENAI_FUNCTION_REGIONS.split(',');
51
+ }
52
+
53
+ return {
54
+ CUSTOM_MODELS: process.env.CUSTOM_MODELS,
55
+
56
+ OPENAI_API_KEY: process.env.OPENAI_API_KEY,
57
+ OPENAI_PROXY_URL: process.env.OPENAI_PROXY_URL,
58
+ OPENAI_FUNCTION_REGIONS: regions,
59
+
60
+ ENABLED_ZHIPU: !!ZHIPU_API_KEY,
61
+ ZHIPU_API_KEY,
62
+
63
+ ENABLED_GOOGLE: !!GOOGLE_API_KEY,
64
+ GOOGLE_API_KEY,
65
+
66
+ ENABLED_AWS_BEDROCK: !!AWS_ACCESS_KEY_ID,
67
+ AWS_REGION: process.env.AWS_REGION,
68
+ AWS_ACCESS_KEY_ID: AWS_ACCESS_KEY_ID,
69
+ AWS_SECRET_ACCESS_KEY: process.env.AWS_SECRET_ACCESS_KEY || '',
70
+
71
+ AZURE_API_KEY: process.env.AZURE_API_KEY,
72
+ AZURE_API_VERSION: process.env.AZURE_API_VERSION,
73
+ AZURE_ENDPOINT: process.env.AZURE_ENDPOINT,
74
+ USE_AZURE_OPENAI: process.env.USE_AZURE_OPENAI === '1',
75
+
76
+ DEBUG_CHAT_COMPLETION: process.env.DEBUG_CHAT_COMPLETION === '1',
77
+ };
78
+ };
@@ -0,0 +1,30 @@
1
+ export const LOBE_CHAT_AUTH_HEADER = 'X-lobe-chat-auth';
2
+
3
+ export const JWT_SECRET_KEY = 'LobeHub · LobeChat';
4
+
5
+ /* eslint-disable typescript-sort-keys/interface */
6
+ export interface JWTPayload {
7
+ /**
8
+ * password
9
+ */
10
+ accessCode?: string;
11
+ /**
12
+ * Represents the user's API key
13
+ *
14
+ * If provider need multi keys like bedrock,
15
+ * this will be used as the checker whether to use frontend key
16
+ */
17
+ apiKey?: string;
18
+ /**
19
+ * Represents the endpoint of provider
20
+ */
21
+ endpoint?: string;
22
+
23
+ azureApiVersion?: string;
24
+ useAzure?: boolean;
25
+
26
+ awsAccessKeyId?: string;
27
+ awsRegion?: string;
28
+ awsSecretAccessKey?: string;
29
+ }
30
+ /* eslint-enable */
@@ -7,6 +7,9 @@ export const AZURE_OPENAI_API_VERSION = 'X-azure-openai-api-version';
7
7
 
8
8
  export const LOBE_CHAT_ACCESS_CODE = 'X-lobe-chat-access-code';
9
9
 
10
+ /**
11
+ * @deprecated
12
+ */
10
13
  export const getOpenAIAuthFromRequest = (req: Request) => {
11
14
  const apiKey = req.headers.get(OPENAI_API_KEY_HEADER_KEY);
12
15
  const endpoint = req.headers.get(OPENAI_END_POINT);
@@ -1,7 +1,6 @@
1
- import { DEFAULT_OPENAI_MODEL_LIST } from '@/const/llm';
2
1
  import { DEFAULT_AGENT_META } from '@/const/meta';
2
+ import { ModelProvider } from '@/libs/agent-runtime';
3
3
  import { LobeAgentConfig, LobeAgentTTSConfig } from '@/types/agent';
4
- import { LanguageModel } from '@/types/llm';
5
4
  import {
6
5
  GlobalBaseSettings,
7
6
  GlobalDefaultAgent,
@@ -33,7 +32,7 @@ export const DEFAULT_AGENT_CONFIG: LobeAgentConfig = {
33
32
  displayMode: 'chat',
34
33
  enableAutoCreateTopic: true,
35
34
  historyCount: 1,
36
- model: LanguageModel.GPT3_5,
35
+ model: 'gpt-3.5-turbo',
37
36
  params: {
38
37
  frequency_penalty: 0,
39
38
  presence_penalty: 0,
@@ -41,14 +40,35 @@ export const DEFAULT_AGENT_CONFIG: LobeAgentConfig = {
41
40
  top_p: 1,
42
41
  },
43
42
  plugins: [],
43
+ provider: ModelProvider.OpenAI,
44
44
  systemRole: '',
45
45
  tts: DEFAUTT_AGENT_TTS_CONFIG,
46
46
  };
47
47
 
48
48
  export const DEFAULT_LLM_CONFIG: GlobalLLMConfig = {
49
+ azure: {
50
+ apiKey: '',
51
+ deployments: '',
52
+ enabled: false,
53
+ endpoint: '',
54
+ },
55
+ bedrock: {
56
+ accessKeyId: '',
57
+ enabled: false,
58
+ region: 'us-east-1',
59
+ secretAccessKey: '',
60
+ },
61
+ google: {
62
+ apiKey: '',
63
+ enabled: false,
64
+ },
49
65
  openAI: {
50
66
  OPENAI_API_KEY: '',
51
- models: DEFAULT_OPENAI_MODEL_LIST,
67
+ models: [],
68
+ },
69
+ zhipu: {
70
+ apiKey: '',
71
+ enabled: false,
52
72
  },
53
73
  };
54
74
 
@@ -2,7 +2,8 @@ import { describe, expect } from 'vitest';
2
2
 
3
3
  import input from './fixtures/input.json';
4
4
  import outputData from './fixtures/output.json';
5
- import { V4Settings, migrateSettingsToUser } from './index';
5
+ import { migrateSettingsToUser } from './index';
6
+ import { V4Settings } from './type';
6
7
 
7
8
  describe('migrateSettingsFromLocalStorage', () => {
8
9
  it('from localStorage to indexedDB', () => {
@@ -1,23 +1,6 @@
1
- import type { NeutralColors, PrimaryColors } from '@lobehub/ui';
2
- import type { ThemeMode } from 'antd-style';
3
-
4
1
  import { DB_Settings, DB_User } from '@/database/schemas/user';
5
- import { LocaleMode } from '@/types/locale';
6
- import { GlobalDefaultAgent, GlobalLLMConfig, GlobalTTSConfig, GlobalTool } from '@/types/settings';
7
2
 
8
- export interface V4Settings {
9
- avatar: string;
10
- defaultAgent: GlobalDefaultAgent;
11
- fontSize: number;
12
- language: LocaleMode;
13
- languageModel: GlobalLLMConfig;
14
- neutralColor?: NeutralColors;
15
- password: string;
16
- primaryColor?: PrimaryColors;
17
- themeMode: ThemeMode;
18
- tool: GlobalTool;
19
- tts: GlobalTTSConfig;
20
- }
3
+ import { V4Settings } from './type';
21
4
 
22
5
  export const migrateSettingsToUser = (settings: V4Settings): DB_User => {
23
6
  const dbSettings: DB_Settings = {
@@ -0,0 +1,100 @@
1
+ import type { ThemeMode } from 'antd-style';
2
+
3
+ import { LobeAgentTTSConfig } from '@/types/agent';
4
+ import { FewShots, LLMParams } from '@/types/llm';
5
+ import { MetaData } from '@/types/meta';
6
+ import { STTServer } from '@/types/settings';
7
+
8
+ interface V4LobeAgentConfig {
9
+ autoCreateTopicThreshold: number;
10
+ compressThreshold?: number;
11
+ displayMode?: 'chat' | 'docs';
12
+ enableAutoCreateTopic: boolean;
13
+ /**
14
+ * 历史消息长度压缩阈值
15
+ */
16
+ enableCompressThreshold?: boolean;
17
+ /**
18
+ * 开启历史记录条数
19
+ */
20
+ enableHistoryCount?: boolean;
21
+ enableMaxTokens?: boolean;
22
+
23
+ fewShots?: FewShots;
24
+ /**
25
+ * 历史消息条数
26
+ */
27
+ historyCount?: number;
28
+ inputTemplate?: string;
29
+ /**
30
+ * 角色所使用的语言模型
31
+ * @default gpt-3.5-turbo
32
+ */
33
+ model: string;
34
+ /**
35
+ * 语言模型参数
36
+ */
37
+ params: LLMParams;
38
+ /**
39
+ * 启用的插件
40
+ */
41
+ plugins?: string[];
42
+ /**
43
+ * 模型供应商
44
+ */
45
+ provider?: string;
46
+ /**
47
+ * 系统角色
48
+ */
49
+ systemRole: string;
50
+ /**
51
+ * 语音服务
52
+ */
53
+ tts: LobeAgentTTSConfig;
54
+ }
55
+
56
+ interface V4DefaultAgent {
57
+ config: V4LobeAgentConfig;
58
+ meta: MetaData;
59
+ }
60
+
61
+ interface V4OpenAIConfig {
62
+ OPENAI_API_KEY: string;
63
+ azureApiVersion?: string;
64
+ customModelName?: string;
65
+ endpoint?: string;
66
+ models?: string[];
67
+ useAzure?: boolean;
68
+ }
69
+
70
+ interface V4LLMConfig {
71
+ openAI: V4OpenAIConfig;
72
+ }
73
+
74
+ interface V4Tool {
75
+ dalle: {
76
+ autoGenerate: boolean;
77
+ };
78
+ }
79
+ interface V4TTSConfig {
80
+ openAI: {
81
+ sttModel: 'whisper-1';
82
+ ttsModel: 'tts-1' | 'tts-1-hd';
83
+ };
84
+ sttAutoStop: boolean;
85
+ sttServer: STTServer;
86
+ }
87
+
88
+ export interface V4Settings {
89
+ avatar: string;
90
+ defaultAgent: V4DefaultAgent;
91
+ fontSize: number;
92
+ language: string;
93
+ languageModel: V4LLMConfig;
94
+ neutralColor?: string;
95
+ password: string;
96
+ primaryColor?: string;
97
+ themeMode: ThemeMode;
98
+ tool: V4Tool;
99
+ tts: V4TTSConfig;
100
+ }
@@ -10,6 +10,7 @@ export interface CreateMessageParams
10
10
  extends Partial<Omit<ChatMessage, 'content' | 'role'>>,
11
11
  Pick<ChatMessage, 'content' | 'role'> {
12
12
  fromModel?: string;
13
+ fromProvider?: string;
13
14
  sessionId: string;
14
15
  }
15
16
 
@@ -215,13 +216,14 @@ class _MessageModel extends BaseModel {
215
216
 
216
217
  private mapToChatMessage = ({
217
218
  fromModel,
219
+ fromProvider,
218
220
  translate,
219
221
  tts,
220
222
  ...item
221
223
  }: DBModel<DB_Message>): ChatMessage => {
222
224
  return {
223
225
  ...item,
224
- extra: { fromModel, translate, tts },
226
+ extra: { fromModel, fromProvider, translate, tts },
225
227
  meta: {},
226
228
  topicId: item.topicId ?? undefined,
227
229
  };
@@ -24,6 +24,7 @@ export const DB_MessageSchema = z.object({
24
24
  plugin: PluginSchema.optional(),
25
25
  pluginState: z.any().optional(),
26
26
  fromModel: z.string().optional(),
27
+ fromProvider: z.string().optional(),
27
28
  translate: TranslateSchema.optional().or(z.literal(false)),
28
29
  tts: z.any().optional(),
29
30
 
@@ -42,6 +42,7 @@ export const AgentSchema = z.object({
42
42
  top_p: z.number().default(1).optional(),
43
43
  }),
44
44
  plugins: z.array(z.string()).optional(),
45
+ provider: z.string().default('openai').optional(),
45
46
  systemRole: z.string().default(''),
46
47
  tts: ttsSchema.optional(),
47
48
  });
@@ -0,0 +1,71 @@
1
+ import { Select, SelectProps } from 'antd';
2
+ import { createStyles } from 'antd-style';
3
+ import isEqual from 'fast-deep-equal';
4
+ import { memo, useMemo } from 'react';
5
+
6
+ import { ModelItemRender, ProviderItemRender } from '@/components/ModelSelect';
7
+ import { useGlobalStore } from '@/store/global';
8
+ import { modelProviderSelectors } from '@/store/global/selectors';
9
+ import { ModelProviderCard } from '@/types/llm';
10
+
11
+ import { useStore } from '../store';
12
+
13
+ const useStyles = createStyles(({ css, prefixCls }) => ({
14
+ select: css`
15
+ .${prefixCls}-select-dropdown .${prefixCls}-select-item-option-grouped {
16
+ padding-inline-start: 12px;
17
+ }
18
+ `,
19
+ }));
20
+ interface ModelOption {
21
+ label: any;
22
+ provider: string;
23
+ value: string;
24
+ }
25
+
26
+ const ModelSelect = memo(() => {
27
+ const [model, updateConfig] = useStore((s) => [s.config.model, s.setAgentConfig]);
28
+ const select = useGlobalStore(modelProviderSelectors.modelSelectList, isEqual);
29
+ const { styles } = useStyles();
30
+
31
+ const enabledList = select.filter((s) => s.enabled);
32
+
33
+ const options = useMemo<SelectProps['options']>(() => {
34
+ const getChatModels = (provider: ModelProviderCard) =>
35
+ provider.chatModels
36
+ .filter((c) => !c.hidden)
37
+ .map((model) => ({
38
+ label: <ModelItemRender {...model} />,
39
+ provider: provider.id,
40
+ value: model.id,
41
+ }));
42
+
43
+ if (enabledList.length === 1) {
44
+ const provider = enabledList[0];
45
+
46
+ return getChatModels(provider);
47
+ }
48
+
49
+ return enabledList.map((provider) => ({
50
+ label: <ProviderItemRender provider={provider.id} />,
51
+ options: getChatModels(provider),
52
+ }));
53
+ }, [enabledList]);
54
+
55
+ return (
56
+ <Select
57
+ className={styles.select}
58
+ onChange={(model, option) => {
59
+ updateConfig({
60
+ model,
61
+ provider: (option as unknown as ModelOption).provider,
62
+ });
63
+ }}
64
+ options={options}
65
+ popupMatchSelectWidth={false}
66
+ value={model}
67
+ />
68
+ );
69
+ });
70
+
71
+ export default ModelSelect;