-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ feat: support chat completion call at client side #2041
Conversation
Someone is attempting to deploy a commit to the LobeHub Team on Vercel. A member of the Team first needs to authorize it. |
👍 @cy948 Thank you for raising your pull request and contributing to our Community |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agent Runtime 里应该还是有一些 server 端的逻辑,估计还是需要一些改造。
- 从 server 取环境变量的逻辑需要抽离出来;
- trace 的部分可能不需要有,或者要改成通过 api 去调用;
c3c8148
to
f57c7e1
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2041 +/- ##
==========================================
+ Coverage 92.77% 92.81% +0.04%
==========================================
Files 265 266 +1
Lines 15086 15361 +275
Branches 1062 1783 +721
==========================================
+ Hits 13996 14258 +262
- Misses 1090 1103 +13 ☔ View full report in Codecov by Sentry. |
endpoint only - 🐛 fix: this feature only enable when user set both apikey and endpoint in one specific llm setting
* ♻️ refactor: remove deprecate class AgentRuntime * ♻️ refactor: fix circular dependence from AgentRuntime * ✅ test: pass tests
fbc2741
to
ec5be8c
Compare
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
❤️ Great PR @cy948 ❤️ The growth of project is inseparable from user feedback and contribution, thanks for your contribution! If you are interesting with the lobehub developer community, please join our discord and then dm @arvinxx or @canisminor1990. They will invite you to our private developer channel. We are talking about the lobe-chat development or sharing ai newsletter around the world. |
## [Version 0.148.0](v0.147.22...v0.148.0) <sup>Released on **2024-04-20**</sup> #### ✨ Features - **misc**: Support chat completion call at client side. <br/> <details> <summary><kbd>Improvements and Fixes</kbd></summary> #### What's improved * **misc**: Support chat completion call at client side, closes [#2041](#2041) ([9f5858f](9f5858f)) </details> <div align="right"> [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top) </div>
🎉 This PR is included in version 0.148.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
## [Version 1.28.0](v1.27.20...v1.28.0) <sup>Released on **2024-04-20**</sup> #### ✨ Features - **misc**: Support chat completion call at client side. <br/> <details> <summary><kbd>Improvements and Fixes</kbd></summary> #### What's improved * **misc**: Support chat completion call at client side, closes [lobehub#2041](https://github.com/bentwnghk/lobe-chat/issues/2041) ([9f5858f](9f5858f)) </details> <div align="right"> [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top) </div>
* ✨ feat: support chat completion call at client side * 🐛 fix: disable agent-runtime in browser feature when user set endpoint only - 🐛 fix: this feature only enable when user set both apikey and endpoint in one specific llm setting * ♻️ refactor: refactor agentruntime * ♻️ refactor: add fetchOnClient * 🚨 chore: eslint Circular Dependencies issue * 💄 feat: Added UI to control fetchOnClient * ✅ test: Passed chat provider test * ♻️ refactor: remove redundant export * ✅ test: add for agentRuntime * 💄 style: remove tag for llm config * ✅ test: add for agentRuntime init * ♻️ refactor: fetchOnClient * ✅ test: add for clinet agentRuntime init * ♻️ refactor: for write tests easily * ✅ test: for client AgentRuntime * 🌐 i18n: fetch on client * ✅ test: agentruntime * ♻️ refactor: don't trace on client * 📝 docs: update annotation for new methods * 🐛fix: error not catch at client * ♻️ refactor: extract trace at chat() * ✅ test: for new chat method * ♻️ refactor: -lines make stats better * ♻️ refactor: remove deprecate * ♻️ refactor: remove deprecate class AgentRuntime * ♻️ refactor: fix circular dependence from AgentRuntime * ✅ test: pass tests * ♻️ refactor: reformat import urls * ♻️ refactor: rename initAgentRuntimeWithUserPayload * 💄 style: improve config * 🌐 style: add i18n * 💄 style: client 默认显示 ollama
## [Version 0.148.0](lobehub/lobe-chat@v0.147.22...v0.148.0) <sup>Released on **2024-04-20**</sup> #### ✨ Features - **misc**: Support chat completion call at client side. <br/> <details> <summary><kbd>Improvements and Fixes</kbd></summary> #### What's improved * **misc**: Support chat completion call at client side, closes [lobehub#2041](lobehub#2041) ([9f5858f](lobehub@9f5858f)) </details> <div align="right"> [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top) </div>
docker 部署如何开启默认使用客户端模式呢 |
How to enable docker deployment to use client mode by default |
目前“是否默认开启客户端模式”功能由社区统一配置,暂时不能由环境变量进行配置。 |
Currently, the "whether to enable client mode by default" function is uniformly configured by the community and cannot be configured by environment variables for the time being. |
* ✨ feat: support chat completion call at client side * 🐛 fix: disable agent-runtime in browser feature when user set endpoint only - 🐛 fix: this feature only enable when user set both apikey and endpoint in one specific llm setting * ♻️ refactor: refactor agentruntime * ♻️ refactor: add fetchOnClient * 🚨 chore: eslint Circular Dependencies issue * 💄 feat: Added UI to control fetchOnClient * ✅ test: Passed chat provider test * ♻️ refactor: remove redundant export * ✅ test: add for agentRuntime * 💄 style: remove tag for llm config * ✅ test: add for agentRuntime init * ♻️ refactor: fetchOnClient * ✅ test: add for clinet agentRuntime init * ♻️ refactor: for write tests easily * ✅ test: for client AgentRuntime * 🌐 i18n: fetch on client * ✅ test: agentruntime * ♻️ refactor: don't trace on client * 📝 docs: update annotation for new methods * 🐛fix: error not catch at client * ♻️ refactor: extract trace at chat() * ✅ test: for new chat method * ♻️ refactor: -lines make stats better * ♻️ refactor: remove deprecate * ♻️ refactor: remove deprecate class AgentRuntime * ♻️ refactor: fix circular dependence from AgentRuntime * ✅ test: pass tests * ♻️ refactor: reformat import urls * ♻️ refactor: rename initAgentRuntimeWithUserPayload * 💄 style: improve config * 🌐 style: add i18n * 💄 style: client 默认显示 ollama
## [Version 0.148.0](lobehub/lobe-chat@v0.147.22...v0.148.0) <sup>Released on **2024-04-20**</sup> #### ✨ Features - **misc**: Support chat completion call at client side. <br/> <details> <summary><kbd>Improvements and Fixes</kbd></summary> #### What's improved * **misc**: Support chat completion call at client side, closes [lobehub#2041](lobehub#2041) ([9f5858f](lobehub@9f5858f)) </details> <div align="right"> [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top) </div>
💻 变更类型 | Change Type
🔀 变更说明 | Description of Change
detail:
src/libs/agent-runtime/AgentRuntime.ts
:从src/app/api/chat/agentRuntime.ts
中将 AgentRuntime 代码抽离,去掉服务端逻辑后得到该 lib; ❇️chat
方法现在接受两个参数:payload:ChatStreamPayload
、options?:ChatCompetitionOptions
;src/libs/agent-runtime/AgentRuntime.test.ts
:为上述模块的测试文件,主要测试AgentRuntime
类能否初始化及正常入参;src/app/api/chat/agentRuntime.ts
:新增方法getLlmOptionsFromPayload
用于处理服务端参数、新增方法initializeWithUserPayload
用于调用src/libs/agent-runtime/AgentRuntime.ts
中的 AgentRuntime,并调用getLlmOptionsFromPayload
进行参数处理;❇️L485:
新增了方法createTraceOptions
用于构建trace
设置。src/app/api/chat/agentRuntime.test.ts
:为上述新增方法initializeWithUserPayload
,getLlmOptionsFromPayload
补充单元测试,主要测试:initializeWithUserPayload
在空payload
下能否正常使用环境变量填补必要的参数,完成AgentRuntime
instance 初始化;initializeWithUserPayload
在非空payload
下能否正常传参,完成AgentRuntime
instance 初始化;src/app/api/chat/[provider]/route.ts
:使用src/app/api/chat/agentRuntime.ts: initializeWithUserPayload
创建服务端 AgentRuntime instance;❇️根据是否启用trace
条件调用chat
方法。src/app/api/chat/[provider]/route.test.ts
:测试对象变更,src/app/api/chat/agentRuntime.ts
->src/libs/agent-runtime/AgentRuntime.ts
;❇️L113:115
,新route.ts
中若用户不开启 trace,chat
方法中没有第二个参数,故移除了对第二个参数的expect
;src/services/chat.ts
:新增方法initializeWithClientStore
用于创建客户端 AgentRuntime instance;❇️移除了L:178
中fetchOnClient
方法的 trace 头构建;src/services/__tests__/chat.test.ts
:新增针对上述方法initializeWithClientStore
的测试;❗ZhiPu AI
在初始化中,generateApiToken
方法报错,只能强制mock该方法结果以通过测试,日后待排查。src/locales/default/setting.ts
:新增fetchOnClient
的翻译,❗ i18n 待 review 后生成;📝 补充信息 | Additional Information
src/services/chat.ts:L271
:使用用户 llm 设置决定是否使用 client 请求;src/services/chat.ts:L85
:目前仅在客户端设置解除 openai 的 sdk 的 browser 端限制,其他 sdk 可能也存在 browser 端限制,目前依靠其他 provider contributor 测试后进行调整;preview: on Vercel
refs: [RFC] 024 - 浏览器端请求方式改造 #1257