@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
@@ -0,0 +1,23 @@
1
+ import { FormInstance } from 'antd/es/form/hooks/useForm';
2
+ import { useEffect } from 'react';
3
+
4
+ import { useGlobalStore } from '@/store/global';
5
+
6
+ export const useSyncSettings = (form: FormInstance) => {
7
+ useEffect(() => {
8
+ // set the first time
9
+ form.setFieldsValue(useGlobalStore.getState().settings);
10
+
11
+ // sync with later updated settings
12
+ const unsubscribe = useGlobalStore.subscribe(
13
+ (s) => s.settings,
14
+ (settings) => {
15
+ form.setFieldsValue(settings);
16
+ },
17
+ );
18
+
19
+ return () => {
20
+ unsubscribe();
21
+ };
22
+ }, []);
23
+ };
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, it } from 'vitest';
2
2
 
3
- import { OpenAIChatStreamPayload } from '@/types/openai/chat';
3
+ import { ChatStreamPayload } from '@/types/openai/chat';
4
4
 
5
5
  import { chainLangDetect } from '../langDetect';
6
6
 
@@ -12,7 +12,7 @@ describe('chainLangDetect', () => {
12
12
  const userContent = 'Hola';
13
13
 
14
14
  // 预期的返回值结构
15
- const expectedPayload: Partial<OpenAIChatStreamPayload> = {
15
+ const expectedPayload: Partial<ChatStreamPayload> = {
16
16
  messages: [
17
17
  {
18
18
  content:
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, it } from 'vitest';
2
2
 
3
- import { OpenAIChatStreamPayload } from '@/types/openai/chat';
3
+ import { ChatStreamPayload } from '@/types/openai/chat';
4
4
 
5
5
  import { chainPickEmoji } from '../pickEmoji';
6
6
 
@@ -12,7 +12,7 @@ describe('chainPickEmoji', () => {
12
12
  const userContent = '你是一名星际探索者';
13
13
 
14
14
  // 预期的返回值结构
15
- const expectedPayload: Partial<OpenAIChatStreamPayload> = {
15
+ const expectedPayload: Partial<ChatStreamPayload> = {
16
16
  messages: [
17
17
  {
18
18
  content:
@@ -1,6 +1,6 @@
1
- import { OpenAIChatStreamPayload } from '@/types/openai/chat';
1
+ import { ChatStreamPayload } from '@/types/openai/chat';
2
2
 
3
- export const chainLangDetect = (content: string): Partial<OpenAIChatStreamPayload> => ({
3
+ export const chainLangDetect = (content: string): Partial<ChatStreamPayload> => ({
4
4
  messages: [
5
5
  {
6
6
  content:
@@ -1,10 +1,10 @@
1
- import { OpenAIChatStreamPayload } from '@/types/openai/chat';
1
+ import { ChatStreamPayload } from '@/types/openai/chat';
2
2
 
3
3
  /**
4
4
  * pick emoji for user prompt
5
5
  * @param content
6
6
  */
7
- export const chainPickEmoji = (content: string): Partial<OpenAIChatStreamPayload> => ({
7
+ export const chainPickEmoji = (content: string): Partial<ChatStreamPayload> => ({
8
8
  messages: [
9
9
  {
10
10
  content:
@@ -1,11 +1,11 @@
1
1
  import { globalHelpers } from '@/store/global/helpers';
2
- import { OpenAIChatStreamPayload } from '@/types/openai/chat';
2
+ import { ChatStreamPayload } from '@/types/openai/chat';
3
3
 
4
4
  /**
5
5
  * summary agent name for user prompt
6
6
  * @param content
7
7
  */
8
- export const chainSummaryAgentName = (content: string): Partial<OpenAIChatStreamPayload> => ({
8
+ export const chainSummaryAgentName = (content: string): Partial<ChatStreamPayload> => ({
9
9
  messages: [
10
10
  {
11
11
  content: `你是一名擅长起名的起名大师,名字需要有文学内涵,注重精炼和赋子意境,你需要将用户的描述总结为 10 个字以内的角色,并翻译为目标语言。格式要求如下:\n输入: {文本作为JSON引用字符串} [locale]\n输出: {角色名}`,
@@ -1,7 +1,7 @@
1
1
  import { globalHelpers } from '@/store/global/helpers';
2
- import { OpenAIChatStreamPayload } from '@/types/openai/chat';
2
+ import { ChatStreamPayload } from '@/types/openai/chat';
3
3
 
4
- export const chainSummaryDescription = (content: string): Partial<OpenAIChatStreamPayload> => ({
4
+ export const chainSummaryDescription = (content: string): Partial<ChatStreamPayload> => ({
5
5
  messages: [
6
6
  {
7
7
  content: `你是一名擅长技能总结的助理,你需要将用户的输入的内容总结为一个角色技能简介,不超过 20 个字。内容需要确保信息清晰、逻辑清晰,并有效地传达角色的技能和经验,需要并翻译为目标语言:${globalHelpers.getCurrentLanguage()}。格式要求如下:\n输入: {文本作为JSON引用字符串} [locale]\n输出: {简介}`,
@@ -1,7 +1,7 @@
1
1
  import { globalHelpers } from '@/store/global/helpers';
2
- import { OpenAIChatStreamPayload } from '@/types/openai/chat';
2
+ import { ChatStreamPayload } from '@/types/openai/chat';
3
3
 
4
- export const chainSummaryTags = (content: string): Partial<OpenAIChatStreamPayload> => ({
4
+ export const chainSummaryTags = (content: string): Partial<ChatStreamPayload> => ({
5
5
  messages: [
6
6
  {
7
7
  content:
@@ -1,11 +1,11 @@
1
1
  import { chatHelpers } from '@/store/chat/helpers';
2
2
  import { globalHelpers } from '@/store/global/helpers';
3
3
  import { LanguageModel } from '@/types/llm';
4
- import { OpenAIChatMessage, OpenAIChatStreamPayload } from '@/types/openai/chat';
4
+ import { OpenAIChatMessage, ChatStreamPayload } from '@/types/openai/chat';
5
5
 
6
6
  export const chainSummaryTitle = async (
7
7
  messages: OpenAIChatMessage[],
8
- ): Promise<Partial<OpenAIChatStreamPayload>> => {
8
+ ): Promise<Partial<ChatStreamPayload>> => {
9
9
  const lang = globalHelpers.getCurrentLanguage();
10
10
 
11
11
  const finalMessages: OpenAIChatMessage[] = [
@@ -1,9 +1,9 @@
1
- import { OpenAIChatStreamPayload } from '@/types/openai/chat';
1
+ import { ChatStreamPayload } from '@/types/openai/chat';
2
2
 
3
3
  export const chainTranslate = (
4
4
  content: string,
5
5
  targetLang: string,
6
- ): Partial<OpenAIChatStreamPayload> => ({
6
+ ): Partial<ChatStreamPayload> => ({
7
7
  messages: [
8
8
  {
9
9
  content: '你是一名擅长翻译的助理,你需要将输入的语言翻译为目标语言',
@@ -0,0 +1,37 @@
1
+ import {
2
+ Anthropic,
3
+ Aws,
4
+ Baichuan,
5
+ ChatGLM,
6
+ Gemini,
7
+ Meta,
8
+ Minimax,
9
+ Mistral,
10
+ OpenAI,
11
+ Tongyi,
12
+ } from '@lobehub/icons';
13
+ import { memo } from 'react';
14
+
15
+ interface ModelProviderIconProps {
16
+ model?: string;
17
+ size?: number;
18
+ }
19
+
20
+ const ModelIcon = memo<ModelProviderIconProps>(({ model, size = 12 }) => {
21
+ if (!model) return;
22
+
23
+ if (model.startsWith('gpt-3')) return <OpenAI.Avatar size={size} type={'gpt3'} />;
24
+ if (model.startsWith('gpt-4')) return <OpenAI.Avatar size={size} type={'gpt4'} />;
25
+ if (model.startsWith('glm')) return <ChatGLM.Avatar size={size} />;
26
+ if (model.includes('claude')) return <Anthropic.Avatar size={size} />;
27
+ if (model.includes('titan')) return <Aws.Avatar size={size} />;
28
+ if (model.includes('llama')) return <Meta.Avatar size={size} />;
29
+ if (model.includes('gemini')) return <Gemini.Avatar size={size} />;
30
+ if (model.includes('qwen')) return <Tongyi.Avatar background={Tongyi.colorPrimary} size={size} />;
31
+ if (model.includes('minmax')) return <Minimax.Avatar size={size} />;
32
+ if (model.includes('baichuan'))
33
+ return <Baichuan.Avatar background={Baichuan.colorPrimary} size={size} />;
34
+ if (model.includes('mistral')) return <Mistral.Avatar size={size} />;
35
+ });
36
+
37
+ export default ModelIcon;
@@ -0,0 +1,44 @@
1
+ import { Azure, Bedrock, Google, OpenAI, Zhipu } from '@lobehub/icons';
2
+ import { memo } from 'react';
3
+ import { Center } from 'react-layout-kit';
4
+
5
+ import { ModelProvider } from '@/libs/agent-runtime';
6
+
7
+ interface ModelProviderIconProps {
8
+ provider?: string;
9
+ }
10
+
11
+ const ModelProviderIcon = memo<ModelProviderIconProps>(({ provider }) => {
12
+ switch (provider) {
13
+ case ModelProvider.ZhiPu: {
14
+ return <Zhipu size={20} />;
15
+ }
16
+
17
+ case ModelProvider.Bedrock: {
18
+ return <Bedrock size={20} />;
19
+ }
20
+
21
+ case ModelProvider.Google: {
22
+ return (
23
+ <Center height={20} width={20}>
24
+ <Google size={14} />
25
+ </Center>
26
+ );
27
+ }
28
+
29
+ case ModelProvider.Azure: {
30
+ return (
31
+ <Center height={20} width={20}>
32
+ <Azure size={14} />
33
+ </Center>
34
+ );
35
+ }
36
+
37
+ default:
38
+ case ModelProvider.OpenAI: {
39
+ return <OpenAI size={20} />;
40
+ }
41
+ }
42
+ });
43
+
44
+ export default ModelProviderIcon;
@@ -0,0 +1,133 @@
1
+ import { Icon, Tooltip } from '@lobehub/ui';
2
+ import { createStyles } from 'antd-style';
3
+ import { LucideEye, ToyBrick } from 'lucide-react';
4
+ import numeral from 'numeral';
5
+ import { rgba } from 'polished';
6
+ import { memo } from 'react';
7
+ import { useTranslation } from 'react-i18next';
8
+ import { Center, Flexbox } from 'react-layout-kit';
9
+ import ModelIcon from 'src/components/ModelIcon';
10
+ import ModelProviderIcon from 'src/components/ModelProviderIcon';
11
+
12
+ import { ChatModelCard } from '@/types/llm';
13
+
14
+ const useStyles = createStyles(({ css, token }) => ({
15
+ custom: css`
16
+ width: 36px;
17
+ height: 20px;
18
+
19
+ font-family: ${token.fontFamilyCode};
20
+ font-size: 12px;
21
+ color: ${rgba(token.colorWarning, 0.75)};
22
+
23
+ background: ${token.colorWarningBg};
24
+ border-radius: 4px;
25
+ `,
26
+ tag: css`
27
+ cursor: default;
28
+
29
+ display: flex;
30
+ align-items: center;
31
+ justify-content: center;
32
+
33
+ width: 20px;
34
+ height: 20px;
35
+
36
+ border-radius: 4px;
37
+ `,
38
+ tagBlue: css`
39
+ color: ${token.geekblue};
40
+ background: ${token.geekblue1};
41
+ `,
42
+ tagGreen: css`
43
+ color: ${token.green};
44
+ background: ${token.green1};
45
+ `,
46
+ token: css`
47
+ width: 36px;
48
+ height: 20px;
49
+
50
+ font-family: ${token.fontFamilyCode};
51
+ font-size: 11px;
52
+ color: ${token.colorTextSecondary};
53
+
54
+ background: ${token.colorFillTertiary};
55
+ border-radius: 4px;
56
+ `,
57
+ }));
58
+
59
+ interface ModelItemRenderProps extends ChatModelCard {
60
+ showInfoTag?: boolean;
61
+ }
62
+ export const ModelItemRender = memo<ModelItemRenderProps>(({ showInfoTag = true, ...model }) => {
63
+ const { styles, cx } = useStyles();
64
+ const { t } = useTranslation('common');
65
+
66
+ return (
67
+ <Flexbox align={'center'} gap={32} horizontal justify={'space-between'}>
68
+ <Flexbox align={'center'} gap={8} horizontal>
69
+ <ModelIcon model={model.id} size={20} />
70
+ {model.displayName || model.id}
71
+ </Flexbox>
72
+
73
+ {showInfoTag && (
74
+ <Flexbox gap={4} horizontal>
75
+ {model.vision && (
76
+ <Tooltip placement={'right'} title={t('ModelSelect.featureTag.vision')}>
77
+ <div className={cx(styles.tag, styles.tagGreen)}>
78
+ <Icon icon={LucideEye} />
79
+ </div>
80
+ </Tooltip>
81
+ )}
82
+ {model.functionCall && (
83
+ <Tooltip
84
+ overlayStyle={{ maxWidth: 'unset' }}
85
+ placement={'right'}
86
+ title={t('ModelSelect.featureTag.functionCall')}
87
+ >
88
+ <div className={cx(styles.tag, styles.tagBlue)}>
89
+ <Icon icon={ToyBrick} />
90
+ </div>
91
+ </Tooltip>
92
+ )}
93
+
94
+ {model.tokens && (
95
+ <Tooltip
96
+ overlayStyle={{ maxWidth: 'unset' }}
97
+ placement={'right'}
98
+ title={t('ModelSelect.featureTag.tokens', {
99
+ tokens: numeral(model.tokens).format('0,0'),
100
+ })}
101
+ >
102
+ <Center className={styles.token}>{Math.floor(model.tokens / 1000)}K</Center>
103
+ </Tooltip>
104
+ )}
105
+ {model.isCustom && (
106
+ <Tooltip
107
+ overlayStyle={{ maxWidth: 300 }}
108
+ placement={'right'}
109
+ title={t('ModelSelect.featureTag.custom')}
110
+ >
111
+ <Center className={styles.custom}>DIY</Center>
112
+ </Tooltip>
113
+ )}
114
+ </Flexbox>
115
+ )}
116
+ </Flexbox>
117
+ );
118
+ });
119
+
120
+ interface ProviderItemRenderProps {
121
+ provider: string;
122
+ }
123
+
124
+ export const ProviderItemRender = memo<ProviderItemRenderProps>(({ provider }) => {
125
+ const { t } = useTranslation('common');
126
+
127
+ return (
128
+ <Flexbox align={'center'} gap={4} horizontal>
129
+ <ModelProviderIcon provider={provider} />
130
+ {t(`modelProvider.${provider}` as any)}
131
+ </Flexbox>
132
+ );
133
+ });
@@ -0,0 +1,35 @@
1
+ import {
2
+ Anthropic,
3
+ Aws,
4
+ Baichuan,
5
+ ChatGLM,
6
+ Gemini,
7
+ Meta,
8
+ Minimax,
9
+ Mistral,
10
+ OpenAI,
11
+ Tongyi,
12
+ } from '@lobehub/icons';
13
+ import { memo } from 'react';
14
+
15
+ interface ModelIconProps {
16
+ model?: string;
17
+ size?: number;
18
+ }
19
+
20
+ const ModelIcon = memo<ModelIconProps>(({ model, size = 12 }) => {
21
+ if (!model) return;
22
+
23
+ if (model.startsWith('gpt')) return <OpenAI size={size} />;
24
+ if (model.startsWith('glm')) return <ChatGLM size={size} />;
25
+ if (model.includes('claude')) return <Anthropic size={size} />;
26
+ if (model.includes('titan')) return <Aws size={size} />;
27
+ if (model.includes('llama')) return <Meta size={size} />;
28
+ if (model.includes('gemini')) return <Gemini size={size} />;
29
+ if (model.includes('qwen')) return <Tongyi size={size} />;
30
+ if (model.includes('minmax')) return <Minimax size={size} />;
31
+ if (model.includes('baichuan')) return <Baichuan size={size} />;
32
+ if (model.includes('mistral')) return <Mistral size={size} />;
33
+ });
34
+
35
+ export default ModelIcon;
@@ -0,0 +1,13 @@
1
+ import { Tag } from '@lobehub/ui';
2
+ import { memo } from 'react';
3
+
4
+ import ModelIcon from './ModelIcon';
5
+
6
+ interface ModelTagProps {
7
+ model: string;
8
+ }
9
+ const ModelTag = memo<ModelTagProps>(({ model }) => (
10
+ <Tag icon={<ModelIcon model={model} />}>{model}</Tag>
11
+ ));
12
+
13
+ export default ModelTag;
@@ -0,0 +1,43 @@
1
+ import { ModelProviderCard } from '@/types/llm';
2
+
3
+ const Bedrock: ModelProviderCard = {
4
+ chatModels: [
5
+ {
6
+ description:
7
+ 'Amazon Titan Text G1 - Express v1,上下文长度可达 8000 个 token,适合广泛的用途。',
8
+ displayName: 'Titan Text G1 - Express',
9
+ hidden: true,
10
+ id: 'amazon.titan-text-express-v1:0:8k',
11
+ tokens: 8000,
12
+ },
13
+ {
14
+ description:
15
+ 'Claude Instant 1.2 v1.2,上下文大小等于 100k,一个更快更便宜但仍然非常能干的模型,可以处理包括随意对话在内的多种任务。',
16
+ displayName: 'Claude Instant 1.2',
17
+ id: 'anthropic.claude-instant-v1',
18
+ tokens: 100_000,
19
+ },
20
+ {
21
+ description:
22
+ 'Claude 2.1 v2.1,上下文大小等于 200k,Claude 2 的更新版本,特性包括双倍的上下文窗口,以及在可靠性等方面的提升。',
23
+ displayName: 'Claude 2.1',
24
+ id: 'anthropic.claude-v2:1',
25
+ tokens: 200_000,
26
+ },
27
+ {
28
+ description: 'Llama 2 Chat 13B v1,上下文大小为 4k,Llama 2 模型的对话用例优化变体。',
29
+ displayName: 'Llama 2 Chat 13B',
30
+ id: 'meta.llama2-13b-chat-v1',
31
+ tokens: 4000,
32
+ },
33
+ {
34
+ description: 'Llama 2 Chat 70B v1,上下文大小为 4k,Llama 2 模型的对话用例优化变体。',
35
+ displayName: 'Llama 2 Chat 70B',
36
+ id: 'meta.llama2-70b-chat-v1',
37
+ tokens: 4000,
38
+ },
39
+ ],
40
+ id: 'bedrock',
41
+ };
42
+
43
+ export default Bedrock;
@@ -0,0 +1,20 @@
1
+ import { ModelProviderCard } from '@/types/llm';
2
+
3
+ const Google: ModelProviderCard = {
4
+ chatModels: [
5
+ {
6
+ displayName: 'Gemini Pro',
7
+ id: 'gemini-pro',
8
+ tokens: 32_768,
9
+ },
10
+ {
11
+ displayName: 'Gemini Pro Vision',
12
+ id: 'gemini-pro-vision',
13
+ tokens: 16_384,
14
+ vision: true,
15
+ },
16
+ ],
17
+ id: 'google',
18
+ };
19
+
20
+ export default Google;
@@ -0,0 +1,18 @@
1
+ import { ChatModelCard } from '@/types/llm';
2
+
3
+ import BedrockProvider from './bedrock';
4
+ import GoogleProvider from './google';
5
+ import OpenAIProvider from './openai';
6
+ import ZhiPuProvider from './zhipu';
7
+
8
+ export const LOBE_DEFAULT_MODEL_LIST: ChatModelCard[] = [
9
+ OpenAIProvider.chatModels,
10
+ ZhiPuProvider.chatModels,
11
+ BedrockProvider.chatModels,
12
+ GoogleProvider.chatModels,
13
+ ].flat();
14
+
15
+ export { default as BedrockProvider } from './bedrock';
16
+ export { default as GoogleProvider } from './google';
17
+ export { default as OpenAIProvider } from './openai';
18
+ export { default as ZhiPuProvider } from './zhipu';
@@ -0,0 +1,102 @@
1
+ import { ModelProviderCard } from '@/types/llm';
2
+
3
+ // refs to: https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo
4
+ const OpenAI: ModelProviderCard = {
5
+ chatModels: [
6
+ {
7
+ description: 'GPT 3.5 Turbo,适用于各种文本生成和理解任务',
8
+ displayName: 'GPT-3.5 Turbo',
9
+ functionCall: true,
10
+ id: 'gpt-3.5-turbo',
11
+ tokens: 4096,
12
+ },
13
+ {
14
+ displayName: 'GPT-3.5 Turbo (0125)',
15
+ functionCall: true,
16
+ id: 'gpt-3.5-turbo-0125',
17
+ tokens: 16_385,
18
+ },
19
+ {
20
+ displayName: 'GPT-3.5 Turbo (1106)',
21
+ functionCall: true,
22
+ hidden: true,
23
+ id: 'gpt-3.5-turbo-1106',
24
+ tokens: 16_385,
25
+ },
26
+ {
27
+ hidden: true,
28
+ id: 'gpt-3.5-turbo-instruct',
29
+ tokens: 4096,
30
+ },
31
+ {
32
+ hidden: true,
33
+ id: 'gpt-3.5-turbo-16k',
34
+ tokens: 16_385,
35
+ },
36
+ {
37
+ hidden: true,
38
+ id: 'gpt-3.5-turbo-0613',
39
+ legacy: true,
40
+ tokens: 4096,
41
+ },
42
+ {
43
+ hidden: true,
44
+ id: 'gpt-3.5-turbo-16k-0613',
45
+ legacy: true,
46
+ tokens: 4096,
47
+ },
48
+ {
49
+ displayName: 'GPT-4 Turbo Preview',
50
+ functionCall: true,
51
+ id: 'gpt-4-turbo-preview',
52
+ tokens: 128_000,
53
+ },
54
+ {
55
+ displayName: 'GPT-4 Turbo Preview (0125)',
56
+ functionCall: true,
57
+ id: 'gpt-4-0125-preview',
58
+ tokens: 128_000,
59
+ },
60
+ {
61
+ description: 'GPT-4 视觉预览版,支持视觉任务',
62
+ displayName: 'GPT-4 Turbo Vision (Preview)',
63
+ id: 'gpt-4-vision-preview',
64
+ tokens: 128_000,
65
+ vision: true,
66
+ },
67
+ {
68
+ functionCall: true,
69
+ hidden: true,
70
+ id: 'gpt-4-1106-preview',
71
+ tokens: 128_000,
72
+ },
73
+ {
74
+ functionCall: true,
75
+ hidden: true,
76
+ id: 'gpt-4',
77
+ tokens: 8192,
78
+ },
79
+ {
80
+ functionCall: true,
81
+ hidden: true,
82
+ id: 'gpt-4-0613',
83
+ tokens: 8192,
84
+ },
85
+ {
86
+ functionCall: true,
87
+ hidden: true,
88
+ id: 'gpt-4-32k',
89
+ tokens: 32_768,
90
+ },
91
+ {
92
+ functionCall: true,
93
+ hidden: true,
94
+ id: 'gpt-4-32k-0613',
95
+ tokens: 32_768,
96
+ },
97
+ ],
98
+ enabled: true,
99
+ id: 'openai',
100
+ };
101
+
102
+ export default OpenAI;
@@ -0,0 +1,34 @@
1
+ import { ModelProviderCard } from '@/types/llm';
2
+
3
+ // TODO: 等待 ZhiPu 修复 API 问题后开启 functionCall
4
+ // refs: https://github.com/lobehub/lobe-chat/discussions/737#discussioncomment-8315815
5
+ // 暂时不透出 GLM 系列的 function_call 功能
6
+ const ZhiPu: ModelProviderCard = {
7
+ chatModels: [
8
+ {
9
+ description: '最新的 GLM-4 、最大支持 128k 上下文、支持 Function Call 、Retreival',
10
+ displayName: 'GLM-4',
11
+ // functionCall: true,
12
+ id: 'glm-4',
13
+ tokens: 128_000,
14
+ },
15
+ {
16
+ description:
17
+ '实现了视觉语言特征的深度融合,支持视觉问答、图像字幕、视觉定位、复杂目标检测等各类多模态理解任务',
18
+ displayName: 'GLM-4 Vision',
19
+ id: 'glm-4v',
20
+ tokens: 128_000,
21
+ vision: true,
22
+ },
23
+ {
24
+ description: '最新的glm-3-turbo、最大支持 128k上下文、支持Function Call、Retreival',
25
+ displayName: 'GLM-3 Turbo',
26
+ // functionCall: true,
27
+ id: 'glm-3-turbo',
28
+ tokens: 128_000,
29
+ },
30
+ ],
31
+ id: 'zhipu',
32
+ };
33
+
34
+ export default ZhiPu;