@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.
- package/.env.example +22 -2
- package/.eslintrc.js +1 -0
- package/CHANGELOG.md +25 -0
- package/README.md +11 -9
- package/README.zh-CN.md +11 -9
- package/docs/Deployment/Environment-Variable.md +65 -23
- package/docs/Deployment/Environment-Variable.zh-CN.md +64 -22
- package/locales/ar/chat.json +12 -1
- package/locales/ar/common.json +16 -0
- package/locales/ar/error.json +35 -6
- package/locales/ar/setting.json +53 -6
- package/locales/de-DE/chat.json +12 -1
- package/locales/de-DE/common.json +16 -0
- package/locales/de-DE/error.json +35 -6
- package/locales/de-DE/setting.json +53 -6
- package/locales/en-US/chat.json +13 -2
- package/locales/en-US/common.json +16 -0
- package/locales/en-US/error.json +35 -6
- package/locales/en-US/setting.json +53 -6
- package/locales/es-ES/chat.json +12 -1
- package/locales/es-ES/common.json +16 -0
- package/locales/es-ES/error.json +35 -6
- package/locales/es-ES/setting.json +53 -6
- package/locales/fr-FR/chat.json +13 -2
- package/locales/fr-FR/common.json +16 -0
- package/locales/fr-FR/error.json +35 -6
- package/locales/fr-FR/setting.json +53 -6
- package/locales/it-IT/chat.json +12 -1
- package/locales/it-IT/common.json +16 -0
- package/locales/it-IT/error.json +35 -6
- package/locales/it-IT/setting.json +53 -6
- package/locales/ja-JP/chat.json +12 -1
- package/locales/ja-JP/common.json +16 -0
- package/locales/ja-JP/error.json +35 -6
- package/locales/ja-JP/setting.json +53 -6
- package/locales/ko-KR/chat.json +12 -1
- package/locales/ko-KR/common.json +16 -0
- package/locales/ko-KR/error.json +35 -6
- package/locales/ko-KR/setting.json +53 -6
- package/locales/nl-NL/chat.json +12 -1
- package/locales/nl-NL/common.json +16 -0
- package/locales/nl-NL/error.json +35 -6
- package/locales/nl-NL/setting.json +53 -6
- package/locales/pl-PL/chat.json +12 -1
- package/locales/pl-PL/common.json +16 -0
- package/locales/pl-PL/error.json +35 -6
- package/locales/pl-PL/setting.json +53 -6
- package/locales/pt-BR/chat.json +12 -1
- package/locales/pt-BR/common.json +16 -0
- package/locales/pt-BR/error.json +35 -6
- package/locales/pt-BR/setting.json +53 -6
- package/locales/ru-RU/chat.json +12 -1
- package/locales/ru-RU/common.json +16 -0
- package/locales/ru-RU/error.json +35 -6
- package/locales/ru-RU/setting.json +53 -6
- package/locales/tr-TR/chat.json +12 -1
- package/locales/tr-TR/common.json +16 -0
- package/locales/tr-TR/error.json +35 -6
- package/locales/tr-TR/setting.json +53 -6
- package/locales/vi-VN/chat.json +12 -1
- package/locales/vi-VN/common.json +16 -0
- package/locales/vi-VN/error.json +35 -6
- package/locales/vi-VN/setting.json +53 -6
- package/locales/zh-CN/chat.json +12 -1
- package/locales/zh-CN/common.json +16 -0
- package/locales/zh-CN/error.json +34 -5
- package/locales/zh-CN/setting.json +59 -12
- package/locales/zh-TW/chat.json +12 -1
- package/locales/zh-TW/common.json +16 -0
- package/locales/zh-TW/error.json +35 -6
- package/locales/zh-TW/setting.json +53 -6
- package/next.config.mjs +8 -2
- package/package.json +8 -1
- package/src/app/api/chat/[provider]/agentRuntime.ts +129 -0
- package/src/app/api/chat/[provider]/route.ts +64 -0
- package/src/app/api/chat/auth.ts +42 -0
- package/src/app/api/chat/google/route.ts +86 -0
- package/src/app/api/config/route.ts +6 -1
- package/src/app/api/config.ts +3 -3
- package/src/app/api/errorResponse.test.ts +8 -8
- package/src/app/api/errorResponse.ts +43 -6
- package/src/app/api/openai/createBizOpenAI/createAzureOpenai.ts +1 -1
- package/src/app/api/openai/createBizOpenAI/createOpenai.ts +1 -1
- package/src/app/api/openai/createBizOpenAI/index.ts +2 -2
- package/src/app/chat/(desktop)/features/ChatHeader.tsx +6 -4
- package/src/app/chat/(desktop)/features/ChatInput/Footer/index.tsx +13 -3
- package/src/app/chat/(desktop)/features/ChatInput/Header/index.tsx +16 -24
- package/src/app/chat/(desktop)/features/SideBar/index.tsx +1 -0
- package/src/app/chat/features/ChatHeader/ShareButton/Preview.tsx +3 -3
- package/src/app/chat/features/SessionListContent/List/Item/index.tsx +2 -3
- package/src/app/settings/llm/Azure/index.tsx +145 -0
- package/src/app/settings/llm/Bedrock/index.tsx +109 -0
- package/src/app/settings/llm/{LLM/Checker.tsx → Checker.tsx} +11 -14
- package/src/app/settings/llm/Google/index.tsx +74 -0
- package/src/app/settings/llm/{LLM → OpenAI}/index.tsx +26 -44
- package/src/app/settings/llm/Zhipu/index.tsx +78 -0
- package/src/app/settings/llm/const.ts +13 -0
- package/src/app/settings/llm/page.tsx +42 -2
- package/src/app/settings/llm/useSyncSettings.ts +23 -0
- package/src/chains/__tests__/langDetect.test.ts +2 -2
- package/src/chains/__tests__/pickEmoji.test.ts +2 -2
- package/src/chains/langDetect.ts +2 -2
- package/src/chains/pickEmoji.ts +2 -2
- package/src/chains/summaryAgentName.ts +2 -2
- package/src/chains/summaryDescription.ts +2 -2
- package/src/chains/summaryTags.ts +2 -2
- package/src/chains/summaryTitle.ts +2 -2
- package/src/chains/translate.ts +2 -2
- package/src/components/ModelIcon/index.tsx +37 -0
- package/src/components/ModelProviderIcon/index.tsx +44 -0
- package/src/components/ModelSelect/index.tsx +133 -0
- package/src/components/ModelTag/ModelIcon.tsx +35 -0
- package/src/components/ModelTag/index.tsx +13 -0
- package/src/config/modelProviders/bedrock.ts +43 -0
- package/src/config/modelProviders/google.ts +20 -0
- package/src/config/modelProviders/index.ts +18 -0
- package/src/config/modelProviders/openai.ts +102 -0
- package/src/config/modelProviders/zhipu.ts +34 -0
- package/src/config/{server.ts → server/app.ts} +1 -24
- package/src/config/server/index.ts +13 -0
- package/src/config/server/provider.ts +78 -0
- package/src/const/auth.ts +30 -0
- package/src/const/fetch.ts +3 -0
- package/src/const/settings.ts +24 -4
- package/src/database/core/migrations/migrateSettingsToUser/index.test.ts +2 -1
- package/src/database/core/migrations/migrateSettingsToUser/index.ts +1 -18
- package/src/database/core/migrations/migrateSettingsToUser/type.ts +100 -0
- package/src/database/models/message.ts +3 -1
- package/src/database/schemas/message.ts +1 -0
- package/src/database/schemas/session.ts +1 -0
- package/src/features/AgentSetting/AgentConfig/ModelSelect.tsx +71 -0
- package/src/features/AgentSetting/AgentConfig/index.tsx +171 -161
- package/src/features/AgentSetting/AgentConfig/useSyncConfig.ts +23 -0
- package/src/features/AgentSetting/AgentPrompt/TokenTag.tsx +39 -0
- package/src/features/AgentSetting/AgentPrompt/index.tsx +4 -26
- package/src/features/AgentSetting/store/index.ts +10 -2
- package/src/features/ChatInput/ActionBar/FileUpload.tsx +11 -4
- package/src/features/ChatInput/ActionBar/ModelSwitch.tsx +56 -14
- package/src/features/ChatInput/ActionBar/Token/TokenTag.tsx +42 -7
- package/src/features/ChatInput/ActionBar/Token/index.tsx +5 -2
- package/src/features/ChatInput/ActionBar/Tools/index.tsx +11 -1
- package/src/features/ChatInput/useChatInput.ts +5 -1
- package/src/features/Conversation/Error/APIKeyForm/Bedrock.tsx +80 -0
- package/src/features/Conversation/Error/APIKeyForm/Google.tsx +61 -0
- package/src/features/Conversation/Error/APIKeyForm/OpenAI.tsx +63 -0
- package/src/features/Conversation/Error/APIKeyForm/Zhipu.tsx +62 -0
- package/src/features/Conversation/Error/APIKeyForm/index.tsx +72 -0
- package/src/features/Conversation/Error/AccessCodeForm.tsx +63 -0
- package/src/features/Conversation/Error/ErrorJsonViewer.tsx +26 -0
- package/src/features/Conversation/Error/InvalidAPIKey.tsx +16 -0
- package/src/features/Conversation/Error/InvalidAccessCode.tsx +50 -0
- package/src/features/Conversation/Error/OpenAiBizError.tsx +9 -17
- package/src/features/Conversation/Error/{Plugin/PluginSettings.tsx → PluginSettings.tsx} +8 -3
- package/src/features/Conversation/Error/index.tsx +75 -70
- package/src/features/Conversation/Error/style.tsx +9 -3
- package/src/features/Conversation/Extras/Assistant.tsx +2 -3
- package/src/features/Conversation/Plugins/Inspector/index.tsx +8 -2
- package/src/features/Conversation/components/ChatItem/index.tsx +9 -24
- package/src/features/Conversation/types/index.tsx +2 -5
- package/src/hooks/_header.ts +35 -0
- package/src/libs/agent-runtime/BaseAI.ts +9 -0
- package/src/libs/agent-runtime/azureOpenai/index.ts +72 -0
- package/src/libs/agent-runtime/bedrock/index.ts +134 -0
- package/src/libs/agent-runtime/error.ts +26 -0
- package/src/libs/agent-runtime/google/index.ts +160 -0
- package/src/libs/agent-runtime/index.ts +9 -0
- package/src/libs/agent-runtime/openai/index.test.ts +176 -0
- package/src/libs/agent-runtime/openai/index.ts +107 -0
- package/src/libs/agent-runtime/types/chat.ts +119 -0
- package/src/libs/agent-runtime/types/index.ts +2 -0
- package/src/libs/agent-runtime/types/type.ts +34 -0
- package/src/libs/agent-runtime/utils/createError.ts +10 -0
- package/src/libs/agent-runtime/utils/debugStream.ts +18 -0
- package/src/libs/agent-runtime/utils/env.ts +1 -0
- package/src/libs/agent-runtime/utils/handleOpenAIError.ts +39 -0
- package/src/libs/agent-runtime/utils/uriParser.ts +16 -0
- package/src/libs/agent-runtime/zhipu/authToken.ts +22 -0
- package/src/libs/agent-runtime/zhipu/index.ts +125 -0
- package/src/locales/default/chat.ts +12 -2
- package/src/locales/default/common.ts +16 -0
- package/src/locales/default/error.ts +42 -5
- package/src/locales/default/setting.ts +61 -12
- package/src/services/__tests__/chat.test.ts +8 -2
- package/src/services/__tests__/message.test.ts +1 -1
- package/src/services/_auth.ts +106 -0
- package/src/services/_header.ts +1 -0
- package/src/services/_url.ts +0 -2
- package/src/services/chat.ts +32 -14
- package/src/store/chat/slices/message/action.ts +9 -6
- package/src/store/global/slices/common/action.ts +8 -2
- package/src/store/global/slices/settings/action.test.ts +2 -2
- package/src/store/global/slices/settings/action.ts +11 -4
- package/src/store/global/slices/settings/selectors/__snapshots__/modelProvider.test.ts.snap +242 -78
- package/src/store/global/slices/settings/selectors/__snapshots__/selectors.test.ts.snap +2 -0
- package/src/store/global/slices/settings/selectors/modelProvider.test.ts +171 -47
- package/src/store/global/slices/settings/selectors/modelProvider.ts +136 -43
- package/src/store/session/slices/agent/selectors.test.ts +0 -48
- package/src/store/session/slices/agent/selectors.ts +7 -12
- package/src/types/agent/index.ts +6 -2
- package/src/types/fetch.ts +4 -2
- package/src/types/files.ts +3 -3
- package/src/types/llm.ts +27 -0
- package/src/types/message/index.ts +7 -3
- package/src/types/openai/chat.ts +6 -11
- package/src/types/settings/index.ts +1 -0
- package/src/types/settings/modelProvider.ts +37 -1
- package/src/utils/__snapshots__/parseModels.test.ts.snap +63 -0
- package/src/utils/parseModels.test.ts +24 -0
- package/src/utils/parseModels.ts +37 -0
- package/src/app/api/openai/chat/createChatCompletion.test.ts +0 -166
- package/src/app/api/openai/chat/createChatCompletion.ts +0 -76
- package/src/app/api/openai/chat/route.ts +0 -19
- package/src/app/api/openai/models/route.ts +0 -17
- package/src/app/settings/llm/LLM/ModelList.tsx +0 -51
- package/src/app/settings/llm/LLM/getModelList.ts +0 -9
- package/src/app/settings/llm/index.tsx +0 -36
- package/src/const/llm.ts +0 -32
- package/src/features/Conversation/Error/ApiKeyForm.tsx +0 -87
- package/src/features/Conversation/Error/ErrorActionContainer.tsx +0 -23
- package/src/features/Conversation/Error/InvalidAccess.tsx +0 -90
- package/src/features/Conversation/Error/OpenAPIKey.tsx +0 -13
- package/src/features/Conversation/Error/Plugin/PluginError.tsx +0 -30
- package/src/services/modelList.ts +0 -15
- /package/src/app/chat/(desktop)/features/ChatInput/{Header → Footer}/DragUpload.tsx +0 -0
- /package/src/{app/api/openai/chat → libs/agent-runtime/utils}/desensitizeUrl.test.ts +0 -0
- /package/src/{app/api/openai/chat → libs/agent-runtime/utils}/desensitizeUrl.ts +0 -0
- /package/src/types/{translate.ts → message/translate.ts} +0 -0
package/locales/zh-CN/chat.json
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
+
"ModelSwitch": {
|
|
3
|
+
"title": "模型"
|
|
4
|
+
},
|
|
2
5
|
"agentDefaultMessage": "你好,我是 **{{name}}**,你可以立即与我开始对话,也可以前往 [助手设置](/chat/settings#session={{id}}) 完善我的信息。",
|
|
3
6
|
"agentDefaultMessageWithSystemRole": "你好,我是 **{{name}}**,{{systemRole}},让我们开始对话吧!",
|
|
4
7
|
"backToBottom": "跳转至当前",
|
|
@@ -64,7 +67,14 @@
|
|
|
64
67
|
"prettifying": "润色中..."
|
|
65
68
|
},
|
|
66
69
|
"temp": "临时",
|
|
67
|
-
"
|
|
70
|
+
"tokenDetails": {
|
|
71
|
+
"chats": "会话消息",
|
|
72
|
+
"rest": "剩余可用",
|
|
73
|
+
"systemRole": "角色设定",
|
|
74
|
+
"tools": "插件设定",
|
|
75
|
+
"total": "总共可用",
|
|
76
|
+
"used": "总计使用"
|
|
77
|
+
},
|
|
68
78
|
"tokenTag": {
|
|
69
79
|
"overload": "超过限制",
|
|
70
80
|
"remained": "剩余",
|
|
@@ -102,6 +112,7 @@
|
|
|
102
112
|
"updateAgent": "更新助理信息",
|
|
103
113
|
"upload": {
|
|
104
114
|
"actionTooltip": "上传图片",
|
|
115
|
+
"disabled": "当前模型不支持视觉识别,请切换模型后使用",
|
|
105
116
|
"dragDesc": "拖拽文件到这里,支持上传多个图片。按住 Shift 直接发送图片",
|
|
106
117
|
"dragTitle": "上传图片"
|
|
107
118
|
}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
{
|
|
2
|
+
"ModelSelect": {
|
|
3
|
+
"featureTag": {
|
|
4
|
+
"custom": "自定义模型,默认设定同时支持函数调用与视觉识别,请根据实际情况验证上述能力的可用性",
|
|
5
|
+
"functionCall": "该模型支持函数调用(Function Call)",
|
|
6
|
+
"tokens": "该模型单个会话最多支持 {{tokens}} Tokens",
|
|
7
|
+
"vision": "该模型支持视觉识别"
|
|
8
|
+
}
|
|
9
|
+
},
|
|
2
10
|
"about": "关于",
|
|
3
11
|
"advanceSettings": "高级设置",
|
|
4
12
|
"agentMaxToken": "会话最大长度",
|
|
@@ -89,6 +97,14 @@
|
|
|
89
97
|
"zh-TW": "繁体中文"
|
|
90
98
|
},
|
|
91
99
|
"layoutInitializing": "正在加载布局...",
|
|
100
|
+
"modelProvider": {
|
|
101
|
+
"azure": "Azure",
|
|
102
|
+
"bedrock": "AWS Bedrock",
|
|
103
|
+
"google": "Google",
|
|
104
|
+
"oneapi": "One API",
|
|
105
|
+
"openai": "OpenAI",
|
|
106
|
+
"zhipu": "智谱AI"
|
|
107
|
+
},
|
|
92
108
|
"noDescription": "暂无描述",
|
|
93
109
|
"ok": "确定",
|
|
94
110
|
"password": "密码",
|
package/locales/zh-CN/error.json
CHANGED
|
@@ -45,9 +45,19 @@
|
|
|
45
45
|
"PluginServerError": "插件服务端请求返回出错,请检查根据下面的报错信息检查你的插件描述文件、插件配置或服务端实现",
|
|
46
46
|
"PluginGatewayError": "很抱歉,插件网关出现错误,请检查插件网关配置是否正确",
|
|
47
47
|
"PluginOpenApiInitError": "很抱歉,OpenAPI 客户端初始化失败,请检查 OpenAPI 的配置信息是否正确",
|
|
48
|
-
"InvalidAccessCode": "密码不正确或为空,请输入正确的访问密码,或者添加自定义
|
|
48
|
+
"InvalidAccessCode": "密码不正确或为空,请输入正确的访问密码,或者添加自定义 API Key",
|
|
49
|
+
"LocationNotSupportError": "很抱歉,你的所在位置不支持此模型服务,可能是由于地区限制或服务未开通。请确认当前位置是否支持使用此服务,或尝试使用其他位置信息。",
|
|
49
50
|
"OpenAIBizError": "请求 OpenAI 服务出错,请根据以下信息排查或重试",
|
|
50
|
-
"
|
|
51
|
+
"NoOpenAIAPIKey": "OpenAI API Key 为空,请添加自定义 OpenAI API Key",
|
|
52
|
+
"ZhipuBizError": "请求智谱服务出错,请根据以下信息排查或重试",
|
|
53
|
+
"InvalidZhipuAPIKey": "Zhipu API Key 不正确或为空,请检查 Zhipu API Key 后重试",
|
|
54
|
+
"GoogleBizError": "请求 Google 服务出错,请根据以下信息排查或重试",
|
|
55
|
+
"InvalidGoogleAPIKey": "Google API Key 不正确或为空,请检查 Google API Key 后重试",
|
|
56
|
+
"InvalidBedrockCredentials": "Bedrock 鉴权未通过,请检查 AccessKeyId/SecretAccessKey 后重试",
|
|
57
|
+
"BedrockBizError": "请求 Bedrock 服务出错,请根据以下信息排查或重试",
|
|
58
|
+
"InvalidAzureAPIKey": "Azure API Key 不正确或为空,请检查 Azure API Key 后重试",
|
|
59
|
+
"AzureBizError": "请求 Azure AI 服务出错,请根据以下信息排查或重试",
|
|
60
|
+
"AgentRuntimeError": "Lobe 语言模型运行时执行出错,请根据以下信息排查或重试"
|
|
51
61
|
},
|
|
52
62
|
"stt": {
|
|
53
63
|
"responseError": "服务请求失败,请检查配置或重试"
|
|
@@ -57,9 +67,24 @@
|
|
|
57
67
|
},
|
|
58
68
|
"unlock": {
|
|
59
69
|
"apikey": {
|
|
60
|
-
"
|
|
61
|
-
|
|
62
|
-
|
|
70
|
+
"Bedrock": {
|
|
71
|
+
"customRegion": "自定义服务区域",
|
|
72
|
+
"description": "输入你的 Aws AccessKeyId / SecretAccessKey 即可开始会话。应用不会记录你的鉴权配置",
|
|
73
|
+
"title": "使用自定义 Bedrock 鉴权信息"
|
|
74
|
+
},
|
|
75
|
+
"Google": {
|
|
76
|
+
"description": "输入你的 Google API Key 即可开始会话。应用不会记录你的 API Key",
|
|
77
|
+
"title": "使用自定义 Google API Key"
|
|
78
|
+
},
|
|
79
|
+
"OpenAI": {
|
|
80
|
+
"addProxyUrl": "添加 OpenAI 代理地址(可选)",
|
|
81
|
+
"description": "输入你的 OpenAI API Key 即可开始会话。应用不会记录你的 API Key",
|
|
82
|
+
"title": "使用自定义 OpenAI API Key"
|
|
83
|
+
},
|
|
84
|
+
"Zhipu": {
|
|
85
|
+
"description": "输入你的 Zhipu API Key 即可开始会话。应用不会记录你的 API Key",
|
|
86
|
+
"title": "使用自定义 Zhipu API Key"
|
|
87
|
+
}
|
|
63
88
|
},
|
|
64
89
|
"closeMessage": "关闭提示",
|
|
65
90
|
"confirm": "确认并重试",
|
|
@@ -67,6 +92,10 @@
|
|
|
67
92
|
"description": "管理员已开启应用加密,输入应用密码后即可解锁应用。密码只需填写一次",
|
|
68
93
|
"placeholder": "请输入密码",
|
|
69
94
|
"title": "输入密码解锁应用"
|
|
95
|
+
},
|
|
96
|
+
"tabs": {
|
|
97
|
+
"apiKey": "自定义 API Key",
|
|
98
|
+
"password": "密码"
|
|
70
99
|
}
|
|
71
100
|
}
|
|
72
101
|
}
|
|
@@ -22,6 +22,15 @@
|
|
|
22
22
|
},
|
|
23
23
|
"llm": {
|
|
24
24
|
"AzureOpenAI": {
|
|
25
|
+
"azureApiVersion": {
|
|
26
|
+
"desc": "Azure 的 API 版本,遵循 YYYY-MM-DD 格式,查阅[最新版本](https://learn.microsoft.com/zh-cn/azure/ai-services/openai/reference#chat-completions)",
|
|
27
|
+
"fetch": "获取列表",
|
|
28
|
+
"title": "Azure Api Version"
|
|
29
|
+
},
|
|
30
|
+
"deployments": {
|
|
31
|
+
"desc": "使用 id=name 的语法填写你的部署模型(如部署名和模型同名,可以只填写模型名称),多个模型使用逗号(,) 隔开",
|
|
32
|
+
"title": "Azure 部署模型列表"
|
|
33
|
+
},
|
|
25
34
|
"endpoint": {
|
|
26
35
|
"desc": "从 Azure 门户检查资源时,可在“密钥和终结点”部分中找到此值",
|
|
27
36
|
"placeholder": "https://docs-test-001.openai.azure.com",
|
|
@@ -31,25 +40,48 @@
|
|
|
31
40
|
"desc": "支持的模型",
|
|
32
41
|
"title": "模型列表"
|
|
33
42
|
},
|
|
34
|
-
"title": "Azure OpenAI
|
|
43
|
+
"title": "Azure OpenAI",
|
|
35
44
|
"token": {
|
|
36
45
|
"desc": "从 Azure 门户检查资源时,可在“密钥和终结点”部分中找到此值。 可以使用 KEY1 或 KEY2",
|
|
37
46
|
"placeholder": "Azure API Key",
|
|
38
47
|
"title": "API Key"
|
|
39
48
|
}
|
|
40
49
|
},
|
|
50
|
+
"Bedrock": {
|
|
51
|
+
"accessKeyId": {
|
|
52
|
+
"desc": "填入Aws Access Key Id",
|
|
53
|
+
"placeholder": "Aws Access Key Id",
|
|
54
|
+
"title": "Aws Access Key Id"
|
|
55
|
+
},
|
|
56
|
+
"checker": {
|
|
57
|
+
"desc": "测试 AccessKeyId / SecretAccessKey 是否填写正确"
|
|
58
|
+
},
|
|
59
|
+
"region": {
|
|
60
|
+
"desc": "填入 Aws Region",
|
|
61
|
+
"placeholder": "Aws Region",
|
|
62
|
+
"title": "Aws Region"
|
|
63
|
+
},
|
|
64
|
+
"secretAccessKey": {
|
|
65
|
+
"desc": "填入 Aws Secret Access Key",
|
|
66
|
+
"placeholder": "Aws Secret Access Key",
|
|
67
|
+
"title": "Aws Secret Access Key"
|
|
68
|
+
},
|
|
69
|
+
"title": "Bedrock"
|
|
70
|
+
},
|
|
71
|
+
"Google": {
|
|
72
|
+
"title": "Google",
|
|
73
|
+
"token": {
|
|
74
|
+
"desc": "填入来自 Google 的 API Key",
|
|
75
|
+
"placeholder": "Google API Key",
|
|
76
|
+
"title": "API Key"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
41
79
|
"OpenAI": {
|
|
42
80
|
"azureApiVersion": {
|
|
43
81
|
"desc": "Azure 的 API 版本,遵循 YYYY-MM-DD 格式,查阅[最新版本](https://learn.microsoft.com/zh-cn/azure/ai-services/openai/reference#chat-completions)",
|
|
44
82
|
"fetch": "获取列表",
|
|
45
83
|
"title": "Azure Api Version"
|
|
46
84
|
},
|
|
47
|
-
"check": {
|
|
48
|
-
"button": "检查",
|
|
49
|
-
"desc": "测试 Api Key 与代理地址是否正确填写",
|
|
50
|
-
"pass": "检查通过",
|
|
51
|
-
"title": "连通性检查"
|
|
52
|
-
},
|
|
53
85
|
"customModelName": {
|
|
54
86
|
"desc": "增加自定义模型,多个模型使用逗号(,) 隔开",
|
|
55
87
|
"placeholder": "model1,model2,model3",
|
|
@@ -69,11 +101,11 @@
|
|
|
69
101
|
"refetch": "重新获取模型列表",
|
|
70
102
|
"title": "模型列表"
|
|
71
103
|
},
|
|
72
|
-
"title": "OpenAI
|
|
104
|
+
"title": "OpenAI",
|
|
73
105
|
"token": {
|
|
74
106
|
"desc": "使用自己的 OpenAI Key",
|
|
75
107
|
"placeholder": "OpenAI API Key",
|
|
76
|
-
"title": "API Key"
|
|
108
|
+
"title": "OpenAI API Key"
|
|
77
109
|
},
|
|
78
110
|
"useAzure": {
|
|
79
111
|
"desc": "使用 Azure 提供的 OpenAI 服务",
|
|
@@ -82,6 +114,20 @@
|
|
|
82
114
|
"title": "Azure OpenAI"
|
|
83
115
|
}
|
|
84
116
|
},
|
|
117
|
+
"Zhipu": {
|
|
118
|
+
"title": "智谱",
|
|
119
|
+
"token": {
|
|
120
|
+
"desc": "填入来自智谱的 API Key",
|
|
121
|
+
"placeholder": "Zhipu API Key",
|
|
122
|
+
"title": "API Key"
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
"checker": {
|
|
126
|
+
"button": "检查",
|
|
127
|
+
"desc": "测试 Api Key 与代理地址是否正确填写",
|
|
128
|
+
"pass": "检查通过",
|
|
129
|
+
"title": "连通性检查"
|
|
130
|
+
},
|
|
85
131
|
"waitingForMore": "更多模型正在 <1>计划接入</1> 中,敬请期待 ✨"
|
|
86
132
|
},
|
|
87
133
|
"plugin": {
|
|
@@ -291,14 +337,15 @@
|
|
|
291
337
|
},
|
|
292
338
|
"tools": {
|
|
293
339
|
"builtins": {
|
|
294
|
-
"groupName": "
|
|
340
|
+
"groupName": "内置插件"
|
|
295
341
|
},
|
|
342
|
+
"disabled": "当前模型不支持函数调用,无法使用插件",
|
|
296
343
|
"plugins": {
|
|
297
344
|
"enabled": "已启用 {{num}}",
|
|
298
|
-
"groupName": "
|
|
345
|
+
"groupName": "三方插件",
|
|
299
346
|
"noEnabled": "暂无启用插件",
|
|
300
347
|
"store": "插件商店"
|
|
301
348
|
},
|
|
302
|
-
"title": "
|
|
349
|
+
"title": "扩展插件"
|
|
303
350
|
}
|
|
304
351
|
}
|
package/locales/zh-TW/chat.json
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
+
"ModelSwitch": {
|
|
3
|
+
"title": "模型"
|
|
4
|
+
},
|
|
2
5
|
"agentDefaultMessage": "你好,我是 **{{name}}**,你可以立即與我開始對話,也可以前往 [助手設置](/chat/settings#session={{id}}) 完善我的信息。",
|
|
3
6
|
"agentDefaultMessageWithSystemRole": "你好,我是 **{{name}}**,{{systemRole}},讓我們開始對話吧!",
|
|
4
7
|
"backToBottom": "返回底部",
|
|
@@ -64,7 +67,14 @@
|
|
|
64
67
|
"prettifying": "潤色中..."
|
|
65
68
|
},
|
|
66
69
|
"temp": "臨時",
|
|
67
|
-
"
|
|
70
|
+
"tokenDetails": {
|
|
71
|
+
"chats": "聊天訊息",
|
|
72
|
+
"rest": "剩餘可用",
|
|
73
|
+
"systemRole": "角色設定",
|
|
74
|
+
"tools": "外掛程式設定",
|
|
75
|
+
"total": "總共可用",
|
|
76
|
+
"used": "總計使用"
|
|
77
|
+
},
|
|
68
78
|
"tokenTag": {
|
|
69
79
|
"overload": "超過限制",
|
|
70
80
|
"remained": "剩餘",
|
|
@@ -102,6 +112,7 @@
|
|
|
102
112
|
"updateAgent": "更新助理信息",
|
|
103
113
|
"upload": {
|
|
104
114
|
"actionTooltip": "上傳圖片",
|
|
115
|
+
"disabled": "當前模型不支援視覺識別,請切換模型後使用",
|
|
105
116
|
"dragDesc": "拖拽文件到這裡,支持上傳多個圖片。按住 Shift 直接發送圖片",
|
|
106
117
|
"dragTitle": "上傳圖片"
|
|
107
118
|
}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
{
|
|
2
|
+
"ModelSelect": {
|
|
3
|
+
"featureTag": {
|
|
4
|
+
"custom": "自訂模型,預設支援函數呼叫與視覺辨識,請根據實際情況驗證上述能力的可用性",
|
|
5
|
+
"functionCall": "該模型支援函數呼叫(Function Call)",
|
|
6
|
+
"tokens": "該模型單個會話最多支援 {{tokens}} Tokens",
|
|
7
|
+
"vision": "該模型支援視覺辨識"
|
|
8
|
+
}
|
|
9
|
+
},
|
|
2
10
|
"about": "關於",
|
|
3
11
|
"advanceSettings": "進階設定",
|
|
4
12
|
"agentMaxToken": "助手最大標記",
|
|
@@ -89,6 +97,14 @@
|
|
|
89
97
|
"zh-TW": "繁體中文"
|
|
90
98
|
},
|
|
91
99
|
"layoutInitializing": "正在載入版面配置...",
|
|
100
|
+
"modelProvider": {
|
|
101
|
+
"azure": "Azure",
|
|
102
|
+
"bedrock": "AWS Bedrock",
|
|
103
|
+
"google": "Google",
|
|
104
|
+
"oneapi": "One API",
|
|
105
|
+
"openai": "OpenAI",
|
|
106
|
+
"zhipu": "智譜AI"
|
|
107
|
+
},
|
|
92
108
|
"noDescription": "暫無描述",
|
|
93
109
|
"ok": "確定",
|
|
94
110
|
"password": "密碼",
|
package/locales/zh-TW/error.json
CHANGED
|
@@ -33,8 +33,17 @@
|
|
|
33
33
|
"502": "抱歉,伺服器似乎迷失了方向,暫時無法提供服務。請稍後再試。",
|
|
34
34
|
"503": "抱歉,伺服器目前無法處理您的請求,可能是因為過載或正在進行維護。請稍後再試。",
|
|
35
35
|
"504": "抱歉,伺服器沒有收到上游伺服器的回應。請稍後再試。",
|
|
36
|
-
"
|
|
37
|
-
"
|
|
36
|
+
"AgentRuntimeError": "Lobe 語言模型運行時執行出錯,請根據以下信息排查或重試",
|
|
37
|
+
"AzureBizError": "請求 Azure AI 服務出錯,請根據以下信息排查或重試",
|
|
38
|
+
"BedrockBizError": "請求 Bedrock 服務出錯,請根據以下信息排查或重試",
|
|
39
|
+
"GoogleBizError": "請求 Google 服務出錯,請根據以下信息排查或重試",
|
|
40
|
+
"InvalidAccessCode": "密碼不正確或為空,請輸入正確的訪問密碼,或添加自定義 API 金鑰",
|
|
41
|
+
"InvalidAzureAPIKey": "Azure API Key 不正確或為空,請檢查 Azure API Key 後重試",
|
|
42
|
+
"InvalidBedrockCredentials": "Bedrock 驗證未通過,請檢查 AccessKeyId/SecretAccessKey 後重試",
|
|
43
|
+
"InvalidGoogleAPIKey": "Google API Key 不正確或為空,請檢查 Google API Key 後重試",
|
|
44
|
+
"InvalidZhipuAPIKey": "Zhipu API Key 不正確或為空,請檢查 Zhipu API Key 後重試",
|
|
45
|
+
"LocationNotSupportError": "很抱歉,你的所在位置不支持此模型服務,可能是由於地區限制或服務未開通。請確認當前位置是否支持使用此服務,或嘗試使用其他位置信息。",
|
|
46
|
+
"NoOpenAIAPIKey": "OpenAI API 金鑰為空,請添加自訂 OpenAI API 金鑰",
|
|
38
47
|
"OpenAIBizError": "請求 OpenAI 服務出錯。請根據以下資訊進行排查或重試。",
|
|
39
48
|
"PluginApiNotFound": "抱歉,外掛描述檔案中不存在該 API。請檢查您的請求方法與外掛清單 API 是否相符",
|
|
40
49
|
"PluginApiParamsError": "抱歉,該外掛請求的輸入參數驗證失敗。請檢查輸入參數與 API 描述資訊是否相符",
|
|
@@ -47,7 +56,8 @@
|
|
|
47
56
|
"PluginMetaNotFound": "抱歉,索引中找不到該外掛。請檢查索引中的外掛設定資訊",
|
|
48
57
|
"PluginOpenApiInitError": "很抱歉,OpenAPI 客戶端初始化失敗,請檢查 OpenAPI 的配置信息是否正確",
|
|
49
58
|
"PluginServerError": "外掛伺服器請求回傳錯誤。請根據下面的錯誤資訊檢查您的外掛描述檔案、外掛設定或伺服器實作",
|
|
50
|
-
"PluginSettingsInvalid": "該外掛需要正確設定後才可以使用。請檢查您的設定是否正確"
|
|
59
|
+
"PluginSettingsInvalid": "該外掛需要正確設定後才可以使用。請檢查您的設定是否正確",
|
|
60
|
+
"ZhipuBizError": "請求智譜服務出錯,請根據以下信息排查或重試"
|
|
51
61
|
},
|
|
52
62
|
"stt": {
|
|
53
63
|
"responseError": "服務請求失敗,請檢查配置或重試"
|
|
@@ -57,9 +67,24 @@
|
|
|
57
67
|
},
|
|
58
68
|
"unlock": {
|
|
59
69
|
"apikey": {
|
|
60
|
-
"
|
|
61
|
-
|
|
62
|
-
|
|
70
|
+
"Bedrock": {
|
|
71
|
+
"customRegion": "自定義服務區域",
|
|
72
|
+
"description": "輸入你的 Aws AccessKeyId / SecretAccessKey 即可開始會話。應用不會記錄你的驗證配置",
|
|
73
|
+
"title": "使用自定義 Bedrock 驗證信息"
|
|
74
|
+
},
|
|
75
|
+
"Google": {
|
|
76
|
+
"description": "輸入你的 Google API Key 即可開始會話。應用不會記錄你的 API Key",
|
|
77
|
+
"title": "使用自定義 Google API Key"
|
|
78
|
+
},
|
|
79
|
+
"OpenAI": {
|
|
80
|
+
"addProxyUrl": "添加 OpenAI 代理地址(可選)",
|
|
81
|
+
"description": "輸入你的 OpenAI API Key 即可開始會話。應用不會記錄你的 API Key",
|
|
82
|
+
"title": "使用自定義 OpenAI API Key"
|
|
83
|
+
},
|
|
84
|
+
"Zhipu": {
|
|
85
|
+
"description": "輸入你的 Zhipu API Key 即可開始會話。應用不會記錄你的 API Key",
|
|
86
|
+
"title": "使用自定義 Zhipu API Key"
|
|
87
|
+
}
|
|
63
88
|
},
|
|
64
89
|
"closeMessage": "關閉提示",
|
|
65
90
|
"confirm": "確認並重試",
|
|
@@ -67,6 +92,10 @@
|
|
|
67
92
|
"description": "管理員已啟用應用程式加密,輸入應用程式密碼後即可解鎖應用程式。密碼只需填寫一次。",
|
|
68
93
|
"placeholder": "請輸入密碼",
|
|
69
94
|
"title": "輸入密碼解鎖應用程式"
|
|
95
|
+
},
|
|
96
|
+
"tabs": {
|
|
97
|
+
"apiKey": "自定義 API Key",
|
|
98
|
+
"password": "密碼"
|
|
70
99
|
}
|
|
71
100
|
}
|
|
72
101
|
}
|
|
@@ -22,6 +22,15 @@
|
|
|
22
22
|
},
|
|
23
23
|
"llm": {
|
|
24
24
|
"AzureOpenAI": {
|
|
25
|
+
"azureApiVersion": {
|
|
26
|
+
"desc": "Azure 的 API 版本,遵循 YYYY-MM-DD 格式,查閱[最新版本](https://learn.microsoft.com/zh-cn/azure/ai-services/openai/reference#chat-completions)",
|
|
27
|
+
"fetch": "獲取列表",
|
|
28
|
+
"title": "Azure API 版本"
|
|
29
|
+
},
|
|
30
|
+
"deployments": {
|
|
31
|
+
"desc": "使用 id=name 的語法填寫你的部署模型(如部署名和模型同名,可以只填寫模型名稱),多個模型使用逗號(,) 隔開",
|
|
32
|
+
"title": "Azure 部署模型列表"
|
|
33
|
+
},
|
|
25
34
|
"endpoint": {
|
|
26
35
|
"desc": "從 Azure 門戶檢查資源時,可在“金鑰和終結點”部分中找到此值",
|
|
27
36
|
"placeholder": "https://docs-test-001.openai.azure.com",
|
|
@@ -38,18 +47,41 @@
|
|
|
38
47
|
"title": "API 金鑰"
|
|
39
48
|
}
|
|
40
49
|
},
|
|
50
|
+
"Bedrock": {
|
|
51
|
+
"accessKeyId": {
|
|
52
|
+
"desc": "填入 AWS Access Key ID",
|
|
53
|
+
"placeholder": "AWS Access Key ID",
|
|
54
|
+
"title": "AWS Access Key ID"
|
|
55
|
+
},
|
|
56
|
+
"checker": {
|
|
57
|
+
"desc": "測試 Access Key ID / Secret Access Key 是否填寫正確"
|
|
58
|
+
},
|
|
59
|
+
"region": {
|
|
60
|
+
"desc": "填入 AWS Region",
|
|
61
|
+
"placeholder": "AWS Region",
|
|
62
|
+
"title": "AWS Region"
|
|
63
|
+
},
|
|
64
|
+
"secretAccessKey": {
|
|
65
|
+
"desc": "填入 AWS Secret Access Key",
|
|
66
|
+
"placeholder": "AWS Secret Access Key",
|
|
67
|
+
"title": "AWS Secret Access Key"
|
|
68
|
+
},
|
|
69
|
+
"title": "Bedrock"
|
|
70
|
+
},
|
|
71
|
+
"Google": {
|
|
72
|
+
"title": "Google",
|
|
73
|
+
"token": {
|
|
74
|
+
"desc": "填入來自 Google 的 API 金鑰",
|
|
75
|
+
"placeholder": "Google API 金鑰",
|
|
76
|
+
"title": "API 金鑰"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
41
79
|
"OpenAI": {
|
|
42
80
|
"azureApiVersion": {
|
|
43
81
|
"desc": "Azure 的 API 版本,遵循 YYYY-MM-DD 格式,查閱[最新版本](https://learn.microsoft.com/zh-cn/azure/ai-services/openai/reference#chat-completions)",
|
|
44
82
|
"fetch": "獲取列表",
|
|
45
83
|
"title": "Azure Api 版本"
|
|
46
84
|
},
|
|
47
|
-
"check": {
|
|
48
|
-
"button": "檢查",
|
|
49
|
-
"desc": "測試 Api 金鑰與代理地址是否正確填寫",
|
|
50
|
-
"pass": "檢查通過",
|
|
51
|
-
"title": "連通性檢查"
|
|
52
|
-
},
|
|
53
85
|
"customModelName": {
|
|
54
86
|
"desc": "增加自訂模型,多個模型使用逗號(,) 隔開",
|
|
55
87
|
"placeholder": "model1,model2,model3",
|
|
@@ -82,6 +114,20 @@
|
|
|
82
114
|
"title": "Azure OpenAI"
|
|
83
115
|
}
|
|
84
116
|
},
|
|
117
|
+
"Zhipu": {
|
|
118
|
+
"title": "智譜",
|
|
119
|
+
"token": {
|
|
120
|
+
"desc": "填入來自智譜的 API 金鑰",
|
|
121
|
+
"placeholder": "智譜 API 金鑰",
|
|
122
|
+
"title": "API 金鑰"
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
"checker": {
|
|
126
|
+
"button": "檢查",
|
|
127
|
+
"desc": "測試 API 金鑰與代理地址是否正確填寫",
|
|
128
|
+
"pass": "檢查通過",
|
|
129
|
+
"title": "連通性檢查"
|
|
130
|
+
},
|
|
85
131
|
"waitingForMore": "更多模型正在 <1>計劃接入</1> 中,敬請期待 ✨"
|
|
86
132
|
},
|
|
87
133
|
"plugin": {
|
|
@@ -293,6 +339,7 @@
|
|
|
293
339
|
"builtins": {
|
|
294
340
|
"groupName": "內置"
|
|
295
341
|
},
|
|
342
|
+
"disabled": "當前模型不支持函數調用,無法使用插件",
|
|
296
343
|
"plugins": {
|
|
297
344
|
"enabled": "已啟用 {{num}}",
|
|
298
345
|
"groupName": "插件",
|
package/next.config.mjs
CHANGED
|
@@ -4,6 +4,9 @@ import analyzer from '@next/bundle-analyzer';
|
|
|
4
4
|
const isProd = process.env.NODE_ENV === 'production';
|
|
5
5
|
const buildWithDocker = process.env.DOCKER === 'true';
|
|
6
6
|
|
|
7
|
+
// if you need to proxy the api endpoint to remote server
|
|
8
|
+
const API_PROXY_ENDPOINT = process.env.API_PROXY_ENDPOINT || '';
|
|
9
|
+
|
|
7
10
|
const withBundleAnalyzer = analyzer({
|
|
8
11
|
enabled: process.env.ANALYZE === 'true',
|
|
9
12
|
});
|
|
@@ -44,10 +47,13 @@ const nextConfig = {
|
|
|
44
47
|
},
|
|
45
48
|
output: buildWithDocker ? 'standalone' : undefined,
|
|
46
49
|
|
|
50
|
+
rewrites: async () => [
|
|
51
|
+
// due to google api not work correct in some countries
|
|
52
|
+
// we need a proxy to bypass the restriction
|
|
53
|
+
{ source: '/api/chat/google', destination: `${API_PROXY_ENDPOINT}/api/chat/google` },
|
|
54
|
+
],
|
|
47
55
|
reactStrictMode: true,
|
|
48
56
|
|
|
49
|
-
transpilePackages: ['antd-style'],
|
|
50
|
-
|
|
51
57
|
webpack(config) {
|
|
52
58
|
config.experiments = {
|
|
53
59
|
asyncWebAssembly: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/chat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.123.0",
|
|
4
4
|
"description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"framework",
|
|
@@ -73,10 +73,14 @@
|
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
75
|
"@ant-design/icons": "^5",
|
|
76
|
+
"@aws-sdk/client-bedrock-runtime": "^3.503.1",
|
|
77
|
+
"@azure/openai": "^1.0.0-beta.11",
|
|
76
78
|
"@cfworker/json-schema": "^1",
|
|
79
|
+
"@google/generative-ai": "^0.2.0",
|
|
77
80
|
"@icons-pack/react-simple-icons": "^9",
|
|
78
81
|
"@lobehub/chat-plugin-sdk": "latest",
|
|
79
82
|
"@lobehub/chat-plugins-gateway": "latest",
|
|
83
|
+
"@lobehub/icons": "^1.10.2",
|
|
80
84
|
"@lobehub/tts": "latest",
|
|
81
85
|
"@lobehub/ui": "latest",
|
|
82
86
|
"@vercel/analytics": "^1",
|
|
@@ -95,11 +99,13 @@
|
|
|
95
99
|
"i18next-resources-to-backend": "^1",
|
|
96
100
|
"idb-keyval": "^6",
|
|
97
101
|
"immer": "^10",
|
|
102
|
+
"jose": "^5.2.0",
|
|
98
103
|
"lodash-es": "^4",
|
|
99
104
|
"lucide-react": "latest",
|
|
100
105
|
"modern-screenshot": "^4",
|
|
101
106
|
"nanoid": "^5",
|
|
102
107
|
"next": "^14.1",
|
|
108
|
+
"numeral": "^2.0.6",
|
|
103
109
|
"nuqs": "^1.15.4",
|
|
104
110
|
"openai": "^4.22",
|
|
105
111
|
"polished": "^4",
|
|
@@ -146,6 +152,7 @@
|
|
|
146
152
|
"@types/lodash": "^4",
|
|
147
153
|
"@types/lodash-es": "^4",
|
|
148
154
|
"@types/node": "^20",
|
|
155
|
+
"@types/numeral": "^2.0.5",
|
|
149
156
|
"@types/react": "^18",
|
|
150
157
|
"@types/react-dom": "^18",
|
|
151
158
|
"@types/rtl-detect": "^1",
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { getServerConfig } from '@/config/server';
|
|
2
|
+
import { JWTPayload } from '@/const/auth';
|
|
3
|
+
import {
|
|
4
|
+
ChatStreamPayload,
|
|
5
|
+
LobeAzureOpenAI,
|
|
6
|
+
LobeBedrockAI,
|
|
7
|
+
LobeGoogleAI,
|
|
8
|
+
LobeOpenAI,
|
|
9
|
+
LobeRuntimeAI,
|
|
10
|
+
LobeZhipuAI,
|
|
11
|
+
ModelProvider,
|
|
12
|
+
} from '@/libs/agent-runtime';
|
|
13
|
+
|
|
14
|
+
interface AzureOpenAIParams {
|
|
15
|
+
apiVersion?: string;
|
|
16
|
+
model: string;
|
|
17
|
+
useAzure?: boolean;
|
|
18
|
+
}
|
|
19
|
+
class AgentRuntime {
|
|
20
|
+
private _runtime: LobeRuntimeAI;
|
|
21
|
+
|
|
22
|
+
constructor(runtime: LobeRuntimeAI) {
|
|
23
|
+
this._runtime = runtime;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async chat(payload: ChatStreamPayload) {
|
|
27
|
+
return this._runtime.chat(payload);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static async initializeWithUserPayload(
|
|
31
|
+
provider: string,
|
|
32
|
+
payload: JWTPayload,
|
|
33
|
+
azureOpenAI?: AzureOpenAIParams,
|
|
34
|
+
) {
|
|
35
|
+
let runtimeModel: LobeRuntimeAI;
|
|
36
|
+
|
|
37
|
+
switch (provider) {
|
|
38
|
+
default:
|
|
39
|
+
case 'oneapi':
|
|
40
|
+
case ModelProvider.OpenAI: {
|
|
41
|
+
runtimeModel = this.initOpenAI(payload, azureOpenAI);
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
case ModelProvider.Azure: {
|
|
46
|
+
runtimeModel = this.initAzureOpenAI(payload);
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
case ModelProvider.ZhiPu: {
|
|
51
|
+
runtimeModel = await this.initZhipu(payload);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
case ModelProvider.Google: {
|
|
56
|
+
runtimeModel = this.initGoogle(payload);
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
case ModelProvider.Bedrock: {
|
|
61
|
+
runtimeModel = this.initBedrock(payload);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return new AgentRuntime(runtimeModel);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private static initOpenAI(payload: JWTPayload, azureOpenAI?: AzureOpenAIParams) {
|
|
69
|
+
const { OPENAI_API_KEY, OPENAI_PROXY_URL, AZURE_API_VERSION, AZURE_API_KEY, USE_AZURE_OPENAI } =
|
|
70
|
+
getServerConfig();
|
|
71
|
+
const apiKey = payload?.apiKey || OPENAI_API_KEY;
|
|
72
|
+
const baseURL = payload?.endpoint || OPENAI_PROXY_URL;
|
|
73
|
+
|
|
74
|
+
const azureApiKey = payload.apiKey || AZURE_API_KEY;
|
|
75
|
+
const useAzure = azureOpenAI?.useAzure || USE_AZURE_OPENAI;
|
|
76
|
+
const apiVersion = azureOpenAI?.apiVersion || AZURE_API_VERSION;
|
|
77
|
+
|
|
78
|
+
return new LobeOpenAI({
|
|
79
|
+
apiKey: azureOpenAI?.useAzure ? azureApiKey : apiKey,
|
|
80
|
+
azureOptions: {
|
|
81
|
+
apiVersion,
|
|
82
|
+
model: azureOpenAI?.model,
|
|
83
|
+
},
|
|
84
|
+
baseURL,
|
|
85
|
+
useAzure,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
private static initAzureOpenAI(payload: JWTPayload) {
|
|
90
|
+
const { AZURE_API_KEY, AZURE_API_VERSION, AZURE_ENDPOINT } = getServerConfig();
|
|
91
|
+
const apiKey = payload?.apiKey || AZURE_API_KEY;
|
|
92
|
+
const endpoint = payload?.endpoint || AZURE_ENDPOINT;
|
|
93
|
+
const apiVersion = payload?.azureApiVersion || AZURE_API_VERSION;
|
|
94
|
+
|
|
95
|
+
return new LobeAzureOpenAI(endpoint, apiKey, apiVersion);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private static async initZhipu(payload: JWTPayload) {
|
|
99
|
+
const { ZHIPU_API_KEY } = getServerConfig();
|
|
100
|
+
const apiKey = payload?.apiKey || ZHIPU_API_KEY;
|
|
101
|
+
|
|
102
|
+
return LobeZhipuAI.fromAPIKey(apiKey);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private static initGoogle(payload: JWTPayload) {
|
|
106
|
+
const { GOOGLE_API_KEY } = getServerConfig();
|
|
107
|
+
const apiKey = payload?.apiKey || GOOGLE_API_KEY;
|
|
108
|
+
|
|
109
|
+
return new LobeGoogleAI(apiKey);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private static initBedrock(payload: JWTPayload) {
|
|
113
|
+
const { AWS_SECRET_ACCESS_KEY, AWS_ACCESS_KEY_ID, AWS_REGION } = getServerConfig();
|
|
114
|
+
|
|
115
|
+
let accessKeyId: string | undefined = AWS_ACCESS_KEY_ID;
|
|
116
|
+
let accessKeySecret: string | undefined = AWS_SECRET_ACCESS_KEY;
|
|
117
|
+
let region = AWS_REGION;
|
|
118
|
+
// if the payload has the api key, use user
|
|
119
|
+
if (payload.apiKey) {
|
|
120
|
+
accessKeyId = payload?.awsAccessKeyId;
|
|
121
|
+
accessKeySecret = payload?.awsSecretAccessKey;
|
|
122
|
+
region = payload?.awsRegion;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return new LobeBedrockAI({ accessKeyId, accessKeySecret, region });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export default AgentRuntime;
|