@lobehub/chat 0.156.2 → 0.157.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +50 -0
- package/package.json +32 -31
- package/src/app/api/chat/[provider]/route.test.ts +2 -2
- package/src/app/api/chat/[provider]/route.ts +1 -1
- package/src/app/api/chat/models/[provider]/route.ts +1 -1
- package/src/app/api/config.test.ts +1 -51
- package/src/app/api/openai/createBizOpenAI/auth.test.ts +52 -0
- package/src/app/api/openai/createBizOpenAI/index.ts +1 -1
- package/src/app/api/plugin/gateway/route.ts +1 -1
- package/src/app/api/text-to-image/[provider]/route.ts +61 -0
- package/src/components/GalleyGrid/index.tsx +2 -2
- package/src/config/modelProviders/anthropic.ts +3 -0
- package/src/config/modelProviders/google.ts +3 -0
- package/src/config/modelProviders/groq.ts +5 -1
- package/src/config/modelProviders/minimax.ts +10 -7
- package/src/config/modelProviders/mistral.ts +1 -0
- package/src/config/modelProviders/moonshot.ts +3 -0
- package/src/config/modelProviders/zhipu.ts +2 -6
- package/src/config/server/provider.ts +1 -1
- package/src/database/client/core/db.ts +32 -0
- package/src/database/client/core/schemas.ts +9 -0
- package/src/database/client/models/__tests__/message.test.ts +2 -2
- package/src/database/client/schemas/message.ts +10 -1
- package/src/features/AgentSetting/store/action.ts +15 -6
- package/src/features/Conversation/Actions/Assistant.tsx +3 -2
- package/src/features/Conversation/Actions/Tool.tsx +28 -0
- package/src/features/Conversation/Actions/index.ts +2 -2
- package/src/features/Conversation/Messages/Assistant/ToolCalls/index.tsx +73 -0
- package/src/features/Conversation/Messages/Assistant/ToolCalls/style.ts +25 -0
- package/src/features/Conversation/Messages/Assistant/index.tsx +51 -0
- package/src/features/Conversation/Messages/Default.tsx +4 -1
- package/src/features/Conversation/{Plugins → Messages/Tool}/Inspector/index.tsx +35 -36
- package/src/features/Conversation/Messages/Tool/index.tsx +44 -0
- package/src/features/Conversation/Messages/index.ts +3 -2
- package/src/features/Conversation/Plugins/Render/StandaloneType/Iframe.tsx +1 -1
- package/src/features/Conversation/Plugins/Render/index.tsx +11 -2
- package/src/features/Conversation/components/SkeletonList.tsx +2 -2
- package/src/features/Conversation/index.tsx +2 -3
- package/src/hooks/useTokenCount.test.ts +38 -0
- package/src/hooks/useTokenCount.ts +1 -2
- package/src/libs/agent-runtime/AgentRuntime.ts +9 -1
- package/src/libs/agent-runtime/BaseAI.ts +5 -9
- package/src/libs/agent-runtime/anthropic/index.test.ts +195 -0
- package/src/libs/agent-runtime/anthropic/index.ts +71 -15
- package/src/libs/agent-runtime/azureOpenai/index.ts +6 -5
- package/src/libs/agent-runtime/bedrock/index.ts +24 -18
- package/src/libs/agent-runtime/google/index.test.ts +154 -0
- package/src/libs/agent-runtime/google/index.ts +91 -10
- package/src/libs/agent-runtime/groq/index.test.ts +41 -72
- package/src/libs/agent-runtime/groq/index.ts +7 -0
- package/src/libs/agent-runtime/minimax/index.test.ts +2 -2
- package/src/libs/agent-runtime/minimax/index.ts +14 -37
- package/src/libs/agent-runtime/mistral/index.test.ts +0 -53
- package/src/libs/agent-runtime/mistral/index.ts +1 -0
- package/src/libs/agent-runtime/moonshot/index.test.ts +1 -71
- package/src/libs/agent-runtime/ollama/index.test.ts +197 -0
- package/src/libs/agent-runtime/ollama/index.ts +3 -3
- package/src/libs/agent-runtime/openai/index.test.ts +0 -53
- package/src/libs/agent-runtime/openrouter/index.test.ts +1 -53
- package/src/libs/agent-runtime/perplexity/index.test.ts +0 -71
- package/src/libs/agent-runtime/perplexity/index.ts +2 -3
- package/src/libs/agent-runtime/togetherai/__snapshots__/index.test.ts.snap +886 -0
- package/src/libs/agent-runtime/togetherai/fixtures/models.json +8111 -0
- package/src/libs/agent-runtime/togetherai/index.test.ts +16 -54
- package/src/libs/agent-runtime/types/chat.ts +19 -3
- package/src/libs/agent-runtime/types/index.ts +1 -0
- package/src/libs/agent-runtime/types/textToImage.ts +34 -0
- package/src/libs/agent-runtime/utils/anthropicHelpers.test.ts +120 -1
- package/src/libs/agent-runtime/utils/anthropicHelpers.ts +67 -4
- package/src/libs/agent-runtime/utils/createError.ts +1 -0
- package/src/libs/agent-runtime/utils/debugStream.test.ts +70 -0
- package/src/libs/agent-runtime/utils/debugStream.ts +39 -9
- package/src/libs/agent-runtime/utils/openaiCompatibleFactory/index.test.ts +521 -0
- package/src/libs/agent-runtime/utils/openaiCompatibleFactory/index.ts +127 -5
- package/src/libs/agent-runtime/utils/response.ts +12 -0
- package/src/libs/agent-runtime/utils/streams/anthropic.test.ts +197 -0
- package/src/libs/agent-runtime/utils/streams/anthropic.ts +91 -0
- package/src/libs/agent-runtime/utils/streams/bedrock/claude.ts +21 -0
- package/src/libs/agent-runtime/utils/streams/bedrock/common.ts +32 -0
- package/src/libs/agent-runtime/utils/streams/bedrock/index.ts +3 -0
- package/src/libs/agent-runtime/utils/streams/bedrock/llama.test.ts +196 -0
- package/src/libs/agent-runtime/utils/streams/bedrock/llama.ts +51 -0
- package/src/libs/agent-runtime/utils/streams/google-ai.test.ts +97 -0
- package/src/libs/agent-runtime/utils/streams/google-ai.ts +68 -0
- package/src/libs/agent-runtime/utils/streams/index.ts +7 -0
- package/src/libs/agent-runtime/utils/streams/minimax.ts +39 -0
- package/src/libs/agent-runtime/utils/streams/ollama.test.ts +77 -0
- package/src/libs/agent-runtime/utils/streams/ollama.ts +38 -0
- package/src/libs/agent-runtime/utils/streams/openai.test.ts +263 -0
- package/src/libs/agent-runtime/utils/streams/openai.ts +79 -0
- package/src/libs/agent-runtime/utils/streams/protocol.ts +100 -0
- package/src/libs/agent-runtime/zeroone/index.test.ts +1 -53
- package/src/libs/agent-runtime/zhipu/index.test.ts +1 -1
- package/src/libs/agent-runtime/zhipu/index.ts +3 -2
- package/src/locales/default/plugin.ts +3 -4
- package/src/locales/default/tool.ts +1 -0
- package/src/migrations/FromV4ToV5/fixtures/from-v1-to-v5-output.json +245 -0
- package/src/migrations/FromV4ToV5/fixtures/function-input-v4.json +96 -0
- package/src/migrations/FromV4ToV5/fixtures/function-output-v5.json +120 -0
- package/src/migrations/FromV4ToV5/index.ts +58 -0
- package/src/migrations/FromV4ToV5/migrations.test.ts +49 -0
- package/src/migrations/FromV4ToV5/types/v4.ts +21 -0
- package/src/migrations/FromV4ToV5/types/v5.ts +27 -0
- package/src/migrations/index.ts +8 -1
- package/src/services/__tests__/chat.test.ts +10 -20
- package/src/services/_url.ts +1 -1
- package/src/services/chat.ts +78 -65
- package/src/services/{imageGeneration.ts → textToImage.ts} +11 -2
- package/src/store/chat/initialState.ts +1 -1
- package/src/store/chat/selectors.ts +1 -1
- package/src/store/chat/slices/{tool → builtinTool}/action.test.ts +1 -1
- package/src/store/chat/slices/{tool → builtinTool}/action.ts +16 -4
- package/src/store/chat/slices/enchance/action.ts +25 -21
- package/src/store/chat/slices/message/action.test.ts +36 -86
- package/src/store/chat/slices/message/action.ts +98 -169
- package/src/store/chat/slices/message/initialState.ts +5 -0
- package/src/store/chat/slices/message/reducer.ts +18 -1
- package/src/store/chat/slices/message/selectors.test.ts +38 -68
- package/src/store/chat/slices/message/selectors.ts +9 -22
- package/src/store/chat/slices/plugin/action.test.ts +148 -204
- package/src/store/chat/slices/plugin/action.ts +163 -134
- package/src/store/chat/slices/share/action.test.ts +3 -3
- package/src/store/chat/slices/share/action.ts +1 -1
- package/src/store/chat/slices/topic/action.ts +7 -2
- package/src/store/chat/store.ts +2 -2
- package/src/store/tool/selectors/tool.ts +6 -24
- package/src/store/tool/slices/builtin/action.test.ts +90 -0
- package/src/store/tool/slices/store/action.test.ts +6 -2
- package/src/store/tool/slices/store/action.ts +3 -1
- package/src/tools/dalle/Render/Item/Error.tsx +50 -0
- package/src/tools/dalle/Render/Item/Image.tsx +44 -0
- package/src/tools/dalle/Render/{Item.tsx → Item/index.tsx} +20 -29
- package/src/types/llm.ts +1 -1
- package/src/types/message/index.ts +9 -4
- package/src/types/message/tools.ts +57 -0
- package/src/types/openai/chat.ts +6 -0
- package/src/utils/fetch.test.ts +450 -1
- package/src/utils/fetch.ts +338 -39
- package/src/utils/toolCall.ts +21 -0
- package/src/app/api/openai/images/createImageGeneration.ts +0 -26
- package/src/app/api/openai/images/route.ts +0 -16
- package/src/features/Conversation/Actions/Function.tsx +0 -17
- package/src/features/Conversation/Messages/Assistant.tsx +0 -26
- package/src/features/Conversation/Messages/Function.tsx +0 -35
- package/src/libs/agent-runtime/ollama/stream.ts +0 -31
- /package/src/app/api/{chat → middleware}/auth/index.test.ts +0 -0
- /package/src/app/api/{chat → middleware}/auth/index.ts +0 -0
- /package/src/app/api/{chat → middleware}/auth/utils.ts +0 -0
- /package/src/app/api/{auth.ts → openai/createBizOpenAI/auth.ts} +0 -0
- /package/src/features/Conversation/{Plugins → Messages/Tool}/Inspector/PluginResultJSON.tsx +0 -0
- /package/src/features/Conversation/{Plugins → Messages/Tool}/Inspector/Settings.tsx +0 -0
- /package/src/features/Conversation/{Plugins → Messages/Tool}/Inspector/style.ts +0 -0
- /package/src/store/chat/slices/{tool → builtinTool}/initialState.ts +0 -0
- /package/src/store/chat/slices/{tool → builtinTool}/selectors.ts +0 -0
- /package/src/tools/dalle/Render/{EditMode.tsx → Item/EditMode.tsx} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,56 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
### [Version 0.157.1](https://github.com/lobehub/lobe-chat/compare/v0.157.0...v0.157.1)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2024-05-12**</sup>
|
|
8
|
+
|
|
9
|
+
#### 🐛 Bug Fixes
|
|
10
|
+
|
|
11
|
+
- **misc**: Fix dalle error.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### What's fixed
|
|
19
|
+
|
|
20
|
+
- **misc**: Fix dalle error ([7c493de](https://github.com/lobehub/lobe-chat/commit/7c493de))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
## [Version 0.157.0](https://github.com/lobehub/lobe-chat/compare/v0.156.2...v0.157.0)
|
|
31
|
+
|
|
32
|
+
<sup>Released on **2024-05-11**</sup>
|
|
33
|
+
|
|
34
|
+
#### ✨ Features
|
|
35
|
+
|
|
36
|
+
- **misc**: upgrade to the new `tool calls` mode.
|
|
37
|
+
|
|
38
|
+
<br/>
|
|
39
|
+
|
|
40
|
+
<details>
|
|
41
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
42
|
+
|
|
43
|
+
#### What's improved
|
|
44
|
+
|
|
45
|
+
- **misc**: upgrade to the new `tool calls` mode, closes [#2414](https://github.com/lobehub/lobe-chat/issues/2414) ([7404f3b](https://github.com/lobehub/lobe-chat/commit/7404f3b))
|
|
46
|
+
|
|
47
|
+
</details>
|
|
48
|
+
|
|
49
|
+
<div align="right">
|
|
50
|
+
|
|
51
|
+
[](#readme-top)
|
|
52
|
+
|
|
53
|
+
</div>
|
|
54
|
+
|
|
5
55
|
### [Version 0.156.2](https://github.com/lobehub/lobe-chat/compare/v0.156.1...v0.156.2)
|
|
6
56
|
|
|
7
57
|
<sup>Released on **2024-05-10**</sup>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/chat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.157.1",
|
|
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",
|
|
@@ -81,24 +81,25 @@
|
|
|
81
81
|
]
|
|
82
82
|
},
|
|
83
83
|
"dependencies": {
|
|
84
|
-
"@ant-design/icons": "^5.3.
|
|
85
|
-
"@anthropic-ai/sdk": "^0.
|
|
84
|
+
"@ant-design/icons": "^5.3.7",
|
|
85
|
+
"@anthropic-ai/sdk": "^0.20.9",
|
|
86
86
|
"@auth/core": "0.28.0",
|
|
87
|
-
"@aws-sdk/client-bedrock-runtime": "^3.
|
|
88
|
-
"@azure/openai": "
|
|
87
|
+
"@aws-sdk/client-bedrock-runtime": "^3.574.0",
|
|
88
|
+
"@azure/openai": "1.0.0-beta.12",
|
|
89
89
|
"@cfworker/json-schema": "^1.12.8",
|
|
90
90
|
"@clerk/localizations": "2.0.0",
|
|
91
|
-
"@clerk/nextjs": "^5.0.
|
|
92
|
-
"@clerk/themes": "^2.
|
|
91
|
+
"@clerk/nextjs": "^5.0.8",
|
|
92
|
+
"@clerk/themes": "^2.1.3",
|
|
93
93
|
"@google/generative-ai": "^0.10.0",
|
|
94
|
-
"@icons-pack/react-simple-icons": "^9.
|
|
94
|
+
"@icons-pack/react-simple-icons": "^9.5.0",
|
|
95
95
|
"@lobehub/chat-plugin-sdk": "latest",
|
|
96
96
|
"@lobehub/chat-plugins-gateway": "latest",
|
|
97
97
|
"@lobehub/icons": "latest",
|
|
98
98
|
"@lobehub/tts": "latest",
|
|
99
|
-
"@lobehub/ui": "^1.138.
|
|
99
|
+
"@lobehub/ui": "^1.138.23",
|
|
100
|
+
"@microsoft/fetch-event-source": "^2.0.1",
|
|
100
101
|
"@next/third-parties": "^14.2.3",
|
|
101
|
-
"@sentry/nextjs": "^7.
|
|
102
|
+
"@sentry/nextjs": "^7.114.0",
|
|
102
103
|
"@t3-oss/env-nextjs": "^0.10.1",
|
|
103
104
|
"@trpc/client": "next",
|
|
104
105
|
"@trpc/next": "next",
|
|
@@ -117,15 +118,15 @@
|
|
|
117
118
|
"diff": "^5.2.0",
|
|
118
119
|
"fast-deep-equal": "^3.1.3",
|
|
119
120
|
"gpt-tokenizer": "^2.1.2",
|
|
120
|
-
"i18next": "^23.11.
|
|
121
|
+
"i18next": "^23.11.4",
|
|
121
122
|
"i18next-browser-languagedetector": "^7.2.1",
|
|
122
123
|
"i18next-resources-to-backend": "^1.2.1",
|
|
123
124
|
"idb-keyval": "^6.2.1",
|
|
124
125
|
"immer": "^10.1.1",
|
|
125
126
|
"ip": "^2.0.1",
|
|
126
|
-
"jose": "^5.
|
|
127
|
-
"langfuse": "^3.
|
|
128
|
-
"langfuse-core": "^3.
|
|
127
|
+
"jose": "^5.3.0",
|
|
128
|
+
"langfuse": "^3.10.0",
|
|
129
|
+
"langfuse-core": "^3.10.0",
|
|
129
130
|
"lodash-es": "^4.17.21",
|
|
130
131
|
"lucide-react": "latest",
|
|
131
132
|
"modern-screenshot": "^4.4.39",
|
|
@@ -134,12 +135,12 @@
|
|
|
134
135
|
"next-auth": "5.0.0-beta.15",
|
|
135
136
|
"next-sitemap": "^4.2.3",
|
|
136
137
|
"numeral": "^2.0.6",
|
|
137
|
-
"nuqs": "^1.17.
|
|
138
|
-
"ollama": "^0.5.
|
|
139
|
-
"openai": "^4.
|
|
138
|
+
"nuqs": "^1.17.2",
|
|
139
|
+
"ollama": "^0.5.1",
|
|
140
|
+
"openai": "^4.45.0",
|
|
140
141
|
"pino": "^9.0.0",
|
|
141
142
|
"polished": "^4.3.1",
|
|
142
|
-
"posthog-js": "^1.
|
|
143
|
+
"posthog-js": "^1.131.4",
|
|
143
144
|
"query-string": "^9.0.0",
|
|
144
145
|
"random-words": "^2.0.1",
|
|
145
146
|
"react": "^18.3.1",
|
|
@@ -154,7 +155,7 @@
|
|
|
154
155
|
"remark-gfm": "^3.0.1",
|
|
155
156
|
"remark-html": "^15.0.2",
|
|
156
157
|
"rtl-detect": "^1.1.2",
|
|
157
|
-
"semver": "^7.6.
|
|
158
|
+
"semver": "^7.6.2",
|
|
158
159
|
"sharp": "^0.33.3",
|
|
159
160
|
"superjson": "^2.2.1",
|
|
160
161
|
"swr": "^2.2.5",
|
|
@@ -169,13 +170,13 @@
|
|
|
169
170
|
"y-webrtc": "^10.3.0",
|
|
170
171
|
"yaml": "^2.4.2",
|
|
171
172
|
"yjs": "^13.6.15",
|
|
172
|
-
"zod": "^3.23.
|
|
173
|
+
"zod": "^3.23.8",
|
|
173
174
|
"zustand": "^4.5.2",
|
|
174
175
|
"zustand-utils": "^1.3.2"
|
|
175
176
|
},
|
|
176
177
|
"devDependencies": {
|
|
177
178
|
"@commitlint/cli": "^19.3.0",
|
|
178
|
-
"@ducanh2912/next-pwa": "^10.2.
|
|
179
|
+
"@ducanh2912/next-pwa": "^10.2.7",
|
|
179
180
|
"@edge-runtime/vm": "^3.2.0",
|
|
180
181
|
"@lobehub/i18n-cli": "^1.18.1",
|
|
181
182
|
"@lobehub/lint": "^1.23.4",
|
|
@@ -184,24 +185,24 @@
|
|
|
184
185
|
"@next/eslint-plugin-next": "^14.2.3",
|
|
185
186
|
"@peculiar/webcrypto": "^1.4.6",
|
|
186
187
|
"@testing-library/jest-dom": "^6.4.5",
|
|
187
|
-
"@testing-library/react": "^15.0.
|
|
188
|
+
"@testing-library/react": "^15.0.7",
|
|
188
189
|
"@types/chroma-js": "^2.4.4",
|
|
189
190
|
"@types/debug": "^4.1.12",
|
|
190
|
-
"@types/diff": "^5.2.
|
|
191
|
+
"@types/diff": "^5.2.1",
|
|
191
192
|
"@types/ip": "^1.1.3",
|
|
192
193
|
"@types/json-schema": "^7.0.15",
|
|
193
|
-
"@types/lodash": "^4.17.
|
|
194
|
+
"@types/lodash": "^4.17.1",
|
|
194
195
|
"@types/lodash-es": "^4.17.12",
|
|
195
|
-
"@types/node": "^20.12.
|
|
196
|
+
"@types/node": "^20.12.11",
|
|
196
197
|
"@types/numeral": "^2.0.5",
|
|
197
|
-
"@types/react": "^18.3.
|
|
198
|
+
"@types/react": "^18.3.2",
|
|
198
199
|
"@types/react-dom": "^18.3.0",
|
|
199
200
|
"@types/rtl-detect": "^1.0.3",
|
|
200
201
|
"@types/semver": "^7.5.8",
|
|
201
202
|
"@types/systemjs": "^6.13.5",
|
|
202
203
|
"@types/ua-parser-js": "^0.7.39",
|
|
203
204
|
"@types/uuid": "^9.0.8",
|
|
204
|
-
"@umijs/lint": "^4.
|
|
205
|
+
"@umijs/lint": "^4.2.2",
|
|
205
206
|
"@vitest/coverage-v8": "~1.2.2",
|
|
206
207
|
"ajv-keywords": "^5.1.0",
|
|
207
208
|
"commitlint": "^19.3.0",
|
|
@@ -210,9 +211,9 @@
|
|
|
210
211
|
"eslint": "^8.57.0",
|
|
211
212
|
"eslint-plugin-mdx": "^2.3.4",
|
|
212
213
|
"fake-indexeddb": "^5.0.2",
|
|
213
|
-
"glob": "^10.3.
|
|
214
|
+
"glob": "^10.3.15",
|
|
214
215
|
"gray-matter": "^4.0.3",
|
|
215
|
-
"happy-dom": "^14.
|
|
216
|
+
"happy-dom": "^14.10.1",
|
|
216
217
|
"husky": "^9.0.11",
|
|
217
218
|
"just-diff": "^6.0.2",
|
|
218
219
|
"lint-staged": "^15.2.2",
|
|
@@ -226,11 +227,11 @@
|
|
|
226
227
|
"remark-parse": "^10.0.2",
|
|
227
228
|
"semantic-release": "^21.1.2",
|
|
228
229
|
"stylelint": "^15.11.0",
|
|
229
|
-
"tsx": "^4.
|
|
230
|
+
"tsx": "^4.10.0",
|
|
230
231
|
"typescript": "^5.4.5",
|
|
231
232
|
"unified": "^11.0.4",
|
|
232
233
|
"unist-util-visit": "^5.0.0",
|
|
233
|
-
"vite": "^5.2.
|
|
234
|
+
"vite": "^5.2.11",
|
|
234
235
|
"vitest": "~1.2.2",
|
|
235
236
|
"vitest-canvas-mock": "^0.3.3"
|
|
236
237
|
},
|
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
import { getAuth } from '@clerk/nextjs/server';
|
|
3
3
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
4
|
|
|
5
|
+
import { checkAuthMethod, getJWTPayload } from '@/app/api/middleware/auth/utils';
|
|
5
6
|
import { LOBE_CHAT_AUTH_HEADER, OAUTH_AUTHORIZED } from '@/const/auth';
|
|
6
7
|
import { AgentRuntime, LobeRuntimeAI } from '@/libs/agent-runtime';
|
|
7
8
|
import { ChatErrorType } from '@/types/fetch';
|
|
8
9
|
|
|
9
|
-
import { checkAuthMethod, getJWTPayload } from '../auth/utils';
|
|
10
10
|
import { POST } from './route';
|
|
11
11
|
|
|
12
12
|
vi.mock('@clerk/nextjs/server', () => ({
|
|
13
13
|
getAuth: vi.fn(),
|
|
14
14
|
}));
|
|
15
15
|
|
|
16
|
-
vi.mock('
|
|
16
|
+
vi.mock('../../middleware/auth/utils', () => ({
|
|
17
17
|
getJWTPayload: vi.fn(),
|
|
18
18
|
checkAuthMethod: vi.fn(),
|
|
19
19
|
}));
|
|
@@ -5,8 +5,8 @@ import { ChatErrorType } from '@/types/fetch';
|
|
|
5
5
|
import { ChatStreamPayload } from '@/types/openai/chat';
|
|
6
6
|
import { getTracePayload } from '@/utils/trace';
|
|
7
7
|
|
|
8
|
+
import { checkAuth } from '../../middleware/auth';
|
|
8
9
|
import { createTraceOptions, initAgentRuntimeWithUserPayload } from '../agentRuntime';
|
|
9
|
-
import { checkAuth } from '../auth';
|
|
10
10
|
|
|
11
11
|
export const runtime = 'edge';
|
|
12
12
|
|
|
@@ -5,8 +5,8 @@ import { createErrorResponse } from '@/app/api/errorResponse';
|
|
|
5
5
|
import { ChatCompletionErrorPayload, ModelProvider } from '@/libs/agent-runtime';
|
|
6
6
|
import { ChatErrorType } from '@/types/fetch';
|
|
7
7
|
|
|
8
|
+
import { checkAuth } from '../../../middleware/auth';
|
|
8
9
|
import { initAgentRuntimeWithUserPayload } from '../../agentRuntime';
|
|
9
|
-
import { checkAuth } from '../../auth';
|
|
10
10
|
|
|
11
11
|
export const runtime = 'edge';
|
|
12
12
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it, vi } from 'vitest';
|
|
2
2
|
|
|
3
|
-
import { checkAuth } from './auth';
|
|
4
3
|
import { getPreferredRegion } from './config';
|
|
4
|
+
import { checkAuth } from './openai/createBizOpenAI/auth';
|
|
5
5
|
|
|
6
6
|
// Stub the global process object to safely mock environment variables
|
|
7
7
|
vi.stubGlobal('process', {
|
|
@@ -41,53 +41,3 @@ describe('getPreferredRegion', () => {
|
|
|
41
41
|
expect(preferredRegion).toStrictEqual(['ida1', 'sfo1']);
|
|
42
42
|
});
|
|
43
43
|
});
|
|
44
|
-
|
|
45
|
-
describe('ACCESS_CODE', () => {
|
|
46
|
-
let auth = false;
|
|
47
|
-
|
|
48
|
-
beforeEach(() => {
|
|
49
|
-
auth = false;
|
|
50
|
-
process.env.ACCESS_CODE = undefined;
|
|
51
|
-
// Reset environment variables before each test case
|
|
52
|
-
vi.restoreAllMocks();
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('set multiple access codes', () => {
|
|
56
|
-
process.env.ACCESS_CODE = ',code1,code2,code3';
|
|
57
|
-
({ auth } = checkAuth({ accessCode: 'code1' }));
|
|
58
|
-
expect(auth).toBe(true);
|
|
59
|
-
({ auth } = checkAuth({ accessCode: 'code2' }));
|
|
60
|
-
expect(auth).toBe(true);
|
|
61
|
-
({ auth } = checkAuth({ accessCode: 'code1,code2' }));
|
|
62
|
-
expect(auth).toBe(false);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('set individual access code', () => {
|
|
66
|
-
process.env.ACCESS_CODE = 'code1';
|
|
67
|
-
({ auth } = checkAuth({ accessCode: 'code1' }));
|
|
68
|
-
expect(auth).toBe(true);
|
|
69
|
-
({ auth } = checkAuth({ accessCode: 'code2' }));
|
|
70
|
-
expect(auth).toBe(false);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('no access code', () => {
|
|
74
|
-
({ auth } = checkAuth({ accessCode: 'code1' }));
|
|
75
|
-
expect(auth).toBe(true);
|
|
76
|
-
({ auth } = checkAuth({}));
|
|
77
|
-
expect(auth).toBe(true);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('empty access code', () => {
|
|
81
|
-
process.env.ACCESS_CODE = '';
|
|
82
|
-
({ auth } = checkAuth({ accessCode: 'code1' }));
|
|
83
|
-
expect(auth).toBe(true);
|
|
84
|
-
({ auth } = checkAuth({}));
|
|
85
|
-
expect(auth).toBe(true);
|
|
86
|
-
|
|
87
|
-
process.env.ACCESS_CODE = ',,';
|
|
88
|
-
({ auth } = checkAuth({ accessCode: 'code1' }));
|
|
89
|
-
expect(auth).toBe(true);
|
|
90
|
-
({ auth } = checkAuth({}));
|
|
91
|
-
expect(auth).toBe(true);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { checkAuth } from './auth';
|
|
2
|
+
|
|
3
|
+
describe('ACCESS_CODE', () => {
|
|
4
|
+
let auth = false;
|
|
5
|
+
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
auth = false;
|
|
8
|
+
process.env.ACCESS_CODE = undefined;
|
|
9
|
+
// Reset environment variables before each test case
|
|
10
|
+
vi.restoreAllMocks();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('set multiple access codes', () => {
|
|
14
|
+
process.env.ACCESS_CODE = ',code1,code2,code3';
|
|
15
|
+
({ auth } = checkAuth({ accessCode: 'code1' }));
|
|
16
|
+
expect(auth).toBe(true);
|
|
17
|
+
({ auth } = checkAuth({ accessCode: 'code2' }));
|
|
18
|
+
expect(auth).toBe(true);
|
|
19
|
+
({ auth } = checkAuth({ accessCode: 'code1,code2' }));
|
|
20
|
+
expect(auth).toBe(false);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('set individual access code', () => {
|
|
24
|
+
process.env.ACCESS_CODE = 'code1';
|
|
25
|
+
({ auth } = checkAuth({ accessCode: 'code1' }));
|
|
26
|
+
expect(auth).toBe(true);
|
|
27
|
+
({ auth } = checkAuth({ accessCode: 'code2' }));
|
|
28
|
+
expect(auth).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('no access code', () => {
|
|
32
|
+
delete process.env.ACCESS_CODE;
|
|
33
|
+
({ auth } = checkAuth({ accessCode: 'code1' }));
|
|
34
|
+
expect(auth).toBe(true);
|
|
35
|
+
({ auth } = checkAuth({}));
|
|
36
|
+
expect(auth).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('empty access code', () => {
|
|
40
|
+
process.env.ACCESS_CODE = '';
|
|
41
|
+
({ auth } = checkAuth({ accessCode: 'code1' }));
|
|
42
|
+
expect(auth).toBe(true);
|
|
43
|
+
({ auth } = checkAuth({}));
|
|
44
|
+
expect(auth).toBe(true);
|
|
45
|
+
|
|
46
|
+
process.env.ACCESS_CODE = ',,';
|
|
47
|
+
({ auth } = checkAuth({ accessCode: 'code1' }));
|
|
48
|
+
expect(auth).toBe(true);
|
|
49
|
+
({ auth } = checkAuth({}));
|
|
50
|
+
expect(auth).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import OpenAI from 'openai';
|
|
2
2
|
|
|
3
|
-
import { checkAuth } from '@/app/api/auth';
|
|
4
3
|
import { getOpenAIAuthFromRequest } from '@/const/fetch';
|
|
5
4
|
import { ChatErrorType, ErrorType } from '@/types/fetch';
|
|
6
5
|
|
|
7
6
|
import { createErrorResponse } from '../../errorResponse';
|
|
7
|
+
import { checkAuth } from './auth';
|
|
8
8
|
import { createOpenai } from './createOpenai';
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { PluginRequestPayload } from '@lobehub/chat-plugin-sdk';
|
|
2
2
|
import { createGatewayOnEdgeRuntime } from '@lobehub/chat-plugins-gateway';
|
|
3
3
|
|
|
4
|
-
import { getJWTPayload } from '@/app/api/chat/auth/utils';
|
|
5
4
|
import { createErrorResponse } from '@/app/api/errorResponse';
|
|
5
|
+
import { getJWTPayload } from '@/app/api/middleware/auth/utils';
|
|
6
6
|
import { getServerConfig } from '@/config/server';
|
|
7
7
|
import { LOBE_CHAT_AUTH_HEADER, OAUTH_AUTHORIZED, enableNextAuth } from '@/const/auth';
|
|
8
8
|
import { LOBE_CHAT_TRACE_ID, TraceNameMap } from '@/const/trace';
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server';
|
|
2
|
+
|
|
3
|
+
import { getPreferredRegion } from '@/app/api/config';
|
|
4
|
+
import { createErrorResponse } from '@/app/api/errorResponse';
|
|
5
|
+
import { ChatCompletionErrorPayload } from '@/libs/agent-runtime';
|
|
6
|
+
import { TextToImagePayload } from '@/libs/agent-runtime/types';
|
|
7
|
+
import { ChatErrorType } from '@/types/fetch';
|
|
8
|
+
|
|
9
|
+
import { initAgentRuntimeWithUserPayload } from '../../chat/agentRuntime';
|
|
10
|
+
import { checkAuth } from '../../middleware/auth';
|
|
11
|
+
|
|
12
|
+
export const runtime = 'edge';
|
|
13
|
+
|
|
14
|
+
export const preferredRegion = getPreferredRegion();
|
|
15
|
+
|
|
16
|
+
// return NextResponse.json(
|
|
17
|
+
// {
|
|
18
|
+
// body: {
|
|
19
|
+
// endpoint: 'https://ai****ix.com/v1',
|
|
20
|
+
// error: {
|
|
21
|
+
// code: 'content_policy_violation',
|
|
22
|
+
// message:
|
|
23
|
+
// 'Your request was rejected as a result of our safety system. Image descriptions generated from your prompt may contain text that is not allowed by our safety system. If you believe this was done in error, your request may succeed if retried, or by adjusting your prompt.',
|
|
24
|
+
// param: null,
|
|
25
|
+
// type: 'invalid_request_error',
|
|
26
|
+
// },
|
|
27
|
+
// provider: 'openai',
|
|
28
|
+
// },
|
|
29
|
+
// errorType: 'OpenAIBizError',
|
|
30
|
+
// },
|
|
31
|
+
// { status: 400 },
|
|
32
|
+
// );
|
|
33
|
+
|
|
34
|
+
export const POST = checkAuth(async (req: Request, { params, jwtPayload }) => {
|
|
35
|
+
const { provider } = params;
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
// ============ 1. init chat model ============ //
|
|
39
|
+
const agentRuntime = await initAgentRuntimeWithUserPayload(provider, jwtPayload);
|
|
40
|
+
|
|
41
|
+
// ============ 2. create chat completion ============ //
|
|
42
|
+
|
|
43
|
+
const data = (await req.json()) as TextToImagePayload;
|
|
44
|
+
|
|
45
|
+
const images = await agentRuntime.textToImage(data);
|
|
46
|
+
|
|
47
|
+
return NextResponse.json(images);
|
|
48
|
+
} catch (e) {
|
|
49
|
+
const {
|
|
50
|
+
errorType = ChatErrorType.InternalServerError,
|
|
51
|
+
error: errorContent,
|
|
52
|
+
...res
|
|
53
|
+
} = e as ChatCompletionErrorPayload;
|
|
54
|
+
|
|
55
|
+
const error = errorContent || e;
|
|
56
|
+
// track the error at server side
|
|
57
|
+
console.error(`Route: [${provider}] ${errorType}:`, error);
|
|
58
|
+
|
|
59
|
+
return createErrorResponse(errorType, { error, ...res, provider });
|
|
60
|
+
}
|
|
61
|
+
});
|
|
@@ -41,13 +41,13 @@ const GalleyGrid = memo<GalleyGridProps>(({ items, renderItem: Render }) => {
|
|
|
41
41
|
<Flexbox gap={gap}>
|
|
42
42
|
<Grid col={firstRow.length} gap={gap} max={max}>
|
|
43
43
|
{firstRow.map((i, index) => (
|
|
44
|
-
<Render {...i} key={index} />
|
|
44
|
+
<Render {...i} index={index} key={index} />
|
|
45
45
|
))}
|
|
46
46
|
</Grid>
|
|
47
47
|
{lastRow.length > 0 && (
|
|
48
48
|
<Grid col={lastRow.length > 2 ? 3 : lastRow.length} gap={gap} max={max}>
|
|
49
49
|
{lastRow.map((i, index) => (
|
|
50
|
-
<Render {...i} key={index} />
|
|
50
|
+
<Render {...i} index={index} key={index} />
|
|
51
51
|
))}
|
|
52
52
|
</Grid>
|
|
53
53
|
)}
|
|
@@ -8,6 +8,7 @@ const Anthropic: ModelProviderCard = {
|
|
|
8
8
|
'Ideal balance of intelligence and speed for enterprise workloads. Maximum utility at a lower price, dependable, balanced for scaled deployments',
|
|
9
9
|
displayName: 'Claude 3 Sonnet',
|
|
10
10
|
enabled: true,
|
|
11
|
+
functionCall: true,
|
|
11
12
|
id: 'claude-3-sonnet-20240229',
|
|
12
13
|
maxOutput: 4096,
|
|
13
14
|
tokens: 200_000,
|
|
@@ -18,6 +19,7 @@ const Anthropic: ModelProviderCard = {
|
|
|
18
19
|
'Most powerful model for highly complex tasks. Top-level performance, intelligence, fluency, and understanding',
|
|
19
20
|
displayName: 'Claude 3 Opus',
|
|
20
21
|
enabled: true,
|
|
22
|
+
functionCall: true,
|
|
21
23
|
id: 'claude-3-opus-20240229',
|
|
22
24
|
maxOutput: 4096,
|
|
23
25
|
tokens: 200_000,
|
|
@@ -28,6 +30,7 @@ const Anthropic: ModelProviderCard = {
|
|
|
28
30
|
'Fastest and most compact model for near-instant responsiveness. Quick and accurate targeted performance',
|
|
29
31
|
displayName: 'Claude 3 Haiku',
|
|
30
32
|
enabled: true,
|
|
33
|
+
functionCall: true,
|
|
31
34
|
id: 'claude-3-haiku-20240307',
|
|
32
35
|
maxOutput: 4096,
|
|
33
36
|
tokens: 200_000,
|
|
@@ -22,6 +22,7 @@ const Google: ModelProviderCard = {
|
|
|
22
22
|
description: 'The best model for scaling across a wide range of tasks',
|
|
23
23
|
displayName: 'Gemini 1.0 Pro',
|
|
24
24
|
enabled: true,
|
|
25
|
+
functionCall: true,
|
|
25
26
|
id: 'gemini-pro',
|
|
26
27
|
maxOutput: 2048,
|
|
27
28
|
tokens: 30_720 + 2048,
|
|
@@ -47,6 +48,7 @@ const Google: ModelProviderCard = {
|
|
|
47
48
|
description:
|
|
48
49
|
'The best model for scaling across a wide range of tasks. This is a stable model that supports tuning.',
|
|
49
50
|
displayName: 'Gemini 1.0 Pro 001 (Tuning)',
|
|
51
|
+
functionCall: true,
|
|
50
52
|
id: 'gemini-1.0-pro-001',
|
|
51
53
|
maxOutput: 2048,
|
|
52
54
|
tokens: 30_720 + 2048,
|
|
@@ -71,6 +73,7 @@ const Google: ModelProviderCard = {
|
|
|
71
73
|
description: 'Mid-size multimodal model that supports up to 1 million tokens',
|
|
72
74
|
displayName: 'Gemini 1.5 Pro',
|
|
73
75
|
enabled: true,
|
|
76
|
+
functionCall: true,
|
|
74
77
|
id: 'gemini-1.5-pro-latest',
|
|
75
78
|
maxOutput: 8192,
|
|
76
79
|
tokens: 1_048_576 + 8192,
|
|
@@ -6,24 +6,28 @@ const Groq: ModelProviderCard = {
|
|
|
6
6
|
{
|
|
7
7
|
displayName: 'LLaMA3-3-70B',
|
|
8
8
|
enabled: true,
|
|
9
|
+
functionCall: true,
|
|
9
10
|
id: 'llama3-70b-8192',
|
|
10
11
|
tokens: 8192,
|
|
11
12
|
},
|
|
12
13
|
{
|
|
13
|
-
displayName: 'Mixtral-8x7b
|
|
14
|
+
displayName: 'Mixtral-8x7b',
|
|
14
15
|
enabled: true,
|
|
16
|
+
functionCall: true,
|
|
15
17
|
id: 'mixtral-8x7b-32768',
|
|
16
18
|
tokens: 32_768,
|
|
17
19
|
},
|
|
18
20
|
{
|
|
19
21
|
displayName: 'Gemma-7b-it',
|
|
20
22
|
enabled: true,
|
|
23
|
+
functionCall: true,
|
|
21
24
|
id: 'gemma-7b-it',
|
|
22
25
|
tokens: 8192,
|
|
23
26
|
},
|
|
24
27
|
{
|
|
25
28
|
displayName: 'LLaMA3-3-8B',
|
|
26
29
|
enabled: true,
|
|
30
|
+
functionCall: true,
|
|
27
31
|
id: 'llama3-8b-8192',
|
|
28
32
|
tokens: 8192,
|
|
29
33
|
},
|
|
@@ -3,24 +3,27 @@ import { ModelProviderCard } from '@/types/llm';
|
|
|
3
3
|
// ref https://www.minimaxi.com/document/guides/chat-model/pro/api
|
|
4
4
|
const Minimax: ModelProviderCard = {
|
|
5
5
|
chatModels: [
|
|
6
|
-
{
|
|
7
|
-
description: '复杂场景,例如应用题计算、科学计算等场景',
|
|
8
|
-
displayName: 'abab6.5',
|
|
9
|
-
enabled: true,
|
|
10
|
-
id: 'abab6.5-chat',
|
|
11
|
-
tokens: 8192,
|
|
12
|
-
},
|
|
13
6
|
{
|
|
14
7
|
description: '通用场景',
|
|
15
8
|
displayName: 'abab6.5s',
|
|
16
9
|
enabled: true,
|
|
10
|
+
functionCall: true,
|
|
17
11
|
id: 'abab6.5s-chat',
|
|
18
12
|
tokens: 245_760,
|
|
19
13
|
},
|
|
14
|
+
{
|
|
15
|
+
description: '复杂场景,例如应用题计算、科学计算等场景',
|
|
16
|
+
displayName: 'abab6.5',
|
|
17
|
+
enabled: true,
|
|
18
|
+
functionCall: true,
|
|
19
|
+
id: 'abab6.5-chat',
|
|
20
|
+
tokens: 8192,
|
|
21
|
+
},
|
|
20
22
|
{
|
|
21
23
|
description: '更复杂的格式化文本生成',
|
|
22
24
|
displayName: 'abab6',
|
|
23
25
|
enabled: true,
|
|
26
|
+
functionCall: true,
|
|
24
27
|
id: 'abab6-chat',
|
|
25
28
|
tokens: 32_768,
|
|
26
29
|
},
|
|
@@ -6,18 +6,21 @@ const Moonshot: ModelProviderCard = {
|
|
|
6
6
|
{
|
|
7
7
|
displayName: 'Moonshot V1 8K',
|
|
8
8
|
enabled: true,
|
|
9
|
+
functionCall: true,
|
|
9
10
|
id: 'moonshot-v1-8k',
|
|
10
11
|
tokens: 8192,
|
|
11
12
|
},
|
|
12
13
|
{
|
|
13
14
|
displayName: 'Moonshot V1 32K',
|
|
14
15
|
enabled: true,
|
|
16
|
+
functionCall: true,
|
|
15
17
|
id: 'moonshot-v1-32k',
|
|
16
18
|
tokens: 32_768,
|
|
17
19
|
},
|
|
18
20
|
{
|
|
19
21
|
displayName: 'Moonshot V1 128K',
|
|
20
22
|
enabled: true,
|
|
23
|
+
functionCall: true,
|
|
21
24
|
id: 'moonshot-v1-128k',
|
|
22
25
|
tokens: 128_000,
|
|
23
26
|
},
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { ModelProviderCard } from '@/types/llm';
|
|
2
2
|
|
|
3
|
-
// TODO: 等待 ZhiPu 修复 API 问题后开启 functionCall
|
|
4
|
-
// 暂时不透出 GLM 系列的 function_call 功能
|
|
5
|
-
// refs https://github.com/lobehub/lobe-chat/discussions/737#discussioncomment-8315815
|
|
6
|
-
|
|
7
3
|
// ref https://open.bigmodel.cn/dev/howuse/model
|
|
8
4
|
const ZhiPu: ModelProviderCard = {
|
|
9
5
|
chatModels: [
|
|
@@ -11,7 +7,7 @@ const ZhiPu: ModelProviderCard = {
|
|
|
11
7
|
description: '最新的 GLM-4 、最大支持 128k 上下文、支持 Function Call 、Retreival',
|
|
12
8
|
displayName: 'GLM-4',
|
|
13
9
|
enabled: true,
|
|
14
|
-
|
|
10
|
+
functionCall: true,
|
|
15
11
|
id: 'glm-4',
|
|
16
12
|
tokens: 128_000,
|
|
17
13
|
},
|
|
@@ -28,7 +24,7 @@ const ZhiPu: ModelProviderCard = {
|
|
|
28
24
|
description: '最新的glm-3-turbo、最大支持 128k上下文、支持Function Call、Retreival',
|
|
29
25
|
displayName: 'GLM-3 Turbo',
|
|
30
26
|
enabled: true,
|
|
31
|
-
|
|
27
|
+
functionCall: true,
|
|
32
28
|
id: 'glm-3-turbo',
|
|
33
29
|
tokens: 128_000,
|
|
34
30
|
},
|
|
@@ -211,7 +211,7 @@ export const getProviderConfig = () => {
|
|
|
211
211
|
AWS_ACCESS_KEY_ID: AWS_ACCESS_KEY_ID,
|
|
212
212
|
AWS_SECRET_ACCESS_KEY: process.env.AWS_SECRET_ACCESS_KEY || '',
|
|
213
213
|
|
|
214
|
-
ENABLE_OLLAMA: process.env.ENABLE_OLLAMA
|
|
214
|
+
ENABLE_OLLAMA: Boolean(process.env.ENABLE_OLLAMA),
|
|
215
215
|
OLLAMA_PROXY_URL: process.env.OLLAMA_PROXY_URL || '',
|
|
216
216
|
OLLAMA_MODEL_LIST: process.env.OLLAMA_MODEL_LIST || process.env.OLLAMA_CUSTOM_MODELS,
|
|
217
217
|
};
|