@lobehub/chat 0.147.22 → 0.148.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/locales/ar/setting.json +4 -0
- package/locales/bg-BG/setting.json +4 -0
- package/locales/de-DE/setting.json +4 -0
- package/locales/en-US/setting.json +4 -0
- package/locales/es-ES/setting.json +4 -0
- package/locales/fr-FR/setting.json +4 -0
- package/locales/it-IT/setting.json +4 -0
- package/locales/ja-JP/setting.json +4 -0
- package/locales/ko-KR/setting.json +4 -0
- package/locales/nl-NL/setting.json +4 -0
- package/locales/pl-PL/setting.json +4 -0
- package/locales/pt-BR/setting.json +4 -0
- package/locales/ru-RU/setting.json +4 -0
- package/locales/tr-TR/setting.json +4 -0
- package/locales/vi-VN/setting.json +4 -0
- package/locales/zh-CN/setting.json +4 -0
- package/locales/zh-TW/setting.json +4 -0
- package/package.json +31 -30
- package/src/app/api/chat/[provider]/route.test.ts +5 -7
- package/src/app/api/chat/[provider]/route.ts +13 -7
- package/src/app/api/chat/agentRuntime.test.ts +195 -451
- package/src/app/api/chat/agentRuntime.ts +197 -280
- package/src/app/api/chat/models/[provider]/route.ts +2 -2
- package/src/app/settings/llm/components/ProviderConfig/index.tsx +23 -1
- package/src/app/settings/llm/index.tsx +2 -2
- package/src/app/settings/llm/page.tsx +1 -5
- package/src/libs/agent-runtime/AgentRuntime.test.ts +400 -0
- package/src/libs/agent-runtime/AgentRuntime.ts +192 -0
- package/src/libs/agent-runtime/index.ts +1 -0
- package/src/locales/default/setting.ts +4 -0
- package/src/services/__tests__/chat.test.ts +287 -1
- package/src/services/chat.ts +148 -2
- package/src/store/chat/slices/topic/action.test.ts +1 -3
- package/src/store/chat/slices/topic/action.ts +5 -10
- package/src/store/global/slices/settings/selectors/modelConfig.ts +13 -0
- package/src/types/settings/modelProvider.ts +4 -0
- package/vercel.json +1 -1
- package/vitest.config.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,56 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
### [Version 0.148.1](https://github.com/lobehub/lobe-chat/compare/v0.148.0...v0.148.1)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2024-04-20**</sup>
|
|
8
|
+
|
|
9
|
+
#### 🐛 Bug Fixes
|
|
10
|
+
|
|
11
|
+
- **misc**: Fix topic title not auto generate.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### What's fixed
|
|
19
|
+
|
|
20
|
+
- **misc**: Fix topic title not auto generate, closes [#2114](https://github.com/lobehub/lobe-chat/issues/2114) ([5979de3](https://github.com/lobehub/lobe-chat/commit/5979de3))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
## [Version 0.148.0](https://github.com/lobehub/lobe-chat/compare/v0.147.22...v0.148.0)
|
|
31
|
+
|
|
32
|
+
<sup>Released on **2024-04-20**</sup>
|
|
33
|
+
|
|
34
|
+
#### ✨ Features
|
|
35
|
+
|
|
36
|
+
- **misc**: Support chat completion call at client side.
|
|
37
|
+
|
|
38
|
+
<br/>
|
|
39
|
+
|
|
40
|
+
<details>
|
|
41
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
42
|
+
|
|
43
|
+
#### What's improved
|
|
44
|
+
|
|
45
|
+
- **misc**: Support chat completion call at client side, closes [#2041](https://github.com/lobehub/lobe-chat/issues/2041) ([9f5858f](https://github.com/lobehub/lobe-chat/commit/9f5858f))
|
|
46
|
+
|
|
47
|
+
</details>
|
|
48
|
+
|
|
49
|
+
<div align="right">
|
|
50
|
+
|
|
51
|
+
[](#readme-top)
|
|
52
|
+
|
|
53
|
+
</div>
|
|
54
|
+
|
|
5
55
|
### [Version 0.147.22](https://github.com/lobehub/lobe-chat/compare/v0.147.21...v0.147.22)
|
|
6
56
|
|
|
7
57
|
<sup>Released on **2024-04-19**</sup>
|
package/locales/ar/setting.json
CHANGED
|
@@ -75,6 +75,10 @@
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
|
+
"fetchOnClient": {
|
|
79
|
+
"desc": "طريقة طلب العميل ستبدأ طلب الجلسة مباشرة من المتصفح، مما يمكن أن يعزز سرعة الاستجابة",
|
|
80
|
+
"title": "استخدام طريقة طلب العميل"
|
|
81
|
+
},
|
|
78
82
|
"fetcher": {
|
|
79
83
|
"fetch": "احصل على قائمة النماذج",
|
|
80
84
|
"fetching": "جاري الحصول على قائمة النماذج...",
|
|
@@ -75,6 +75,10 @@
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
|
+
"fetchOnClient": {
|
|
79
|
+
"desc": "Режимът на заявка от клиента стартира заявката директно от браузъра, което може да увеличи скоростта на отговора",
|
|
80
|
+
"title": "Използване на режим на заявка от клиента"
|
|
81
|
+
},
|
|
78
82
|
"fetcher": {
|
|
79
83
|
"fetch": "Изтегляне на списъка с модели",
|
|
80
84
|
"fetching": "Изтегляне на списъка с модели...",
|
|
@@ -75,6 +75,10 @@
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
|
+
"fetchOnClient": {
|
|
79
|
+
"desc": "Client Fetch-Modus initiiert direkte Sitzungsanfragen vom Browser aus und verbessert die Reaktionsgeschwindigkeit.",
|
|
80
|
+
"title": "Client Fetch-Modus verwenden"
|
|
81
|
+
},
|
|
78
82
|
"fetcher": {
|
|
79
83
|
"fetch": "Modelle abrufen",
|
|
80
84
|
"fetching": "Modelle werden abgerufen...",
|
|
@@ -75,6 +75,10 @@
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
|
+
"fetchOnClient": {
|
|
79
|
+
"desc": "Client-side fetching mode initiates session requests directly from the browser, improving response speed.",
|
|
80
|
+
"title": "Use Client-Side Fetching Mode"
|
|
81
|
+
},
|
|
78
82
|
"fetcher": {
|
|
79
83
|
"fetch": "Get Model List",
|
|
80
84
|
"fetching": "Fetching Model List...",
|
|
@@ -75,6 +75,10 @@
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
|
+
"fetchOnClient": {
|
|
79
|
+
"desc": "El modo de solicitud en el cliente iniciará directamente la solicitud de sesión desde el navegador, lo que puede mejorar la velocidad de respuesta",
|
|
80
|
+
"title": "Usar el modo de solicitud en el cliente"
|
|
81
|
+
},
|
|
78
82
|
"fetcher": {
|
|
79
83
|
"fetch": "Obtener lista de modelos",
|
|
80
84
|
"fetching": "Obteniendo lista de modelos...",
|
|
@@ -75,6 +75,10 @@
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
|
+
"fetchOnClient": {
|
|
79
|
+
"desc": "Le mode de requête client lancera directement une session à partir du navigateur, améliorant ainsi la vitesse de réponse",
|
|
80
|
+
"title": "Utiliser le mode de requête client"
|
|
81
|
+
},
|
|
78
82
|
"fetcher": {
|
|
79
83
|
"fetch": "Obtenir la liste des modèles",
|
|
80
84
|
"fetching": "Récupération de la liste des modèles en cours...",
|
|
@@ -75,6 +75,10 @@
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
|
+
"fetchOnClient": {
|
|
79
|
+
"desc": "Il modo di richiesta del client consente di avviare direttamente una richiesta di sessione dal browser, migliorando i tempi di risposta",
|
|
80
|
+
"title": "Utilizzo del modo di richiesta del client"
|
|
81
|
+
},
|
|
78
82
|
"fetcher": {
|
|
79
83
|
"fetch": "Ottenere l'elenco dei modelli",
|
|
80
84
|
"fetching": "Recupero dell'elenco dei modelli in corso...",
|
|
@@ -75,6 +75,10 @@
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
|
+
"fetchOnClient": {
|
|
79
|
+
"desc": "O modo de solicitação do cliente iniciará diretamente a solicitação da sessão a partir do navegador, melhorando a velocidade de resposta",
|
|
80
|
+
"title": "Usar o modo de solicitação do cliente"
|
|
81
|
+
},
|
|
78
82
|
"fetcher": {
|
|
79
83
|
"fetch": "Obter lista de modelos",
|
|
80
84
|
"fetching": "Obtendo lista de modelos...",
|
|
@@ -75,6 +75,10 @@
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
|
+
"fetchOnClient": {
|
|
79
|
+
"desc": "Режим запроса с клиента позволяет инициировать запрос сеанса непосредственно из браузера, что улучшает скорость ответа",
|
|
80
|
+
"title": "Использовать режим запроса с клиента"
|
|
81
|
+
},
|
|
78
82
|
"fetcher": {
|
|
79
83
|
"fetch": "Получить список моделей",
|
|
80
84
|
"fetching": "Идет получение списка моделей...",
|
|
@@ -75,6 +75,10 @@
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
|
+
"fetchOnClient": {
|
|
79
|
+
"desc": "İstemci tarafından alınan veri: Tarayıcı, doğrudan oturum isteği gönderir ve yanıt hızını artırabilir.",
|
|
80
|
+
"title": "İstemci Tarafından Veri Alımı"
|
|
81
|
+
},
|
|
78
82
|
"fetcher": {
|
|
79
83
|
"fetch": "Modelleri Al",
|
|
80
84
|
"fetching": "Modelleri alınıyor...",
|
|
@@ -75,6 +75,10 @@
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
|
+
"fetchOnClient": {
|
|
79
|
+
"desc": "Chế độ yêu cầu từ khách hàng sẽ khởi động yêu cầu phiên trực tiếp từ trình duyệt, có thể cải thiện tốc độ phản hồi",
|
|
80
|
+
"title": "Sử dụng chế độ yêu cầu từ khách hàng"
|
|
81
|
+
},
|
|
78
82
|
"fetcher": {
|
|
79
83
|
"fetch": "Lấy danh sách mô hình",
|
|
80
84
|
"fetching": "Đang lấy danh sách mô hình...",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/chat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.148.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",
|
|
@@ -83,23 +83,23 @@
|
|
|
83
83
|
"@ant-design/icons": "^5.3.6",
|
|
84
84
|
"@anthropic-ai/sdk": "^0.18.0",
|
|
85
85
|
"@auth/core": "0.28.0",
|
|
86
|
-
"@aws-sdk/client-bedrock-runtime": "^3.
|
|
86
|
+
"@aws-sdk/client-bedrock-runtime": "^3.556.0",
|
|
87
87
|
"@azure/openai": "^1.0.0-beta.12",
|
|
88
88
|
"@cfworker/json-schema": "^1.12.8",
|
|
89
|
-
"@google/generative-ai": "^0.7.
|
|
90
|
-
"@icons-pack/react-simple-icons": "^9.4.
|
|
89
|
+
"@google/generative-ai": "^0.7.1",
|
|
90
|
+
"@icons-pack/react-simple-icons": "^9.4.1",
|
|
91
91
|
"@lobehub/chat-plugin-sdk": "latest",
|
|
92
92
|
"@lobehub/chat-plugins-gateway": "latest",
|
|
93
93
|
"@lobehub/icons": "latest",
|
|
94
94
|
"@lobehub/tts": "latest",
|
|
95
|
-
"@lobehub/ui": "^1.138.
|
|
96
|
-
"@next/third-parties": "^14.
|
|
97
|
-
"@sentry/nextjs": "^7.
|
|
95
|
+
"@lobehub/ui": "^1.138.6",
|
|
96
|
+
"@next/third-parties": "^14.2.2",
|
|
97
|
+
"@sentry/nextjs": "^7.111.0",
|
|
98
98
|
"@vercel/analytics": "^1.2.2",
|
|
99
99
|
"@vercel/speed-insights": "^1.0.10",
|
|
100
100
|
"ahooks": "^3.7.11",
|
|
101
101
|
"ai": "3.0.19",
|
|
102
|
-
"antd": "^5.16.
|
|
102
|
+
"antd": "^5.16.2",
|
|
103
103
|
"antd-style": "^3.6.2",
|
|
104
104
|
"brotli-wasm": "^2.0.1",
|
|
105
105
|
"chroma-js": "^2.4.2",
|
|
@@ -109,17 +109,17 @@
|
|
|
109
109
|
"diff": "^5.2.0",
|
|
110
110
|
"fast-deep-equal": "^3.1.3",
|
|
111
111
|
"gpt-tokenizer": "^2.1.2",
|
|
112
|
-
"i18next": "^23.11.
|
|
112
|
+
"i18next": "^23.11.2",
|
|
113
113
|
"i18next-browser-languagedetector": "^7.2.1",
|
|
114
|
-
"i18next-resources-to-backend": "^1.2.
|
|
114
|
+
"i18next-resources-to-backend": "^1.2.1",
|
|
115
115
|
"idb-keyval": "^6.2.1",
|
|
116
116
|
"immer": "^10.0.4",
|
|
117
117
|
"jose": "^5.2.4",
|
|
118
|
-
"langfuse": "^3.
|
|
119
|
-
"langfuse-core": "^3.
|
|
118
|
+
"langfuse": "^3.7.0",
|
|
119
|
+
"langfuse-core": "^3.7.0",
|
|
120
120
|
"lodash-es": "^4.17.21",
|
|
121
121
|
"lucide-react": "latest",
|
|
122
|
-
"modern-screenshot": "^4.4.
|
|
122
|
+
"modern-screenshot": "^4.4.39",
|
|
123
123
|
"nanoid": "^5.0.7",
|
|
124
124
|
"next": "14.1.4",
|
|
125
125
|
"next-auth": "5.0.0-beta.15",
|
|
@@ -127,9 +127,9 @@
|
|
|
127
127
|
"numeral": "^2.0.6",
|
|
128
128
|
"nuqs": "^1.17.1",
|
|
129
129
|
"ollama": "^0.5.0",
|
|
130
|
-
"openai": "^4.
|
|
130
|
+
"openai": "^4.38.2",
|
|
131
131
|
"polished": "^4.3.1",
|
|
132
|
-
"posthog-js": "^1.
|
|
132
|
+
"posthog-js": "^1.128.1",
|
|
133
133
|
"query-string": "^9.0.0",
|
|
134
134
|
"random-words": "^2.0.1",
|
|
135
135
|
"react": "^18.2.0",
|
|
@@ -138,7 +138,7 @@
|
|
|
138
138
|
"react-i18next": "^14.1.0",
|
|
139
139
|
"react-layout-kit": "^1.9.0",
|
|
140
140
|
"react-lazy-load": "^4.0.1",
|
|
141
|
-
"react-virtuoso": "^4.7.
|
|
141
|
+
"react-virtuoso": "^4.7.9",
|
|
142
142
|
"react-wrap-balancer": "^1.1.0",
|
|
143
143
|
"remark": "^14.0.3",
|
|
144
144
|
"remark-gfm": "^3.0.1",
|
|
@@ -158,41 +158,41 @@
|
|
|
158
158
|
"y-webrtc": "^10.3.0",
|
|
159
159
|
"yaml": "^2.4.1",
|
|
160
160
|
"yjs": "^13.6.14",
|
|
161
|
-
"zod": "^3.22.
|
|
161
|
+
"zod": "^3.22.5",
|
|
162
162
|
"zustand": "^4.5.2",
|
|
163
163
|
"zustand-utils": "^1.3.2"
|
|
164
164
|
},
|
|
165
165
|
"devDependencies": {
|
|
166
|
-
"@commitlint/cli": "^19.2.
|
|
166
|
+
"@commitlint/cli": "^19.2.2",
|
|
167
167
|
"@ducanh2912/next-pwa": "^10.2.6",
|
|
168
168
|
"@edge-runtime/vm": "^3.2.0",
|
|
169
169
|
"@lobehub/i18n-cli": "^1.18.1",
|
|
170
170
|
"@lobehub/lint": "^1.23.3",
|
|
171
171
|
"@lobehub/seo-cli": "^1.4.1",
|
|
172
|
-
"@next/bundle-analyzer": "^14.
|
|
173
|
-
"@next/eslint-plugin-next": "^14.
|
|
172
|
+
"@next/bundle-analyzer": "^14.2.2",
|
|
173
|
+
"@next/eslint-plugin-next": "^14.2.2",
|
|
174
174
|
"@peculiar/webcrypto": "^1.4.6",
|
|
175
175
|
"@testing-library/jest-dom": "^6.4.2",
|
|
176
|
-
"@testing-library/react": "^15.0.
|
|
176
|
+
"@testing-library/react": "^15.0.2",
|
|
177
177
|
"@types/chroma-js": "^2.4.4",
|
|
178
178
|
"@types/debug": "^4.1.12",
|
|
179
|
-
"@types/diff": "^5.0
|
|
179
|
+
"@types/diff": "^5.2.0",
|
|
180
180
|
"@types/json-schema": "^7.0.15",
|
|
181
181
|
"@types/lodash": "^4.17.0",
|
|
182
182
|
"@types/lodash-es": "^4.17.12",
|
|
183
|
-
"@types/node": "^20.12.
|
|
183
|
+
"@types/node": "^20.12.7",
|
|
184
184
|
"@types/numeral": "^2.0.5",
|
|
185
|
-
"@types/react": "^18.2.
|
|
186
|
-
"@types/react-dom": "^18.2.
|
|
185
|
+
"@types/react": "^18.2.79",
|
|
186
|
+
"@types/react-dom": "^18.2.25",
|
|
187
187
|
"@types/rtl-detect": "^1.0.3",
|
|
188
188
|
"@types/semver": "^7.5.8",
|
|
189
189
|
"@types/systemjs": "^6.13.5",
|
|
190
190
|
"@types/ua-parser-js": "^0.7.39",
|
|
191
191
|
"@types/uuid": "^9.0.8",
|
|
192
|
-
"@umijs/lint": "^4.1.
|
|
192
|
+
"@umijs/lint": "^4.1.10",
|
|
193
193
|
"@vitest/coverage-v8": "~1.2.2",
|
|
194
194
|
"ajv-keywords": "^5.1.0",
|
|
195
|
-
"commitlint": "^19.2.
|
|
195
|
+
"commitlint": "^19.2.2",
|
|
196
196
|
"consola": "^3.2.3",
|
|
197
197
|
"dpdm": "^3.14.0",
|
|
198
198
|
"eslint": "^8.57.0",
|
|
@@ -200,13 +200,14 @@
|
|
|
200
200
|
"fake-indexeddb": "^5.0.2",
|
|
201
201
|
"glob": "^10.3.12",
|
|
202
202
|
"gray-matter": "^4.0.3",
|
|
203
|
+
"happy-dom": "^14.7.1",
|
|
203
204
|
"husky": "^9.0.11",
|
|
204
|
-
"jsdom": "^24.0.0",
|
|
205
205
|
"just-diff": "^6.0.2",
|
|
206
206
|
"lint-staged": "^15.2.2",
|
|
207
207
|
"lodash": "^4.17.21",
|
|
208
208
|
"markdown-table": "^3.0.3",
|
|
209
209
|
"node-fetch": "^3.3.2",
|
|
210
|
+
"node-gyp": "^10.1.0",
|
|
210
211
|
"p-map": "^7.0.2",
|
|
211
212
|
"prettier": "^3.2.5",
|
|
212
213
|
"remark-cli": "^11.0.0",
|
|
@@ -214,10 +215,10 @@
|
|
|
214
215
|
"semantic-release": "^21.1.2",
|
|
215
216
|
"stylelint": "^15.11.0",
|
|
216
217
|
"tsx": "^4.7.2",
|
|
217
|
-
"typescript": "^5.4.
|
|
218
|
+
"typescript": "^5.4.5",
|
|
218
219
|
"unified": "^11.0.4",
|
|
219
220
|
"unist-util-visit": "^5.0.0",
|
|
220
|
-
"vite": "^5.2.
|
|
221
|
+
"vite": "^5.2.10",
|
|
221
222
|
"vitest": "~1.2.2",
|
|
222
223
|
"vitest-canvas-mock": "^0.3.3"
|
|
223
224
|
},
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
3
|
|
|
4
4
|
import { LOBE_CHAT_AUTH_HEADER, OAUTH_AUTHORIZED } from '@/const/auth';
|
|
5
|
-
import { LobeRuntimeAI } from '@/libs/agent-runtime';
|
|
5
|
+
import { AgentRuntime, LobeRuntimeAI } from '@/libs/agent-runtime';
|
|
6
6
|
import { ChatErrorType } from '@/types/fetch';
|
|
7
7
|
|
|
8
|
-
import AgentRuntime from '../agentRuntime';
|
|
9
8
|
import { getJWTPayload } from '../auth/utils';
|
|
10
9
|
import { POST } from './route';
|
|
11
10
|
|
|
@@ -37,7 +36,7 @@ describe('POST handler', () => {
|
|
|
37
36
|
it('should initialize AgentRuntime correctly with valid authorization', async () => {
|
|
38
37
|
const mockParams = { provider: 'test-provider' };
|
|
39
38
|
|
|
40
|
-
// 设置 getJWTPayload 和
|
|
39
|
+
// 设置 getJWTPayload 和 initAgentRuntimeWithUserPayload 的模拟返回值
|
|
41
40
|
vi.mocked(getJWTPayload).mockResolvedValue({
|
|
42
41
|
accessCode: 'test-access-code',
|
|
43
42
|
apiKey: 'test-api-key',
|
|
@@ -46,8 +45,9 @@ describe('POST handler', () => {
|
|
|
46
45
|
|
|
47
46
|
const mockRuntime: LobeRuntimeAI = { baseURL: 'abc', chat: vi.fn() };
|
|
48
47
|
|
|
48
|
+
// migrate to new AgentRuntime init api
|
|
49
49
|
const spy = vi
|
|
50
|
-
.spyOn(AgentRuntime, '
|
|
50
|
+
.spyOn(AgentRuntime, 'initializeWithProviderOptions')
|
|
51
51
|
.mockResolvedValue(new AgentRuntime(mockRuntime));
|
|
52
52
|
|
|
53
53
|
// 调用 POST 函数
|
|
@@ -110,9 +110,7 @@ describe('POST handler', () => {
|
|
|
110
110
|
const response = await POST(request as unknown as Request, { params: mockParams });
|
|
111
111
|
|
|
112
112
|
expect(response).toEqual(mockChatResponse);
|
|
113
|
-
expect(AgentRuntime.prototype.chat).toHaveBeenCalledWith(mockChatPayload
|
|
114
|
-
provider: 'test-provider',
|
|
115
|
-
});
|
|
113
|
+
expect(AgentRuntime.prototype.chat).toHaveBeenCalledWith(mockChatPayload);
|
|
116
114
|
});
|
|
117
115
|
|
|
118
116
|
it('should return an error response when chat completion fails', async () => {
|
|
@@ -5,7 +5,7 @@ import { ChatErrorType } from '@/types/fetch';
|
|
|
5
5
|
import { ChatStreamPayload } from '@/types/openai/chat';
|
|
6
6
|
import { getTracePayload } from '@/utils/trace';
|
|
7
7
|
|
|
8
|
-
import
|
|
8
|
+
import { createTraceOptions, initAgentRuntimeWithUserPayload } from '../agentRuntime';
|
|
9
9
|
import { checkAuth } from '../auth';
|
|
10
10
|
|
|
11
11
|
export const runtime = 'edge';
|
|
@@ -17,7 +17,7 @@ export const POST = checkAuth(async (req: Request, { params, jwtPayload }) => {
|
|
|
17
17
|
|
|
18
18
|
try {
|
|
19
19
|
// ============ 1. init chat model ============ //
|
|
20
|
-
const agentRuntime = await
|
|
20
|
+
const agentRuntime = await initAgentRuntimeWithUserPayload(provider, jwtPayload);
|
|
21
21
|
|
|
22
22
|
// ============ 2. create chat completion ============ //
|
|
23
23
|
|
|
@@ -25,11 +25,17 @@ export const POST = checkAuth(async (req: Request, { params, jwtPayload }) => {
|
|
|
25
25
|
|
|
26
26
|
const tracePayload = getTracePayload(req);
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
// If user enable trace
|
|
29
|
+
if (tracePayload?.enabled) {
|
|
30
|
+
return await agentRuntime.chat(
|
|
31
|
+
data,
|
|
32
|
+
createTraceOptions(data, {
|
|
33
|
+
provider,
|
|
34
|
+
trace: tracePayload,
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return await agentRuntime.chat(data);
|
|
33
39
|
} catch (e) {
|
|
34
40
|
const {
|
|
35
41
|
errorType = ChatErrorType.InternalServerError,
|