* ♻️ refactor: refactor the user store with auth slice
* ♻️ refactor: separate common and sync slice
* 🧑💻 chore: add an isMobile selector
* ♻️ refactor: refactor the auth action and common action
* 🎨 chore: clean code
* 🐛 fix: plugins with multiple settings cannot be correctly configured
* ♻️ refactor: merge plugin setting in the action layer instead of UI
* ✅ test: add a test to ensure plugin settings are correctly merged
* 🐛 fix: fix display error when using DEFAULT_AGENT_CONFIG env
* 🔥 chore: remove file
* ✅ test: add more test
* ✅ test: add more test
* ✅ test: add more test
* ✅ test: add more test
* Upon completion of the reset process, a pop-up window will appear, displaying the message "Reset Successfully."
* Update zh-CN/setting.json
* translation
* ✨ new: support more model Icons: dbrx, command-r, openchat, rwkv, Bert-vits2, Stable Diffusion, WizardLM, adobe firefly, skylark
* 💄 add: model Stable Cascade
* 💄 add: Jamba and OpenChat
* ♻️ refactor: support more model Icons: dbrx, command-r, openchat, rwkv, Bert-vits2, Stable Diffusion, WizardLM, adobe firefly, skylark and so on
* 💄 fix: remove unused Zhipu from import
* 💄 fix: 01.AI not show Icons in other providers.
* 💄 style: support together ai model fetch
* 💄 style: support together ai model fetch
* 💄 style: support together ai model fetch
* 💄 style: support together ai model fetch
* ♻️ refactor: remove preference hydration
* 🐛 fix: fix model-list menu not display correctly
* 🐛 fix: fix azure not show the deployment name
* ♻️ refactor: rename the StoreHydration
* 💄 style : ico files from online to local
* 💄 style : ico files from online to local
* 💄 style : Convert some ico files from online to local.
* Optimize some code
* 💄 chore: add M and B support max token in ModelInfoTags
* 💄 chore: add M and B support max token in ModelInfoTags
* 💄 chore: add M and B support max token in ModelInfoTags
* 💄 chore: add M support max token in ModelInfoTags
* 💄 models: Mixtral 8x22b is no longer free, and added WizardLM 2 8x22b by default.
* 💄 style: Remove reversed or custom models from official model list.
* 💄 style: Perplexity model name updates
* 💄 style: add model refs doc for update check
* 💄 chore: remove gpt-4-all feature flag test
* 💄 chore: remove gpt-4-all feature flag modelEnabledFiles test
* 🐛 fix: fix not enabled azure openai
* 🐛 fix: fix user define model meta not work
* 🐛 fix: use default server enabledModels
* ⚡️ perf: support more powerful env
* ✅ test: improve test
* ⚡️ perf: support Azure Model List
* ✅ test: fix test
* 🎉 add: GPT-4-turbo and 2024-04-09 Turbo Vision model
* fix typo
* 💄 optmize: mistral Optimized model name change
* 💄 fix: Hide 8x22B by default, this is a local LLM
* 💄 fix: disabled GPT4 Preview version by default
* ✅ test: fix test
* 🐛 fix: topic list displayed incorrectly after switching sessions following search.
* 🐛 fix: Only perform topic search in current session
* ✅ test: add test for search topic
* Support TogetherAI as new model provider
* Setting>LLM>TogetherAI temporary use text only, waiting for new icon for TogetherAI
* Add TOGETHERAI_API_KEY env into Dockerfile and update env docs
* Clean up debug log
* Avoid conflict CI test: model google/gemma-7b-it with openrouter
* Add test case for agent runtime TogetherAI
* ⚡️ perf: improve performance of image load
* ♻️ refactor: refactor the market search bar for mobile
* ♻️ refactor: refactor the chat search bar for mobile
* ✨add: Support 01-AI Models
* 🔧 chore: fix a config typo for model desc
* 🌐 add: Base 01.AI locale json
* 🐛 fix: remove custom model name and dark mode Logo for 01AI
* 💄 optimize: optimize the 01AI/Groq icon show and fix unused import
* 💄 optimize: optimize the settings icon show rules
* ✨ feat: add 01.AI APIKey Error Form
* 💄 fix: PR 01.AI review issue
* 💄 revert: Groq logo change
* 🌐 style: update locale
* ✨ feat: support sync with webrtc
* 🎨 chore: improve code
* 🎨 chore: improve code
* 🐛 fix: fix dont sync when a node enter first
* ✨ feat: support webrtc config settings
* ✨ feat: add device info card
* ✨ feat: finish sync settings
* ✨ feat: finish sync settings page
* ♻️ refactor: refactor the db to support yjs sync
* 🐛 fix: disconnect when user disable sync
* ♻️ refactor: refactor the console with debug
* 🚸 style: add experiment feature tag
* 📱 style: fix with mobile
* 🌐 chore: add i18n
* 💄 style: improve random name action
* 🚸 style: add default Device Name
* 🚸 style: add mobile experiment tag
* 🚨 ci: fix lint
* ✨ feat: new claude 3 models in bedrock
* ✨ support claude 3 params and stream handling
* ♻️ fix: remove useless condition check
* ✨ feat: add haiku to both bedrock and anthropic provider
* ✨ feat: support langfuse trace
* ✅ test: fix test
* ✅ test: add test
* ✅ test: add db user test
* ✅ test: add test
* ♻️ refactor: refactor the route code
* ♻️ refactor: make updateMessageContent the private method
* ✨ feat: langfuse with user events
* ✅ test: fix test
* ⚡️ perf: improve trace
* ✅ test: add tests
* 🚧 wip: notification
* ♻️ refactor: refactor the common settings
* ✨ feat: add about page
* ✨ feat: add about page
* ✨ feat: add control with user settings
* ✨ feat: add telemetry in mobile
* ✅ test: fix test
* 🌐 chore: add i18n
* ✨ feat: Support multiple API keys [RFC 027]
* 📝 docs: add env variable API_KEY_SELECT_MODE
* 🔧 chore: Adjust the parameter API_KEY_SELECT_MODE to be optional
* 🔧 fix: Adjustments made according to Code Review requirements
* ✅ test: add test for ApiKeyManager
* 🔧 fix: Support for multiple API Keys from user input on the client side
* 🔧 chore: handle Perplexity API Key
* 🔧 chore: update OpenAI or Azure API Key select
* 🔧 chore: update OpenAI or Azure API Key select
* ⬆️ chore: update next-auth to 5.0.0-beta.13
- ⬆️ chore: update @auth/core to ^0.27.0
* 🐛 fix: Could not get `user_id` from session
* ⬆️ chore: Unlock next-auth to `beta`
* 📝 docs: Add custom session guide
* 🐛 fix: use `user_id` from next-auth
* 🐛 fix(oauth): fix OAuth throws an error on Vercel deploy (#1277)
* 🐛 fix(oauth): OAuth throws an error (#1274)
* 🐛 fix(oauth): "ikm" argument must be of type string or an instance of SecretKeyObject
* 📝 docs: Update Auth0 callback URLs in deployment docs
The documentation for both the English and Chinese versions of the
Authentication setup has been updated to include instructions on
configuring the Allowed Callback URLs for Auth0. This step is crucial
for ensuring that the authentication process works correctly after
deployment. The notes added emphasize the importance of keeping the
callback URLs consistent with the deployed service's URLs.
* 📝 docs(oauth): Fix wiki documents
* 🐛 fix: only add auth layout when enabled
---------
Co-authored-by: 小云丨Arale <30863298+CloudPassenger@users.noreply.github.com>
* ✨ feat: adding OAuth2 support
* 🐛 fix: translation for OAuth2
* ♻️ refactor: refactor OAuth 2.0
- clean up code under /api/openai
- update middleware.ts to use custom middleware
- clean up unnessary type definitions
* ♻️ refactor(config): Use server config to enable/disable OAuth 2.0
* 🐛 fix: Adapt OAuth 2.0 middleware to new authentication methods
* 📝 docs(config): Environment variables for Authentication Service Providers
* 📝 docs: Add authentication setup guides for LobeChat
docs: Add authentication setup guides for LobeChat
```
Added detailed documentation for setting up the authentication services in LobeChat, with a focus on integrating Auth0. This includes guides for creating an Auth0 application, adding users, and configuring environment variables. Advanced topics cover connecting to existing single sign-on services and setting up social logins. This effort enhances the platform's security and provides clear instructions for enterprise users on authentication procedures.
* 📝 docs: Add authentication integration guide for LobeChat
docs: Add authentication integration guide with Auth.js
Adds a comprehensive guide on integrating a new authentication provider
using Auth.js in both English and Chinese documentation. The guide
includes pre-requisites, step-by-step code integration, server
configuration updates, frontend changes, and environment variable setup.
```
The changes introduce a new guide in the documentation for integrating new authentication providers using Auth.js. The guide is provided in both English and Chinese, ensuring broad accessibility. It covers the necessary pre-requisites, detailed instructions for adding the core authentication code, updating server configuration, modifying frontend components, and setting up the required environment variables. This will aid developers in implementing authentication features using Auth.js in the LobeChat application.
* ✨ feat: support claude
* ✨ feat: support google vision
* ✨ feat: add proxy to provider
* ✨ feat: add google config
* ✨ feat: fix google error handle
* ✨ feat: support bedrock error handle
* ♻️ refactor: refactor the auth with jwt
* ✅ test: fix the openai runtime test
* ♻️ refactor: refactor the settings config
* ✨ feat: refactor the model select in agent setting
* 🎨 chore: improve model list
* ✨ feat: support custom api Key form
* 🎨 chore: improve code
* ♻️ refactor: refactor the custom models
* 💄 style: improve model icon
* ✨ feat: add google handle
* 🌐 style: add i18n
* 📝 docs: add env document about new providers
* 💄 style: improve plugin tag and model options
* ✨ feat: allow user to add agent without redirection
* ✅ test: add test in action.ts if isSwitchSession is false
* 🔖 chore: add additional skeleton button for loading
* 🌐 style: add i18n
* 🔖 chore: Refactor agent creation and session handling in Header component
* 📝 docs: add more development docs
* 📝 docs: add more development docs
* 📝 docs: update docs
* 📝 docs: update document
* 📝 docs: update documents
* 💚 ci: try to fix test ci
* 💚 ci: try to fix test ci
* 🌐 feat(lang): Add Arabic language support
* 🌐 feat(lang): Add Arabic to LocaleOptions & fix RTL direction
* 🌐 feat(lang): Add Arabic to LocaleOptions & fix RTL direction
* 🎨 style(lang): Improve RTL support and use native Arabic label
* 💄 style: fix topic bar empty when hide at first render
* 🐛 fix: having line breaks after sending messages
* ✅ test: add test for preventDefault
* ✅ test: add test for preventDefault
* 🔨 chore: Add vi-VN locale to language setting option
* 🔨 chore: Add all Vietnamese files for the UI
* ✨ feat: add SpeedInsights and change local port to 4010
* 🔨 chore: remove SpeedInsight and revert local port number
* 🔨 chore: remove Vercel SpeedInsights package
* 🔨 chore: Update the vi-VN folder using i18nrc.js and add the missing string "downloading"
* ✨ feat: support markdown type plugin
* 🚨 ci: fix ci
* 🚨 ci: fix test
* ✨ feat: support trigger AI message and create assistant message
* ✅ test: add unit tests
* 📸 test: update test
* 📸 test: update test
* 💄 style: improve loading style
* ♻️ refactor: refactor the FileList
* 🐛 fix: fix agent market index not work with docker
* 🐛 fix: fix CUSTOM_MODEL don't work with docker deployment
* ✅ test: add test
* 📝 docs: update docs
* ✨ feat: add dalle image generation api
* ✨ feat: support to generate images with dalle3
* ✅ test: update test for the tool
* 🌐 docs: update i18n
* 💄 style: improve style
* 🚸 style: improve image generate process
* 🐛 fix: inject tool desc into agent system role
* 💚 ci: fix circular
* ✅ test: add more tests
* ✅ test: add more tests
* ✨ feat: support show tools token
* ♻️ refactor: refactor with plugin dev
* ✅ test: add test for chain
* 🐛 fix: fix plugin display in tool
* ✅ test: add test for plugin service
* ✅ test: add test for plugin service
* 💚 ci: fix ci
* ⚡️ feat: support using env variable to set preferredRegion for OpenAI edge function
* fix: fix the import problems
* ⚡️ feat: add preferredRegion support for tts and stt
* ✅ test: add more unit test for config.ts and server.ts
---------
Co-authored-by: vophan <dev@vophan.day>
* ✨ feat: support the auto create topic configuration
* 🐛 fix: fix the inbox session that not response on config
* ♻️ refactor: rename the agentConfig folder to agent
* 🎨 refactor: improve code
* 🌐 chore: add i18n
* 🐛 fix: fix plugin not work correct when adding agent from market
* ♻️ refactor: refactor the plugin and chat service and plugins selectors entry
* 🐛 fix: fix plugin not work correct when adding agent from market
* ♻️ refactor: refactor the chat service
* ✅ test: add test for selectors
* ✅ test: add test
* 📝 docs: add selectors for the data store
* 📝 docs: improve Selectors docs
- Add new files related to chat, market, settings, and plugin development
- Modify code in certain files to add functionality and improve performance
- Update URLs and add links to external resources
- Add styles to components for improved appearance
- Update descriptions and improve user experience
This commit introduces new features, updates existing code, and enhances the overall functionality and appearance of the codebase.
- Delete "auto-comments.yml" and add "issue-auto-comments.yml"
- Modify "issue-close-require.yml" to include comments on different issue labels
- Delete "issue-remove-inactive.yml" and "pr-welcome.yml"
These changes improve the GitHub workflows for better issue management.
add Suspense and FullscreenLoading components, modify layoutInitializing key
- Modify onClick event in SessionHeader.tsx
- Change title in Loading component in index.tsx
- Add Suspense and FullscreenLoading components in ResponsiveIndex.tsx and ResponsiveLayout.client.tsx respectively
- Modify layoutInitializing key in common.ts
- Remove "productionBrowserSourceMaps" property
- Make "compress" property dependent on "isProd" variable
- Set "reactStrictMode" property to true
- Modify "images" property to set "unoptimized" based on "isProd" variable
These changes improve the configuration of the Next.js application.
- Add and modify configurations, dependencies, styles, and metadata
- Remove and modify props and styles in AgentCardBanner, AvatarBanner, and Hero components
- Adjust height of elements in the layout
The changes are made to enhance the agent card feature in the market application.
This commit introduces new features such as adding mobile responsiveness, creating a new component, modifying properties, and making API calls. It also includes a base64 encoded image, a random string of characters, and defines constants and functions.
Changes made:
- Added mobile responsiveness to improve user experience on different devices
- Created a new component to enhance functionality
- Modified properties to ensure proper data handling
- Made API calls to retrieve and display dynamic data
- Included a base64 encoded image for visual content
- Defined constants and functions for improved code organization and reusability
- Improves performance by lazy loading components only when needed
- Removes a deleted file and updates layout of certain components
This commit introduces a new feature by using the "dynamic" function from the "next/dynamic" library to dynamically import components. This allows for lazy loading of components, improving performance by only loading them when needed. Additionally, it removes a deleted file and updates the layout of certain components.
This commit introduces new components, modifies display properties, and updates the settings feature. It also includes changes to translations and styling. Additionally, a condition is added to check if the app is a progressive web app before rendering a specific component.
# add a access code to lock your lobe-chat application, you can set a long password to avoid leaking. If this value contains a comma, it is a password array.
# ACCESS_CODE=lobe66
# Specify your API Key selection method, currently supporting `random` and `turn`.
# API_KEY_SELECT_MODE=random
########################################
######## Model Provider Service ########
########################################
### OpenAI ###
# you openai api key
OPENAI_API_KEY=sk-xxxxxxxxx
# use a proxy to connect to the OpenAI API
# OPENAI_PROXY_URL=https://api.openai.com/v1
# add your custom model name, multi model separate by comma. for example gpt-3.5-1106,gpt-4-1106
# OPENAI_MODEL_LIST=gpt-3.5-turbo
### Azure OpenAI ###
# you can learn azure OpenAI Service on https://learn.microsoft.com/en-us/azure/ai-services/openai/overview
# use Azure OpenAI Service by uncomment the following line
# The API key you applied for on the Azure OpenAI account page, which can be found in the "Keys and Endpoints" section.
# AZURE_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# The endpoint you applied for on the Azure OpenAI account page, which can be found in the "Keys and Endpoints" section.
# the format is `plugin-identifier:key1=value1;key2=value2`, multiple settings fields are separated by semicolons `;`, multiple plugin settings are separated by commas `,`.
This issue is closed, If you have any questions, you can comment and reply.\
此问题已经关闭。如果您有任何问题,可以留言并回复。
- name:Auto Comment on Pull Request Opened
uses:wow-actions/auto-comment@v1
with:
GITHUB_TOKEN:${{ secrets.GH_TOKEN}}
pullRequestOpened:|
👍 @{{ author }}
Thank you for raising your pull request and contributing to our Community
Please make sure you have followed our contributing guidelines. We will review it as soon as possible.
If you encounter any problems, please feel free to connect with us.\
非常感谢您提出拉取请求并为我们的社区做出贡献,请确保您已经遵循了我们的贡献指南,我们会尽快审查它。
如果您遇到任何问题,请随时与我们联系。
- name:Auto Comment on Pull Request Merged
uses:actions-cool/pr-welcome@main
if:github.event.pull_request.merged == true
with:
token:${{ secrets.GH_TOKEN }}
comment:|
❤️ Great PR @${{ github.event.pull_request.user.login }} ❤️
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](https://discord.com/invite/AYFPHvv2jT) 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.\
issues:write# for actions-cool/issues-helper to update issues
pull-requests:write# for actions-cool/issues-helper to update PRs
runs-on:ubuntu-latest
steps:
- name:check-inactive
uses:actions-cool/issues-helper@v3
with:
actions:'check-inactive'
token:${{ secrets.GH_TOKEN }}
inactive-label:'Inactive'
inactive-day:60
issue-close-require:
permissions:
issues:write# for actions-cool/issues-helper to update issues
@@ -18,29 +32,35 @@ jobs:
uses:actions-cool/issues-helper@v3
with:
actions:'close-issues'
token:${{ secrets.GH_TOKEN }}
labels:'✅ Fixed'
inactive-day:3
body:|
Since the issue was labeled with `✅ Fixed`, but no response in 3 days. This issue will be closed. If you have any questions, you can comment and reply.
👋 @{{ author }}
<br/>
Since the issue was labeled with `✅ Fixed`, but no response in 3 days. This issue will be closed. If you have any questions, you can comment and reply.\
Since the issue was labeled with `🤔 Need Reproduce`, but no response in 3 days. This issue will be closed. If you have any questions, you can comment and reply.
👋 @{{ author }}
<br/>
Since the issue was labeled with `🤔 Need Reproduce`, but no response in 3 days. This issue will be closed. If you have any questions, you can comment and reply.\
Since the issue was labeled with `🙅🏻♀️ WON'T DO`, and no response in 3 days. This issue will be closed. If you have any questions, you can comment and reply.
👋 @{{ github.event.issue.user.login }}
<br/>
Since the issue was labeled with `🙅🏻♀️ WON'T DO`, and no response in 3 days. This issue will be closed. If you have any questions, you can comment and reply.\
target_repo_token:${{ secrets.GITHUB_TOKEN }}# automatically generated, no need to set
# Set test_mode true to run tests instead of the true action!!
test_mode:false
# Step 3: run check
- name:Sync check
if:failure()
uses:actions-cool/issues-helper@v3
with:
actions:'create-issue'
token:${{ secrets.GITHUB_TOKEN }}
title:'🚨 同步失败 | Sync Fail'
body: '由于 [LobeChat][lobechat] 上游仓库的 workflow 文件变更,导致 GitHub 自动暂停了本次自动更新,你需要手动 Sync Fork 一次,请查看[详细教程][tutorial-zh-CN]\n---\nDue to a change in the workflow file of the [LobeChat][lobechat] upstream repository, GitHub has automatically suspended the scheduled automatic update. You need to manually sync your fork. Please refer to the detailed [Tutorial][tutorial-en-US] for instructions.\n\n[lobechat]: https://github.com/lobehub/lobe-chat\n[tutorial-zh-CN]: https://github.com/lobehub/lobe-chat/wiki/Upstream-Sync.zh-CN\n[tutorial-en-US]:https://github.com/lobehub/lobe-chat/wiki/Upstream-Sync.zh-CN'
labels:'🚨 Sync Fail'
body:|
Due to a change in the workflow file of the [LobeChat][lobechat] upstream repository, GitHub has automatically suspended the scheduled automatic update. You need to manually sync your fork. Please refer to the detailed [Tutorial][tutorial-en-US] for instructions.
We're thrilled that you want to contribute to Lobe Chat, the future of communication! 😄
Lobe Chat is an open-source project, and we welcome your collaboration. Before you jump in, let's make sure you're all set to contribute effectively and have loads of fun along the way!
## Table of Contents
- [Fork the Repository](#fork-the-repository)
- [Clone Your Fork](#clone-your-fork)
- [Create a New Branch](#create-a-new-branch)
- [Code Like a Wizard](#code-like-a-wizard)
- [Committing Your Work](#committing-your-work)
- [Sync with Upstream](#sync-with-upstream)
- [Open a Pull Request](#open-a-pull-request)
- [Review and Collaboration](#review-and-collaboration)
- [Celebrate 🎉](#celebrate-)
## Fork the Repository
🍴 Fork this repository to your GitHub account by clicking the "Fork" button at the top right. This creates a personal copy of the project you can work on.
## Clone Your Fork
📦 Clone your forked repository to your local machine using the `git clone` command:
🌿 Create a new branch for your contribution. This helps keep your work organized and separate from the main codebase.
```bash
git checkout -b your-branch-name
```
Choose a meaningful branch name related to your work. It makes collaboration easier!
## Code Like a Wizard
🧙♀️ Time to work your magic! Write your code, fix bugs, or add new features. Be sure to follow our project's coding style. You can check if your code adheres to our style using:
```bash
pnpm lint
```
This adds a bit of enchantment to your coding experience! ✨
## Committing Your Work
📝 Ready to save your progress? Commit your changes to your branch.
```bash
git add .
git commit -m "Your meaningful commit message"
```
Please keep your commits focused and clear. And remember to be kind to your fellow contributors; keep your commits concise.
## Sync with Upstream
⚙️ Periodically, sync your forked repository with the original (upstream) repository to stay up-to-date with the latest changes.
This ensures you're working on the most current version of Lobe Chat. Stay fresh! 💨
## Open a Pull Request
🚀 Time to share your contribution! Head over to the original Lobe Chat repository and open a Pull Request (PR). Our maintainers will review your work.
## Review and Collaboration
👓 Your PR will undergo thorough review and testing. The maintainers will provide feedback, and you can collaborate to make your contribution even better. We value teamwork!
## Celebrate 🎉
🎈 Congratulations! Your contribution is now part of Lobe Chat. 🥳
Thank you for making Lobe Chat even more magical. We can't wait to see what you create! 🌠
An open-source, modern-design ChatGPT/LLMs UI/Framework.<br/>
Supports speech-synthesis, multi-modal, and extensible ([function call][docs-functionc-call]) plugin system.<br/>
One-click **FREE** deployment of your private OpenAI ChatGPT/Claude/Gemini/Groq/Ollama chat application.
LobeChat is a open-source, extensible ([Function Calling][fc-link]), high-performance chatbot framework. <br/> It supports one-click free deployment of your private ChatGPT/LLM web application.
- [`5` Text to Image Generation](#5-text-to-image-generation)
- [`6` Plugin System (Function Calling)](#6-plugin-system-function-calling)
- [`7` Agent Market (GPTs)](#7-agent-market-gpts)
- [`8` Progressive Web App (PWA)](#8-progressive-web-app-pwa)
- [`9` Mobile Device Adaptation](#9-mobile-device-adaptation)
- [`10` Custom Themes](#10-custom-themes)
- [`*` What's more](#-whats-more)
- [⚡️ Performance](#️-performance)
- [🛳 Self Hosting](#-self-hosting)
- [Keep Updated](#keep-updated)
- [`A` Deploying with Vercel, Zeabur or Sealos](#a-deploying-with-vercel-zeabur-or-sealos)
- [`B` Deploying with Docker](#b-deploying-with-docker)
- [Environment Variable](#environment-variable)
- [📦 Ecosystem](#-ecosystem)
- [🧩 Plugins](#-plugins)
- [⌨️ Local Development](#️-local-development)
- [🤝 Contributing](#-contributing)
- [❤️ Sponsor](#️-sponsor)
- [🔗 More Products](#-more-products)
####
@@ -62,18 +83,23 @@ LobeChat is a open-source, extensible ([Function Calling][fc-link]), high-perfor
## 👋🏻 Getting Started & Join Our Community
Please be aware that LobeChat is currently under active development,feedback is welcome for any [issues][issues-link] encountered.
We are a group of e/acc design-engineers, hoping to provide modern design components and tools for AIGC.
By adopting the Bootstrapping approach, we aim to provide developers and users with a more open, transparent, and user-friendly product ecosystem.
Whether for users or professional developers, LobeHub will be your AI Agent playground. Please be aware that LobeChat is currently under active development, and feedback is welcome for any [issues][issues-link] encountered.
| [![][vercel-shield-badge]][vercel-link] | No installation or registration necessary! Visit our website to experience it firsthand. |
| [![][discord-shield-badge]][discord-link] | Join our Discord community! This is where you can connect with developers and other enthusiastic users of LobeHub. |
> **Important**\
>**Star Us**,You will receive all releases notifications from GitHub without any delay \~ ⭐️
> \[!IMPORTANT]
>
> **Star Us**, You will receive all release notifications from GitHub without any delay \~ ⭐️
@@ -82,16 +108,251 @@ Please be aware that LobeChat is currently under active development,feedback i
## ✨ Features
- [x] 💨 **Quick Deployment**: Using the Vercel platform, you can deploy with just one click and complete the process within 1 minute, without any complex configuration;
- [x] 💎 **Exquisite UI Design**: With a carefully designed interface, it offers an elegant appearance and smooth interaction. It supports light and dark themes and is mobile-friendly. PWA support provides a more native-like experience;
- [x] 🗣️ **Smooth Conversation Experience**: Fluid responses ensure a smooth conversation experience. It fully supports Markdown rendering, including code highlighting, LaTex formulas, Mermaid flowcharts, and more;
- [x] 🧩 **Plugin Support & Custom Plugin Development**: Conversations are extendable with plugins. Users can install and use various plugins, such as search engines, web extraction, etc. It also supports the development of custom plugins to meet custom needs;
- [x] 🔒 **Privacy Protection**: All data is stored locally in the user's browser, ensuring user privacy;
- [x] 🤖 **Customizable Agent Roles**: Users can create, share, and debug personalized dialogue agent roles according to their needs, providing more flexible and personalized dialogue functions;
- [x] 🌐 **Custom Domain**: If users have their own domain, they can bind it to the platform for quick access to the dialogue agent from anywhere.
- [x] 🏬 **Role Market**: A Role Market is provided where users can select their preferred dialogue agent roles, enriching the content and style of the dialogue;
[![][image-feat-privoder]][docs-feat-provider]
> **Note**\
### `1` [Multi-Model Service Provider Support][docs-feat-provider]
In the continuous development of LobeChat, we deeply understand the importance of diversity in model service providers for meeting the needs of the community when providing AI conversation services. Therefore, we have expanded our support to multiple model service providers, rather than being limited to a single one, in order to offer users a more diverse and rich selection of conversations.
In this way, LobeChat can more flexibly adapt to the needs of different users, while also providing developers with a wider range of choices.
#### Supported Model Service Providers
We have implemented support for the following model service providers:
- **AWS Bedrock**: Integrated with AWS Bedrock service, supporting models such as **Claude / LLama2**, providing powerful natural language processing capabilities. [Learn more](https://aws.amazon.com/cn/bedrock)
- **Anthropic (Claude)**: Accessed Anthropic's **Claude** series models, including Claude 3 and Claude 2, with breakthroughs in multi-modal capabilities and extended context, setting a new industry benchmark. [Learn more](https://www.anthropic.com/claude)
- **Google AI (Gemini Pro, Gemini Vision)**: Access to Google's **Gemini** series models, including Gemini and Gemini Pro, to support advanced language understanding and generation. [Learn more](https://deepmind.google/technologies/gemini/)
- **Groq**: Accessed Groq's AI models, efficiently processing message sequences and generating responses, capable of multi-turn dialogues and single-interaction tasks. [Learn more](https://groq.com/)
- **OpenRouter**: Supports routing of models including **Claude 3**, **Gemma**, **Mistral**, **Llama2** and **Cohere**, with intelligent routing optimization to improve usage efficiency, open and flexible. [Learn more](https://openrouter.ai/)
- **01.AI (Yi Model)**: Integrated the 01.AI models, with series of APIs featuring fast inference speed, which not only shortened the processing time, but also maintained excellent model performance. [Learn more](https://01.ai/)
- **Together.ai**: Over 100 leading open-source Chat, Language, Image, Code, and Embedding models are available through the Together Inference API. For these models you pay just for what you use. [Learn more](https://www.together.ai/)
- **ChatGLM**: Added the **ChatGLM** series models from Zhipuai (GLM-4/GLM-4-vision/GLM-3-turbo), providing users with another efficient conversation model choice. [Learn more](https://www.zhipuai.cn/)
- **Moonshot AI (Dark Side of the Moon)**: Integrated with the Moonshot series models, an innovative AI startup from China, aiming to provide deeper conversation understanding. [Learn more](https://www.moonshot.cn/)
- **Minimax**: Integrated the Minimax models, including the MoE model **abab6**, offers a broader range of choices. [Learn more](https://www.minimaxi.com/)
At the same time, we are also planning to support more model service providers, such as Replicate and Perplexity, to further enrich our service provider library. If you would like LobeChat to support your favorite service provider, feel free to join our [community discussion](https://github.com/lobehub/lobe-chat/discussions/1284).
<div align="right">
[![][back-to-top]](#readme-top)
</div>
[![][image-feat-local]][docs-feat-local]
### `2` [Local Large Language Model (LLM) Support][docs-feat-local]
To meet the specific needs of users, LobeChat also supports the use of local models based on [Ollama](https://ollama.ai), allowing users to flexibly use their own or third-party models.
> \[!TIP]
>
> Learn more about [📘 Using Ollama in LobeChat][docs-usage-ollama] by checking it out.
LobeChat now supports OpenAI's latest [`gpt-4-vision`](https://platform.openai.com/docs/guides/vision) model with visual recognition capabilities,
a multimodal intelligence that can perceive visuals. Users can easily upload or drag and drop images into the dialogue box,
and the agent will be able to recognize the content of the images and engage in intelligent conversation based on this,
creating smarter and more diversified chat scenarios.
This feature opens up new interactive methods, allowing communication to transcend text and include a wealth of visual elements.
Whether it's sharing images in daily use or interpreting images within specific industries, the agent provides an outstanding conversational experience.
LobeChat supports Text-to-Speech (TTS) and Speech-to-Text (STT) technologies, enabling our application to convert text messages into clear voice outputs,
allowing users to interact with our conversational agent as if they were talking to a real person. Users can choose from a variety of voices to pair with the agent.
Moreover, TTS offers an excellent solution for those who prefer auditory learning or desire to receive information while busy.
In LobeChat, we have meticulously selected a range of high-quality voice options (OpenAI Audio, Microsoft Edge Speech) to meet the needs of users from different regions and cultural backgrounds.
Users can choose the voice that suits their personal preferences or specific scenarios, resulting in a personalized communication experience.
<div align="right">
[![][back-to-top]](#readme-top)
</div>
[![][image-feat-t2i]][docs-feat-t2i]
### `5` [Text to Image Generation][docs-feat-t2i]
With support for the latest text-to-image generation technology, LobeChat now allows users to invoke image creation tools directly within conversations with the agent. By leveraging the capabilities of AI tools such as [`DALL-E 3`](https://openai.com/dall-e-3), [`MidJourney`](https://www.midjourney.com/), and [`Pollinations`](https://pollinations.ai/), the agents are now equipped to transform your ideas into images.
This enables a more private and immersive creative process, allowing for the seamless integration of visual storytelling into your personal dialogue with the agent.
<div align="right">
[![][back-to-top]](#readme-top)
</div>
[![][image-feat-plugin]][docs-feat-plugin]
### `6` [Plugin System (Function Calling)][docs-feat-plugin]
The plugin ecosystem of LobeChat is an important extension of its core functionality, greatly enhancing the practicality and flexibility of the LobeChat assistant.
By utilizing plugins, LobeChat assistants can obtain and process real-time information, such as searching for web information and providing users with instant and relevant news.
In addition, these plugins are not limited to news aggregation, but can also extend to other practical functions, such as quickly searching documents, generating images, obtaining data from various platforms like Bilibili, Steam, and interacting with various third-party services.
> \[!TIP]
>
> Learn more about [📘 Plugin Usage][docs-usage-plugin] by checking it out.
| [Social Search](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **say-apps** on **2024-05-02**</sup> | The Social Search provides access to tweets, users, followers, images, media and more.<br/>`social``twitter``x``search` |
| [Search Google via Serper](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **Barry** on **2024-04-30**</sup> | Google search engine via Serper.dev free API (2500x🆓/month)<br/>`web``search` |
| [NFT Guru](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **swap** on **2024-04-03**</sup> | Discover current prices of NFTs across major platforms and keep track of the rapidly changing marketplace with real-time<br/>`crypto``nft` |
| [Calendar Assistant](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **cc** on **2024-03-13**</sup> | A plugin to manage your calendar events # will auto generate i18n in workflow<br/>`calendar``schedule``will-auto-generate-i-18-n-in-workflow` |
> 📊 Total plugins: [<kbd>**56**</kbd>](https://github.com/lobehub/lobe-chat-plugins)
<!-- PLUGIN LIST -->
<div align="right">
[![][back-to-top]](#readme-top)
</div>
[![][image-feat-agent]][docs-feat-agent]
### `7` [Agent Market (GPTs)][docs-feat-agent]
In LobeChat Agent Marketplace, creators can discover a vibrant and innovative community that brings together a multitude of well-designed agents,
which not only play an important role in work scenarios but also offer great convenience in learning processes.
Our marketplace is not just a showcase platform but also a collaborative space. Here, everyone can contribute their wisdom and share the agents they have developed.
> \[!TIP]
>
> By [🤖/🏪 Submit Agents][submit-agents-link], you can easily submit your agent creations to our platform.
> Importantly, LobeChat has established a sophisticated automated internationalization (i18n) workflow,
> capable of seamlessly translating your agent into multiple language versions.
> This means that no matter what language your users speak, they can experience your agent without barriers.
> \[!IMPORTANT]
>
> We welcome all users to join this growing ecosystem and participate in the iteration and optimization of agents.
> Together, we can create more interesting, practical, and innovative agents, further enriching the diversity and practicality of the agent offerings.
| [Sales Description Specialist](https://chat-preview.lobehub.com/market?agent=verkauf-kleinanzeigen)<br/><sup>By **[highseen](https://github.com/highseen)** on **2024-04-30**</sup> | Assists in the sale of used items through research, pricing, description, and title creation.<br/>`product-sales``research``description` |
| [Jailbreak Assistant DAN](https://chat-preview.lobehub.com/market?agent=gpt-4-dan-assistant)<br/><sup>By **[MapleEve](https://github.com/MapleEve)** on **2024-04-26**</sup> | Bypass OpenAI review mechanism, ChatGPT after jailbreak<br/>`creative``artificial-intelligence``conversation``jailbreak` |
| [TailwindHelper](https://chat-preview.lobehub.com/market?agent=tailwind-helper)<br/><sup>By **[aototo](https://github.com/aototo)** on **2024-04-26**</sup> | TailwindHelper is a professional frontend designer with a solid foundation in design theory and rich practical experience. Created by a leading software development company, it aims to help developers and designers accelerate the development process of web interfaces. TailwindHelper is proficient in the Tailwind CSS framework and can translate complex design requirements into efficient and responsive CSS class names.<br/>`tailwindcss``css``tailwind-helper` |
| [yapi JSON-SCHEMA to Typescript](https://chat-preview.lobehub.com/market?agent=yapi-ts-helper)<br/><sup>By **[zcf0508](https://github.com/zcf0508)** on **2024-04-26**</sup> | Specializes in converting JSON schema to TypeScript types.<br/>`typescript``development` |
> 📊 Total agents: [<kbd>**244**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
<!-- AGENT LIST -->
<div align="right">
[![][back-to-top]](#readme-top)
</div>
[![][image-feat-pwa]][docs-feat-pwa]
### `8` [Progressive Web App (PWA)][docs-feat-pwa]
We deeply understand the importance of providing a seamless experience for users in today's multi-device environment.
Therefore, we have adopted Progressive Web Application ([PWA](https://support.google.com/chrome/answer/9658361)) technology,
a modern web technology that elevates web applications to an experience close to that of native apps.
Through PWA, LobeChat can offer a highly optimized user experience on both desktop and mobile devices while maintaining its lightweight and high-performance characteristics.
Visually and in terms of feel, we have also meticulously designed the interface to ensure it is indistinguishable from native apps,
providing smooth animations, responsive layouts, and adapting to different device screen resolutions.
> \[!NOTE]
>
> If you are unfamiliar with the installation process of PWA, you can add LobeChat as your desktop application (also applicable to mobile devices) by following these steps:
>
> - Launch the Chrome or Edge browser on your computer.
> - Visit the LobeChat webpage.
> - In the upper right corner of the address bar, click on the <kbd>Install</kbd> icon.
> - Follow the instructions on the screen to complete the PWA Installation.
We have carried out a series of optimization designs for mobile devices to enhance the user's mobile experience. Currently, we are iterating on the mobile user experience to achieve smoother and more intuitive interactions. If you have any suggestions or ideas, we welcome you to provide feedback through GitHub Issues or Pull Requests.
<div align="right">
[![][back-to-top]](#readme-top)
</div>
[![][image-feat-theme]][docs-feat-theme]
### `10` [Custom Themes][docs-feat-theme]
As a design-engineering-oriented application, LobeChat places great emphasis on users' personalized experiences,
hence introducing flexible and diverse theme modes, including a light mode for daytime and a dark mode for nighttime.
Beyond switching theme modes, a range of color customization options allow users to adjust the application's theme colors according to their preferences.
Whether it's a desire for a sober dark blue, a lively peach pink, or a professional gray-white, users can find their style of color choices in LobeChat.
> \[!TIP]
>
> The default configuration can intelligently recognize the user's system color mode and automatically switch themes to ensure a consistent visual experience with the operating system.
> For users who like to manually control details, LobeChat also offers intuitive setting options and a choice between chat bubble mode and document mode for conversation scenarios.
<div align="right">
[![][back-to-top]](#readme-top)
</div>
### `*` What's more
Beside these features, LobeChat also have much better basic technique underground:
- [x] 💨 **Quick Deployment**: Using the Vercel platform or docker image, you can deploy with just one click and complete the process within 1 minute without any complex configuration.
- [x] 🌐 **Custom Domain**: If users have their own domain, they can bind it to the platform for quick access to the dialogue agent from anywhere.
- [x] 🔒 **Privacy Protection**: All data is stored locally in the user's browser, ensuring user privacy.
- [x] 💎 **Exquisite UI Design**: With a carefully designed interface, it offers an elegant appearance and smooth interaction. It supports light and dark themes and is mobile-friendly. PWA support provides a more native-like experience.
- [x] 🗣️ **Smooth Conversation Experience**: Fluid responses ensure a smooth conversation experience. It fully supports Markdown rendering, including code highlighting, LaTex formulas, Mermaid flowcharts, and more.
> ✨ more features will be added when LobeChat evolve.
---
> \[!NOTE]
>
> You can find our upcoming [Roadmap][github-project-link] plans in the Projects section.
<div align="right">
@@ -100,53 +361,16 @@ Please be aware that LobeChat is currently under active development,feedback i
By building a powerful plugin ecosystem, ChatGPT not only can provide real-time news updates, but it can also assist you in easily querying documents and accessing various e-commerce data. This allows ChatGPT to play a key role in a wider range of fields. If you are interested in writing plugins, we provide detailed component development documentation, SDKs, and template files in the [🧩 Plugin System](#-Plugin-System) section below. Let's work together to make ChatGPT more powerful and easier to use.
In our agent market, we have accumulated a large number of practical prompt agents that have been used in daily work and study. You can also share your agents here and iterate and optimize your prompt agents with more people. You can submit your agents through [🤖/🏪 Submit Agents][submit-agents-link], and our automated i18n workflow will automatically translate your agents into multiple languages, allowing users around the world to enjoy your wisdom.
Utilize the Progressive Web Application ([PWA](https://support.google.com/chrome/answer/9658361)) technology to achieve a seamless LobeChat experience on your computer or mobile device.
> **Note**\
> If you are unfamiliar with the installation process of PWA, you can add LobeChat as your desktop application (also applicable to mobile devices) by following these steps:
> \[!NOTE]
>
> - Launch the Chrome or Edge browser on your computer
> - Visit the LobeChat webpage
> - In the upper right corner of the address bar, click on the <kbd>Install</kbd> icon
> - Follow the instructions on the screen to complete the PWA installation
> The complete list of reports can be found in the [📘 Lighthouse Reports][docs-lighthouse]
LobeChat offers two unique theme modes - Light Mode and Dark Mode, as well as rich color customization options to meet your personalized needs. By default, our themes will intelligently switch based on your system settings, but if you prefer manual control, you can easily switch in the settings. <br/>
We have carried out a series of optimization designs for mobile devices to enhance the user's mobile experience. Currently, we are iterating on the mobile user experience to achieve smoother and more intuitive interactions. If you have any suggestions or ideas, we welcome you to provide feedback through GitHub Issues or Pull Requests.
> 🚧 Additional snapshots and demonstrations are being progressively added...
@@ -156,31 +380,92 @@ We have carried out a series of optimization designs for mobile devices to enhan
## 🛳 Self Hosting
LobeChat provides a [self-hosted version][deploy-link] with Vercel. This allows you to build your own chatbot within a few minutes, without any prior knowledge. If you want to deploy this service yourself, you can follow these steps:
LobeChat provides Self-Hosted Version with Vercel and [Docker Image][docker-release-link]. This allows you to deploy your own chatbot within a few minutes without any prior knowledge.
> \[!TIP]
>
> Learn more about [📘 Build your own LobeChat][docs-self-hosting] by checking it out.
### `A` Deploying with Vercel, Zeabur or Sealos
If you want to deploy this service yourself on either Vercel or Zeabur, you can follow these steps:
- Prepare your [OpenAI API Key](https://platform.openai.com/account/api-keys).
- Click the button below to start deployment: Deploy with Vercel. Log in directly with your GitHub account and remember to fill in the API Key and access code CODE on the environment variable page;
- After deployment, you can start using it;
- Bind a custom domain (optional): The DNS of the domain assigned by Vercel is polluted in some areas, binding a custom domain can connect directly.
- Click the button below to start deployment: Log in directly with your GitHub account, and remember to fill in the `OPENAI_API_KEY`(required) and `ACCESS_CODE` (recommended) on the environment variable section.
- After deployment, you can start using it.
- Bind a custom domain (optional): The DNS of the domain assigned by Vercel is polluted in some areas; binding a custom domain can connect directly.
<div align="center">
[![][deploy-button-image]][deploy-link]
| Deploy with Vercel | Deploy with Zeabur | Deploy with Sealos |
> This project provides some additional configuration items, set with environment variables, The complete list of environment variables can be found in the [📘 Environment Variables](https://github.com/lobehub/lobe-chat/wiki/Environment-Variable) :
#### After Fork
| Environment Variable | Required | Description | Example |
| `OPENAI_API_KEY` | Yes | This is the API key you apply on the OpenAI account page | `sk-xxxxxx...xxxxxx` |
| `OPENAI_PROXY_URL` | No | If you manually configure the OpenAI interface proxy, you can use this configuration item to override the default OpenAI API request base URL | `https://api.chatanywhere.cn`<br/>The default value is<br/>`https://api.openai.com` |
| `ACCESS_CODE` | No | Add a password to access this service, the password should be a 6-digit number or letter | `awCT74` or `e3@09!` |
After fork, only retain the upstream sync action and disable other actions in your repository on GitHub.
### Keep Updated
#### Keep Updated
If you have deployed your own project following the one-click deployment steps in the README, you might encounter constant prompts indicating "updates available". This is because Vercel defaults to creating a new project instead of forking this one, resulting in an inability to accurately detect updates. We suggest you redeploy using the following steps, [📘 Maintaining Updates with LobeChat Self-Deployment](https://github.com/lobehub/lobe-chat/wiki/Upstream-Sync).
If you have deployed your own project following the one-click deployment steps in the README, you might encounter constant prompts indicating "updates available." This is because Vercel defaults to creating a new project instead of forking this one, resulting in an inability to detect updates accurately.
> \[!TIP]
>
> We suggest you redeploy using the following steps, [📘 Auto Sync With Latest][docs-upstream-sync]
<br/>
### `B` Deploying with Docker
[![][docker-release-shield]][docker-release-link]
[![][docker-size-shield]][docker-size-link]
[![][docker-pulls-shield]][docker-pulls-link]
We provide a Docker image for deploying the LobeChat service on your own private device. Use the following command to start the LobeChat service:
```fish
$ docker run -d-p3210:3210\
-eOPENAI_API_KEY=sk-xxxx \
-eACCESS_CODE=lobe66 \
--name lobe-chat \
lobehub/lobe-chat
```
> \[!TIP]
>
> If you need to use the OpenAI service through a proxy, you can configure the proxy address using the `OPENAI_PROXY_URL` environment variable:
```fish
$ docker run -d-p3210:3210\
-eOPENAI_API_KEY=sk-xxxx \
-eOPENAI_PROXY_URL=https://api-proxy.com/v1 \
-eACCESS_CODE=lobe66 \
--name lobe-chat \
lobehub/lobe-chat
```
> \[!NOTE]
>
> For detailed instructions on deploying with Docker, please refer to the [📘 Docker Deployment Guide][docs-docker]
<br/>
### Environment Variable
This project provides some additional configuration items set with environment variables:
| Environment Variable | Required | Description | Example |
| `OPENAI_API_KEY` | Yes | This is the API key you apply on the OpenAI account page | `sk-xxxxxx...xxxxxx` |
| `OPENAI_PROXY_URL` | No | If you manually configure the OpenAI interface proxy, you can use this configuration item to override the default OpenAI API request base URL | `https://api.chatanywhere.cn` or `https://aihubmix.com/v1` <br/>The default value is<br/>`https://api.openai.com/v1` |
| `ACCESS_CODE` | No | Add a password to access this service; you can set a long password to avoid leaking. If this value contains a comma, it is a password array. | `awCTe)re_r74` or `rtrt_ewee3@09!` or `code1,code2,code3` |
| `OPENAI_MODEL_LIST` | No | Used to control the model list. Use `+` to add a model, `-` to hide a model, and `model_name=display_name` to customize the display name of a model, separated by commas. | `qwen-7b-chat,+glm-6b,-gpt-3.5-turbo` |
> \[!NOTE]
>
> The complete list of environment variables can be found in the [📘 Environment Variables][docs-env-var]
<div align="right">
@@ -190,11 +475,12 @@ If you have deployed your own project following the one-click deployment steps i
| [@lobehub/ui][lobe-ui-link] | [lobehub/lobe-ui][lobe-ui-github] | Lobe UI is an open-source UI component library dedicated to building AIGC web applications. | [![][lobe-ui-shield]][lobe-ui-link] |
| [@lobehub/lint][lobe-lint-link] | [lobehub/lobe-lint][lobe-lint-github] | LobeLint provides configurations for ESlint, Stylelint, Commitlint, Prettier, Remark, and Semantic Release for LobeHub. | [![][lobe-lint-shield]][lobe-lint-link] |
| @lobehub/assets | [lobehub/assets][lobe-assets-github] | Logo assets, favicons, webfonts for LobeHub. | |
| [@lobehub/ui][lobe-ui-link] | [lobehub/lobe-ui][lobe-ui-github] | Open-source UI component library dedicated to building AIGC web applications. | [![][lobe-ui-shield]][lobe-ui-link] |
| [@lobehub/icons][lobe-icons-link] | [lobehub/lobe-icons][lobe-icons-github] | Popular AI / LLM Model Brand SVG Logo and Icon Collection. | [![][lobe-icons-shield]][lobe-icons-link] |
| [@lobehub/lint][lobe-lint-link] | [lobehub/lobe-lint][lobe-lint-github] | Configurations for ESlint, Stylelint, Commitlint, Prettier, Remark, and Semantic Release for LobeHub. | [![][lobe-lint-shield]][lobe-lint-link] |
<div align="right">
@@ -204,25 +490,20 @@ If you have deployed your own project following the one-click deployment steps i
## 🧩 Plugins
Plugins provide a means to extend the [Function Calling][fc-link] capabilities of LobeChat. They can be used to introduce new function calls, and even new ways to render message results. If you are interested in plugin development, please refer to our [📘 Plugin Development Guide](https://github.com/lobehub/lobe-chat/wiki/Plugin-Development) in the Wiki.
Plugins provide a means to extend the [Function Calling][docs-functionc-call] capabilities of LobeChat. They can be used to introduce new function calls and even new ways to render message results. If you are interested in plugin development, please refer to our [📘 Plugin Development Guide][docs-plugin-dev] in the Wiki.
- [lobe-chat-plugins][lobe-chat-plugins]: This is the plugin index for LobeChat. It accesses index.json from this repository to display a list of available plugins for LobeChat to the user.
- [chat-plugin-template][chat-plugin-template]: This is the plugin template for LobeChat plugin development.
- [@lobehub/chat-plugin-sdk][chat-plugin-sdk]: The LobeChat Plugin SDK assists you in creating exceptional chat plugins for Lobe Chat.
- [@lobehub/chat-plugins-gateway][chat-plugins-gateway]: The LobeChat Plugins Gateway is a backend service that serves as a gateway for LobeChat plugins. We deploy this service using Vercel. The primary API POST /api/v1/runner is deployed as an Edge Function.
- [@lobehub/chat-plugins-gateway][chat-plugins-gateway]: The LobeChat Plugins Gateway is a backend service that provides a gateway for LobeChat plugins. We deploy this service using Vercel. The primary API POST /api/v1/runner is deployed as an Edge Function.
> **Note**\
> \[!NOTE]
>
> The plugin system is currently undergoing major development. You can learn more in the following issues:
>
> - [x] [**Plugin Phase 1**](https://github.com/lobehub/lobe-chat/issues/73): Implement separation of the plugin from the main body, split the plugin into an independent repository for maintenance, and realize dynamic loading of the plugin.
> - [x] [**Plugin Phase 2**](https://github.com/lobehub/lobe-chat/issues/97): The security and stability of the plugin's use, more accurately presenting abnormal states, the maintainability of the plugin architecture and developer-friendly.
> - [] [**Plugin Phase 3**](https://github.com/lobehub/lobe-chat/issues/149): Higher-level and more comprehensive customization capabilities, support for plugin authentication and examples.
| [SearchEngine][chat-plugin-search-engine] | This plugin allows for the use of the SerpApi search engine. |
| [RealtimeWeather][chat-plugin-realtime-weather] | This plugin provides practical weather information by obtaining real-time weather data and can automatically update based on the user's location. |
| [WebsiteCrawler][chat-plugin-web-crawler] | This plugin automatically crawls the main content of a specified URL webpage and uses it as context input. |
> - [x] [**Plugin Phase 2**](https://github.com/lobehub/lobe-chat/issues/97): The security and stability of the plugin's use, more accurately presenting abnormal states, the maintainability of the plugin architecture, and developer-friendly.
> - [x] [**Plugin Phase 3**](https://github.com/lobehub/lobe-chat/issues/149): Higher-level and more comprehensive customization capabilities, support for plugin authentication, and examples.
<div align="right">
@@ -238,15 +519,15 @@ You can use GitHub Codespaces for online development:
If you would like to learn more details, please feel free to look at our [📘 Development Guide][docs-dev-guide].
<div align="right">
[![][back-to-top]](#readme-top)
@@ -255,13 +536,68 @@ $ bun dev
## 🤝 Contributing
Contributions of all types are more than welcome, if you are interested in contributing code, feel free to check out our GitHub [Issues][github-issues-link] and [Projects][github-project-link] to get stuck in to show us what you’re made of.
Contributions of all types are more than welcome; if you are interested in contributing code, feel free to check out our GitHub [Issues][github-issues-link] and [Projects][github-project-link] to get stuck in to show us what you’re made of.
> \[!TIP]
>
> We are creating a technology-driven forum, fostering knowledge interaction and the exchange of ideas that may culminate in mutual inspiration and collaborative innovation.
>
> Help us make LobeChat better. Welcome to provide product design feedback, user experience discussions directly to us.
Every bit counts and your one-time donation sparkles in our galaxy of support! You're a shooting star, making a swift and bright impact on our journey. Thank you for believing in us – your generosity guides us toward our mission, one brilliant flash at a time.
@@ -271,9 +607,10 @@ Contributions of all types are more than welcome, if you are interested in contr
## 🔗 More Products
- **[🤯 Lobe Theme][lobe-theme]:** The modern theme for stable diffusion webui, exquisite interface design, highly customizable UI, and efficiencyboosting features.
- **[🅰️ Lobe SD Theme][lobe-theme]:** Modern theme for Stable Diffusion WebUI, exquisite interface design, highly customizable UI, and efficiency-boosting features.
- **[⛵️ Lobe Midjourney WebUI][lobe-midjourney-webui]:** WebUI for Midjourney, leverages AI to quickly generate a wide array of rich and diverse images from text prompts, sparking creativity and enhancing conversations.
- **[🌏 Lobe i18n][lobe-i18n] :** Lobe i18n is an automation tool for the i18n (internationalization) translation process, powered by ChatGPT. It supports features such as automatic splitting of large files, incremental updates, and customization options for the OpenAI model, API proxy, and temperature.
- **[💌 Lobe Commit][lobe-commit]:** Lobe Commit is a CLI tool that leverages Langchain/ChatGPT to generate Gitmoji-based commit messages.
- **[💌 Lobe Commit][lobe-commit]:** Lobe Commit is a CLI tool that leverages Langchain/ChatGPT to generate Gitmoji-based commit messages.
<div align="right">
@@ -289,30 +626,59 @@ Contributions of all types are more than welcome, if you are interested in contr
LobeChat uses [Auth.js v5](https://authjs.dev/) as the external authentication service. Auth.js is an open-source authentication library that provides a simple way to implement authentication and authorization features. This document will introduce how to use Auth.js to implement a new authentication provider.
### TOC
- [Add New Authentication Provider](#add-new-authentication-provider)
- [Pre-requisites: Check the Official Provider List](#pre-requisites-check-the-official-provider-list)
- [Step 4: Configure the Environment Variables](#step-4-configure-the-environment-variables)
- [Step 5: Modify server-side user information processing logic](#step-5-modify-server-side-user-information-processing-logic)
## Add New Authentication Provider
To add a new authentication provider in LobeChat (for example, adding Okta), you need to follow the steps below:
### Pre-requisites: Check the Official Provider List
First, you need to check the [Auth.js Provider List](https://authjs.dev/reference/core/providers) to see if your provider is already supported. If yes, you can directly use the SDK provided by Auth.js to implement the authentication feature.
Next, I will use [Okta](https://authjs.dev/reference/core/providers/okta) as an example to introduce how to add a new authentication provider.
### Step 1: Add Authenticator Core Code
Open the `src/app/api/auth/next-auth.ts` file and import `next-auth/providers/okta`.
Modify the `signIn` function parameter in `src/Features/Conversation/Error/OAuthForm.tsx` and \`src/app/settings/common/Common.tsx
The default is `auth0`, which you can change to `okta` to switch to the Okta provider, or remove this parameter to support all added authentication services
This value is the id of the Auth.js provider, and you can read the source code of the corresponding `next-auth/providers` module to read the default ID.
### Step 4: Configure the Environment Variables
Add `OKTA_CLIENT_ID`、`OKTA_CLIENT_SECRET`、`OKTA_ISSUER` environment variables when you deploy.
### Step 5: Modify server-side user information processing logic
#### Get user information in the frontend
Use the `useOAuthSession()` method in the frontend page to get the user information `user` returned by the backend:
The default type of `user` is `User`, and the type definition is:
```ts
interfaceUser{
id?: string;
name?: string|null;
email?: string|null;
image?: string|null;
}
```
#### Modify user `id` handling logic
The `user.id` is used to identify users. When introducing a new OAuth identity provider, you need to handle the information carried in the OAuth callback in `src/app/api/auth/next-auth.ts`. You need to select the user's `id` from this information. Before that, we need to understand the data processing sequence of `Auth.js`:
```txt
authorize --> jwt --> session
```
By default, in the `jwt --> session` process, `Auth.js` will [automatically assign the user `id` to `account.providerAccountId` based on the login type](https://authjs.dev/reference/core/types#provideraccountid). If you need to select a different value as the user `id`, you need to implement the following handling logic:
```ts
callbacks:{
asyncjwt({token,account,profile}){
if(account){
// You can select a different value from `account` or `profile`
token.userId=account.providerAccountId;
}
returntoken;
},
},
```
#### Customize `session` return
If you want to carry more information about `profile` and `account` in the `session`, according to the data processing order mentioned above in `Auth.js`, you must first copy this information to the `token`. For example, add the user avatar URL `profile.picture` to the `session`:
Then supplement the type definition for the new parameters:
```ts
declaremodule'@auth/core/jwt'{
interfaceJWT{
// ...
avatar?: string;
}
}
declaremodule'next-auth'{
interfaceUser{
avatar?: string;
}
}
```
> [More built-in type extensions in Auth.js](https://authjs.dev/getting-started/typescript#module-augmentation)
#### Differentiate multiple authentication providers in the processing logic
If you have configured multiple authentication providers and their `userId` mappings are different, you can use the `account.provider` parameter in the `jwt` method to get the default id of the identity provider and enter different processing logic.
LobeChat is an AI conversation application built on the Next.js framework, aiming to provide an AI productivity platform that enables users to interact with AI through natural language. The following is an overview of the architecture design of LobeChat:
- [Security and Performance Optimization](#security-and-performance-optimization)
- [Development and Deployment Process](#development-and-deployment-process)
## Application Architecture Overview
The overall architecture of LobeChat consists of the frontend, EdgeRuntime API, Agents Market, Plugin Market, and independent plugins. These components collaborate to provide a complete AI experience.
## Frontend Architecture
The frontend of LobeChat adopts the Next.js framework, leveraging its powerful server-side rendering (SSR) capability and routing functionality. The frontend utilizes a stack of technologies, including the antd component library, lobe-ui AIGC component library, zustand state management, swr request library, i18next internationalization library, and more. These technologies collectively support the functionality and features of LobeChat.
The components in the frontend architecture include app, components, config, const, features, helpers, hooks, layout, locales, migrations, prompts, services, store, styles, types, and utils. Each component has specific responsibilities and collaborates with others to achieve different functionalities.
## Edge Runtime API
The Edge Runtime API is one of the core components of LobeChat, responsible for handling the core logic of AI conversations. It provides interaction interfaces with the AI engine, including natural language processing, intent recognition, and response generation. The EdgeRuntime API communicates with the frontend, receiving user input and returning corresponding responses.
## Agents Market
The Agents Market is a crucial part of LobeChat, providing various AI agents for different scenarios to handle specific tasks and domains. The Agents Market also offers functionality for discovering and uploading agents, allowing users to find agents created by others and easily share their own agents in the market.
## Plugin Market
The Plugin Market is another key component of LobeChat, offering various plugins to extend the functionality and features of LobeChat. Plugins can be independent functional modules or integrated with agents from the Agents Market. During conversations, the assistant automatically identifies user input, recognizes suitable plugins, and passes them to the corresponding plugins for processing and returns the results.
## Security and Performance Optimization
LobeChat's security strategy includes authentication and permission management. Users need to authenticate before using LobeChat, and operations are restricted based on the user's permissions.
To optimize performance, LobeChat utilizes Next.js SSR functionality to achieve fast page loading and response times. Additionally, a series of performance optimization measures are implemented, including code splitting, caching, and resource compression.
## Development and Deployment Process
LobeChat's development process includes version control, testing, continuous integration, and continuous deployment. The development team uses version control systems for code management and conducts unit and integration testing to ensure code quality. Continuous integration and deployment processes ensure rapid delivery and deployment of code.
The above is a brief introduction to the architecture design of LobeChat, detailing the responsibilities and collaboration of each component, as well as the impact of design decisions on application functionality and performance.
The implementation of LobeChat's large model AI mainly relies on OpenAI's API, including the core conversation API on the backend and the integrated API on the frontend. Next, we will introduce the implementation approach and code for the backend and frontend separately.
- [Using Streaming to Get Results](#using-streaming-to-get-results)
## Backend Implementation
The following code removes authentication, error handling, and other logic, retaining only the core functionality logic.
### Core Conversation API
In the file `src/app/api/openai/chat/handler.ts`, we define a `POST` method, which first parses the payload data from the request (i.e., the conversation content sent by the client), and then retrieves the authorization information from the request. Then, we create an `openai` object and call the `createChatCompletion` method, which is responsible for sending the conversation request to OpenAI and returning the result.
In the file `src/app/api/openai/chat/createChatCompletion.ts`, we define the `createChatCompletion` method, which first preprocesses the payload data, then calls OpenAI's `chat.completions.create` method to send the request, and uses the `OpenAIStream` from the [Vercel AI SDK](https://sdk.vercel.ai/docs) to convert the returned result into a streaming response.
In the `src/services/chatModel.ts` file, we define the `fetchChatModel` method, which first preprocesses the payload data, then sends a POST request to the `/chat` endpoint on the backend, and returns the request result.
In the `src/utils/fetch.ts` file, we define the `fetchSSE` method, which uses a streaming approach to retrieve data. When a new data chunk is read, it calls the `onMessageHandle` callback function to process the data chunk, achieving a typewriter-like output effect.
The above is the core implementation of the LobeChat session API. With an understanding of these core codes, further expansion and optimization of LobeChat's AI functionality can be achieved.
Welcome to the Code Style and Contribution Guidelines for LobeChat. This guide will help you understand our code standards and contribution process, ensuring code consistency and smooth project progression.
## TOC
- [Code Style](#code-style)
- [ESLint](#eslint)
- [Prettier](#prettier)
- [remarklint](#remarklint)
- [stylelint](#stylelint)
- [Contribution Process](#contribution-process)
- [Gitmoji](#gitmoji)
- [Semantic Release](#semantic-release)
- [Commitlint](#commitlint)
- [How to Contribute](#how-to-contribute)
## Code Style
In LobeChat, we use the `@lobehub/lint` package to maintain a unified code style. This package incorporates configurations for `ESLint`, `Prettier`, `remarklint`, and `stylelint` to ensure that our JavaScript, Markdown, and CSS files adhere to the same coding standards.
### ESLint
We use ESLint to check for issues in our JavaScript code. You can find the `.eslintrc.js` file in the project's root directory, which contains our extensions and custom rules for the ESLint configuration of `@lobehub/lint`.
To ensure your code aligns with the project's standards, run ESLint before committing your code.
### Prettier
Prettier is responsible for code formatting to maintain consistency. Our Prettier configuration can be found in `.prettierrc.js`, imported from `@lobehub/lint`.
It's recommended to configure your editor to run Prettier automatically upon saving files or manually run it before committing.
### remarklint
For Markdown files, we use remarklint to ensure consistent document formatting. You can find the corresponding configuration file in the project.
### stylelint
We utilize stylelint to standardize the style of our CSS code. In the configuration file for stylelint, we have made some custom rule adjustments based on `@lobehub/lint` configuration.
Ensure that your style code passes stylelint checks before committing.
## Contribution Process
LobeChat follows the gitmoji and semantic release as our code submission and release process.
### Gitmoji
When committing code, please use gitmoji to label your commit messages. This helps other contributors quickly understand the content and purpose of your submission.
Gitmoji commit messages use specific emojis to represent the type or intent of the commit. Here's an example:
```
📝 Update README with contribution guidelines
- Added section about code style preferences
- Included instructions for running tests
- Corrected typos and improved formatting
```
In this example, the 📝 emoji represents a documentation update. The commit message clearly describes the changes and provides specific details.
### Semantic Release
We use semantic release to automate version control and release processes. Ensure that your commit messages adhere to the semantic release specifications so that when the code is merged into the main branch, the system can automatically create a new version and release it.
### Commitlint
To ensure consistency in commit messages, we use `commitlint` to check the format of commit messages. You can find the relevant rules in the `.commitlintrc.js` configuration file.
Before committing your code, ensure that your commit messages adhere to our standards.
### How to Contribute
1. Fork the project to your account.
2. Create a new branch for development.
3. After completing the development, ensure that your code passes the aforementioned code style checks.
4. Commit your changes and use appropriate gitmoji to label your commit message.
5. Create a Pull Request to the main branch of the original project.
6. Await code review and make necessary modifications based on feedback.
Thank you for following these guidelines, as they help us maintain the quality and consistency of the project. We look forward to your contributions!
LobeChat is built on the Next.js framework and uses TypeScript as the primary development language. When developing a new feature, we need to follow a certain development process to ensure the quality and stability of the code. The general process can be divided into the following five steps:
1. Routing: Define routes (`src/app`).
2. Data Structure: Define data structures (`src/types`).
3. Business Logic Implementation: Zustand store (`src/store`).
- [4. Create Page and Components](#4-create-page-and-components)
- [5. Function Binding](#5-function-binding)
## 1. Define Routes
In the `src/app` directory, we need to define a new route to host the "Chat Messages" page. Generally, we would create a new folder under `src/app`, for example, `chat`, and create a `page.tsx` file within this folder to export a React component as the main body of the page.
```tsx
// src/app/chat/page.tsx
importChatPagefrom'./features/chat';
exportdefaultChatPage;
```
## 2. Define Data Structure
In the `src/types` directory, we need to define the data structure for "Chat Messages". For example, we create a `chat.ts` file and define the `ChatMessage` type within it:
```ts
// src/types/chat.ts
exporttypeChatMessage={
id: string;
content: string;
timestamp: number;
sender:'user'|'bot';
};
```
## 3. Create Zustand Store
In the `src/store` directory, we need to create a new Zustand Store to manage the state of "Chat Messages". For example, we create a `chatStore.ts` file and define a Zustand Store within it:
In `src/app/<new-page>/features/<new-feature>.tsx`, we need to create a new page or component to display "Chat Messages". In this file, we can use the Zustand Store created earlier and Ant Design components to build the UI:
In a page or component, we need to bind the Zustand Store's state and methods to the UI. In the example above, we have already bound the `messages` state to the `dataSource` property of the list. Now, we also need a method to add new messages. We can define this method in the Zustand Store and then use it in the page or component:
The above is the step to implement the "chat message" feature in LobeChat. Of course, in the actual development of LobeChat, the business requirements and scenarios faced in real situations are far more complex than the above demo. Please develop according to the actual situation.
This document aims to guide developers on how to develop a complete feature requirement in LobeChat.
We will use the implementation of sessionGroup as an example: [✨ feat: add session group manager](https://github.com/lobehub/lobe-chat/pull/1055), and explain the complete implementation process through the following six main sections:
1. Data Model / Database Definition
2. Service Implementation / Model Implementation
3. Frontend Data Flow Store Implementation
4. UI Implementation and Action Binding
5. Data Migration
6. Data Import and Export
## 1. Database Section
To implement the Session Group feature, it is necessary to define the relevant data model and indexes at the database level.
Define a new sessionGroup table in 3 steps:
### 1. Establish Data Model Schema
Define the data model of `DB_SessionGroup` in `src/database/schema/sessionGroup.ts`:
> In addition to `sessionGroups`, the definition of `sessions` has also been modified here due to data migration. However, as this section only focuses on schema definition and does not delve into the implementation of data migration, please refer to section five for details.
> \[!Important]
>
> If you are unfamiliar with the need to create indexes here and the syntax of schema definition, you may need to familiarize yourself with the basics of Dexie.js. You can refer to the [📘 Local Database](./Local-Database.zh-CN) section for relevant information.
### 3. Add the sessionGroups Table to the Local DB
Extend the local database class to include the new `sessionGroups` table:
```diff
import { dbSchemaV1, dbSchemaV2, dbSchemaV3, dbSchemaV4 } from './schemas';
interface LobeDBSchemaMap {
files: DB_File;
messages: DB_Message;
plugins: DB_Plugin;
+ sessionGroups: DB_SessionGroup;
sessions: DB_Session;
topics: DB_Topic;
}
// Define a local DB
export class LocalDB extends Dexie {
public files: LobeDBTable<'files'>;
public sessions: LobeDBTable<'sessions'>;
public messages: LobeDBTable<'messages'>;
public topics: LobeDBTable<'topics'>;
public plugins: LobeDBTable<'plugins'>;
+ public sessionGroups: LobeDBTable<'sessionGroups'>;
When building the LobeChat application, the Model is responsible for interacting with the database. It defines how to read, insert, update, and delete data from the database, as well as defining specific business logic.
In `src/database/model/sessionGroup.ts`, the `SessionGroupModel` is defined as follows:
In LobeChat, the Service layer is mainly responsible for communicating with the backend service, encapsulating business logic, and providing data to other layers in the frontend. `SessionService` is a service class specifically handling business logic related to sessions. It encapsulates operations such as creating sessions, querying sessions, and updating sessions.
To maintain code maintainability and extensibility, we place the logic related to session grouping in the `SessionService`. This helps to keep the business logic of the session domain cohesive. When business requirements increase or change, it becomes easier to modify and extend within this domain.
`SessionService` implements session group-related request logic by calling methods from `SessionGroupModel`. The following is the implementation of Session Group-related request logic in `sessionService`:
In the LobeChat application, the Store module is used to manage the frontend state of the application. The Actions within it are functions that trigger state updates, usually by calling methods in the service layer to perform actual data processing operations and then updating the state in the Store. We use `zustand` as the underlying dependency for the Store module. For a detailed practical introduction to state management, you can refer to [📘 Best Practices for State Management](../State-Management/State-Management-Intro.zh-CN.md).
### sessionGroup CRUD
CRUD operations for session groups are the core behaviors for managing session group data. In `src/store/session/slice/sessionGroup`, we will implement the state logic related to session groups, including adding, deleting, updating session groups, and their sorting.
The following are the methods of the `SessionGroupAction` interface that need to be implemented in the `action.ts` file:
Taking the `addSessionGroup` method as an example, we first call the `createSessionGroup` method of `sessionService` to create a new session group, and then use the `refreshSessions` method to refresh the sessions state:
```ts
exportconstcreateSessionGroupSlice: StateCreator<
SessionStore,
[['zustand/devtools',never]],
[],
SessionGroupAction
>=(set,get)=>({
// Implement the logic for adding a session group
addSessionGroup: async(name)=>{
// Call the createSessionGroup method in the service layer and pass in the session group name
// Call the get method to get the current Store state and execute the refreshSessions method to refresh the session data
awaitget().refreshSessions();
// Return the ID of the newly created session group
returnid;
},
// ... Other action implementations
});
```
With the above implementation, we can ensure that after adding a new session group, the application's state will be updated in a timely manner, and the relevant components will receive the latest state and re-render. This approach improves the predictability and maintainability of the data flow, while also simplifying communication between components.
### Sessions Group Logic Refactoring
This requirement involves upgrading the Sessions feature to transform it from a single list to three different groups: `pinnedSessions` (pinned list), `customSessionGroups` (custom groups), and `defaultSessions` (default list).
To handle these groups, we need to refactor the implementation logic of `useFetchSessions`. Here are the key changes:
1. Use the `sessionService.getGroupedSessions` method to call the backend API and retrieve the grouped session data.
2. Save the retrieved data into three different state fields: `pinnedSessions`, `customSessionGroups`, and `defaultSessions`.
#### `useFetchSessions` Method
This method is defined in `createSessionSlice` as follows:
After successfully retrieving the data, we use the `set` method to update the `customSessionGroups`, `defaultSessions`, `pinnedSessions`, and `sessions` states. This ensures that the states are synchronized with the latest session data.
#### `sessionService.getGroupedSessions` Method
The `sessionService.getGroupedSessions` method is responsible for calling the backend API `SessionModel.queryWithGroups()`.
This method is the core method called by `sessionService.getGroupedSessions`, and it is responsible for querying and organizing session data. The code is as follows:
```typescript
class_SessionModelextendsBaseModel{
// ... other methods
/**
* Query session data and categorize sessions based on groups.
* @returns {Promise<ChatSessionList>} An object containing all sessions and categorized session lists.
*/
asyncqueryWithGroups():Promise<ChatSessionList>{
// Query session group data
constgroups=awaitSessionGroupModel.query();
// Query custom session groups based on session group IDs
// Combine and return all sessions and their group information
return{
all,// Array containing all sessions
customGroup: groups.map((group)=>({...group,children: customGroups[group.id]})),// Custom groups
default:defaultItems,// Default session list
pinned: pinnedItems,// Pinned session list
};
}
}
```
The `queryWithGroups` method first queries all session groups, then based on the IDs of these groups, it queries custom session groups, as well as default and pinned sessions. Finally, it returns an object containing all sessions and categorized session lists.
### Adjusting sessions selectors
Due to changes in the logic of grouping within sessions, we need to adjust the logic of the `sessions` selectors to ensure they can correctly handle the new data structure.
Since all data retrieval in the UI is implemented using syntax like `useSessionStore(sessionSelectors.defaultSessions)`, we only need to modify the selector implementation of `defaultSessions` to complete the data structure change. The data retrieval code in the UI layer does not need to be changed at all, which can greatly reduce the cost and risk of refactoring.
> !\[Important]
>
> If you are not familiar with the concept and functionality of selectors, you can refer to the section [📘 Data Storage and Retrieval Module](./State-Management-Selectors.en-US) for relevant information.
## IV. UI Section
Bind Store Action in the UI component to implement interactive logic, for example `CreateGroupModal`:
In the process of software development, data migration is an inevitable issue, especially when the existing data structure cannot meet the new business requirements. For this iteration of SessionGroup, we need to handle the migration of the `group` field in the `session`, which is a typical data migration case.
### Issues with the Old Data Structure
In the old data structure, the `group` field was used to mark whether the session was "pinned" or belonged to a "default" group. However, when support for multiple session groups is needed, the original data structure becomes inflexible.
For example:
```
before pin: group = abc
after pin: group = pinned
after unpin: group = default
```
From the above example, it can be seen that once a session is unpinned from the "pinned" state, the `group` field cannot be restored to its original `abc` value. This is because we do not have a separate field to maintain the pinned state. Therefore, we have introduced a new field `pinned` to indicate whether the session is pinned, while the `group` field will be used solely to identify the session group.
### Migration Strategy
The core logic of this migration is as follows:
- When the user's `group` field is `pinned`, set their `pinned` field to `true`, and set the group to `default`.
However, data migration in LobeChat typically involves two parts: **configuration file migration** and **database migration**. Therefore, the above logic will need to be implemented separately in these two areas.
#### Configuration File Migration
For configuration file migration, we recommend performing it before database migration, as configuration file migration is usually easier to test and validate. LobeChat's file migration configuration is located in the `src/migrations/index.ts` file, which defines the various versions of configuration file migration and their corresponding migration scripts.
```diff
// Current latest version number
- export const CURRENT_CONFIG_VERSION = 2;
+ export const CURRENT_CONFIG_VERSION = 3;
// Historical version upgrade module
const ConfigMigrations = [
+ /**
+ * 2024.01.22
+ * from `group = pinned` to `pinned:true`
+ */
+ MigrationV2ToV3,
/**
* 2023.11.27
* Migrate from single key database to dexie-based relational structure
*/
MigrationV1ToV2,
/**
* 2023.07.11
* just the first version, Nothing to do
*/
MigrationV0ToV1,
];
```
The logic for this configuration file migration is defined in `src/migrations/FromV2ToV3/index.ts`, simplified as follows:
It can be seen that the migration implementation is very simple. However, it is important to ensure the correctness of the migration, so corresponding test cases need to be written in `src/migrations/FromV2ToV3/migrations.test.ts`:
Unit tests require the use of `fixtures` to fix the test data. The test cases include verification logic for two parts: 1) the correctness of a single migration (v2 -> v3) and 2) the correctness of a complete migration (v1 -> v3).
> \[!Important]
>
> The version number in the configuration file may not match the database version number, as database version updates do not always involve changes to the data structure (such as adding tables or fields), while configuration file version updates usually involve data migration.
````
#### Database Migration
Database migration needs to be implemented in the `LocalDB` class, which is defined in the `src/database/core/db.ts` file. The migration process involves adding a new `pinned` field for each record in the `sessions` table and resetting the `group` field:
```diff
export class LocalDB extends Dexie {
public files: LobeDBTable<'files'>;
public sessions: LobeDBTable<'sessions'>;
public messages: LobeDBTable<'messages'>;
public topics: LobeDBTable<'topics'>;
public plugins: LobeDBTable<'plugins'>;
public sessionGroups: LobeDBTable<'sessionGroups'>;
This is our data migration strategy. When performing the migration, it is essential to ensure the correctness of the migration script and validate the migration results through thorough testing.
## VI. Data Import and Export
In LobeChat, the data import and export feature is designed to ensure that users can migrate their data between different devices. This includes session, topic, message, and settings data. In the implementation of the Session Group feature, we also need to handle data import and export to ensure that the complete exported data can be restored exactly the same on other devices.
The core implementation of data import and export is in the `ConfigService` in `src/service/config.ts`, with key methods as follows:
| `importConfigState` | Import configuration data |
| `exportAgents` | Export all agent data |
| `exportSessions` | Export all session data |
| `exportSingleSession` | Export single session data |
| `exportSingleAgent` | Export single agent data |
| `exportSettings` | Export settings data |
| `exportAll` | Export all data |
### Data Export
In LobeChat, when a user chooses to export data, the current session, topic, message, and settings data are packaged into a JSON file and provided for download. The standard structure of this JSON file is as follows:
```json
{
"exportType": "sessions",
"state": {
"sessions": [],
"topics": [],
"messages": []
},
"version": 3
}
```
Where:
- `exportType`: Identifies the type of data being exported, currently including `sessions`, `agent`, `settings`, and `all`.
- `state`: Stores the actual data, with different data types for different `exportType`.
- `version`: Indicates the data version.
In the implementation of the Session Group feature, we need to add `sessionGroups` data to the `state` field. This way, when users export data, their Session Group data will also be included.
For example, when exporting sessions, the relevant implementation code modification is as follows:
The data import functionality is implemented through `ConfigService.importConfigState`. When users choose to import data, they need to provide a JSON file that conforms to the above structure specification. The `importConfigState` method accepts the data of the configuration file and imports it into the application.
In the implementation of the Session Group feature, we need to handle the `sessionGroups` data during the data import process. This way, when users import data, their Session Group data will also be imported correctly.
The following is the modified code for the import implementation in `importConfigState`:
One key point of the above modification is to import sessionGroup first, because if sessions are imported first and the corresponding SessionGroup Id is not found in the current database, the group of this session will default to be modified to the default value. This will prevent the correct association of the sessionGroup's ID with the session.
This is the implementation of the LobeChat Session Group feature in the data import and export process. This approach ensures that users' Session Group data is correctly handled during the import and export process.
## Summary
The above is the complete implementation process of the LobeChat Session Group feature. Developers can refer to this document for the development and testing of related functionalities.
The directory structure of LobeChat is as follows:
```bash
src
├── app # Main logic and state management related code for the application
├── components # Reusable UI components
├── config # Application configuration files, including client-side and server-side environment variables
├── const # Used to define constants, such as action types, route names, etc.
├── features # Function modules related to business functions, such as agent settings, plugin development pop-ups, etc.
├── hooks # Custom utility hooks reused throughout the application
├── layout # Application layout components, such as navigation bars, sidebars, etc.
├── locales # Internationalization language files
├── services # Encapsulated backend service interfaces, such as HTTP requests
├── store # Zustand store for state management
├── types # TypeScript type definition files
└── utils # Common utility functions
```
## app
In the `app` folder, we organize each route page according to the app router's [Route Groups](https://nextjs.org/docs/app/building-your-application/routing/route-groups) to separately handle the implementation of desktop and mobile code. Taking the file structure of the `welcome` page as an example:
├── features # This folder contains features code shared by both desktop and mobile, such as the Banner component
│ └── Banner
└── page.tsx # This is the main entry file for the page, used to load desktop or mobile code based on the device type
```
In this way, we can clearly distinguish and manage desktop and mobile code, while also easily reusing code required on both devices, thereby improving development efficiency and maintaining code cleanliness and maintainability.
Welcome to the LobeChat technical development getting started guide. LobeChat is an AI conversation application built on the Next.js framework, which integrates a series of technology stacks to achieve diverse functions and features. This guide will provide a detailed introduction to the main technical components of LobeChat and how to configure and use these technologies in your development environment.
- **Framework**: We have chosen [Next.js](https://nextjs.org/), a powerful React framework that provides key features such as server-side rendering, routing framework, and Router Handler for our project.
- **Component Library**: We use [Ant Design (antd)](https://ant.design/) as the basic component library, and also introduce [lobe-ui](https://github.com/lobehub/lobe-ui) as our business component library.
- **State Management**: We have opted for [zustand](https://github.com/pmndrs/zustand), a lightweight and easy-to-use state management library.
- **Network Requests**: We use [swr](https://swr.vercel.app/), a React Hooks library for data fetching.
- **Routing**: For routing management, we directly use the solution provided by [Next.js](https://nextjs.org/) itself.
- **Internationalization**: We use [i18next](https://www.i18next.com/) to implement multi-language support for the application.
- **Styling**: We use [antd-style](https://github.com/ant-design/antd-style), a CSS-in-JS library that complements Ant Design.
- **Unit Testing**: We use [vitest](https://github.com/vitest-dev/vitest) for unit testing.
## Folder Directory Structure
The folder directory structure of LobeChat is as follows:
```bash
src
├── app # Main logic of the application and code related to state management
├── components # Reusable UI components
├── config # Application configuration files, including client-side environment variables and server-side environment variables
├── const # Used to define constants, such as action types, route names, etc.
├── features # Function modules related to business features, such as Agent settings, plugin development pop-ups, etc.
├── hooks # Custom utility hooks reused throughout the application
├── layout # Application layout components, such as navigation bars, sidebars, etc.
├── locales # Language files for internationalization
├── services # Encapsulated backend service interfaces, such as HTTP requests
├── store # Zustand store for state management
├── types # TypeScript type definition files
└── utils # Common utility functions
```
For a detailed introduction to the directory structure, please refer to: [Folder Directory Structure](Folder-Structure.en-US.md)
The design and development of LobeChat would not have been possible without the excellent projects in the community and ecosystem. We have used or referred to some outstanding resources and guides in the design and development process. Here are some key reference resources for developers to refer to during the development and learning process:
1.**OpenAI API Guide**: We use OpenAI's API to access and process AI conversation data. You can check out the [OpenAI API Guide](https://platform.openai.com/docs/api-reference/introduction) for more details.
2.**OpenAI SDK**: We use OpenAI's Node.js SDK to interact with OpenAI's API. You can view the source code and documentation on the [OpenAI SDK](https://github.com/openai/openai-node) GitHub repository.
3.**AI SDK**: We use Vercel's AI SDK to access and process AI conversation data. You can refer to the documentation of [AI SDK](https://sdk.vercel.ai/docs) for more details.
4.**LangChain**: Our early conversation feature was implemented based on LangChain. You can visit [LangChain](https://langchain.com) to learn more about it.
5.**Chat-Next-Web**: Chat Next Web is an excellent project, and some of LobeChat's features and workflows are referenced from its implementation. You can view the source code and documentation on the [Chat-Next-Web](https://github.com/Yidadaa/ChatGPT-Next-Web) GitHub repository.
6.**Next.js Documentation**: Our project is built on Next.js, and you can refer to the [Next.js Documentation](https://nextjs.org/docs) for more information about Next.js.
7.**FlowGPT**: FlowGPT is currently the world's largest Prompt community, and some of the agents in LobeChat come from active authors in FlowGPT. You can visit [FlowGPT](https://flowgpt.com/) to learn more about it.
We will continue to update and supplement this list to provide developers with more reference resources.
5.**Chat-Next-Web**:Chat Next Web 是一个优秀的项目,LobeChat 的部分功能、Workflow 等参考了它的实现。你可以在 [Chat-Next-Web](https://github.com/Yidadaa/ChatGPT-Next-Web) 的 GitHub 仓库中查看源码和文档。
If you have access to GitHub Codespaces, you can click the button below to enter the online development environment with just one click:
[![][codespaces-shield]][codespaces-link]
## Local Development
Before starting development on LobeChat, you need to install and configure some necessary software and tools in your local environment. This document will guide you through these steps.
### Development Environment Requirements
First, you need to install the following software:
- Node.js: LobeChat is built on Node.js, so you need to install Node.js. We recommend installing the latest stable version.
- Yarn: We use Yarn as the preferred package manager. You can download and install it from the Yarn official website.
- PNPM: We use PNPM as an auxiliary package manager. You can download and install it from the PNPM official website.
- Git: We use Git for version control. You can download and install it from the Git official website.
- IDE: You can choose your preferred integrated development environment (IDE). We recommend using WebStorm, a powerful IDE particularly suitable for TypeScript development.
### Project Setup
After installing the above software, you can start setting up the LobeChat project.
1.**Get the code**: First, you need to clone the LobeChat codebase from GitHub. Run the following command in the terminal:
2.**Install dependencies**: Then, navigate to the project directory and use Yarn to install the project's dependencies:
```bash
cd lobe-chat
yarn install
```
If you are using PNPM, you can execute:
```bash
cd lobe-chat
pnpm install
```
3.**Start the development server**: After installing the dependencies, you can start the development server:
```bash
yarn run dev
```
Now, you can open `http://localhost:3010` in your browser, and you should see the welcome page of LobeChat. This indicates that you have successfully set up the development environment.
During the development process, if you encounter any issues with environment setup or have any questions about LobeChat development, feel free to ask us at any time. We look forward to seeing your contributions!
LobeChat's testing strategy includes unit testing and end-to-end (E2E) testing. Below are detailed explanations of each type of testing:
#### TOC
- [Unit Testing](#unit-testing)
- [🚧 End-to-End Testing](#-end-to-end-testing)
- [Development Testing](#development-testing)
- [1. Unit Testing](#1-unit-testing)
- [Testing Strategy](#testing-strategy)
## Unit Testing
Unit testing is used to test the functionality of independent units in the application, such as components, functions, utility functions, etc. We use [vitest][vitest-url] for unit testing.
To run unit tests, you can use the following command:
```
npm run test
```
This will run all unit tests and generate a test report.
We encourage developers to write corresponding unit tests while writing code to ensure the quality and stability of the code.
## 🚧 End-to-End Testing
End-to-end testing is used to test the functionality and performance of the application in a real environment. It simulates real user operations and verifies the application's performance in different scenarios.
Currently, there is no integrated end-to-end testing in LobeChat. We will gradually introduce end-to-end testing in subsequent iterations.
## Development Testing
### 1. Unit Testing
Unit testing is conducted on the smallest testable units in the application, usually functions, components, or modules. In LobeChat, we use [vitest][vitest-url] for unit testing.
#### Writing Test Cases
Before writing unit tests, you need to create a directory with the same name as the file to be tested and name the test file `<filename>.test.ts`. For example, if you want to test the `src/utils/formatDate.ts` file, the test file should be named `src/utils/formatDate.test.ts`.
In the test file, you can use the `describe` and `it` functions to organize and write test cases. The `describe` function is used to create a test suite, and the `it` function is used to write specific test cases.
```typescript
import{formatNumber}from'./formatNumber';
describe('formatNumber',()=>{
it('should format number with comma separator',()=>{
constresult=formatNumber(1000);
expect(result).toBe('1,000');
});
it('should return the same number if it is less than 1000',()=>{
constresult=formatNumber(500);
expect(result).toBe('500');
});
});
```
In test cases, you can use the `expect` function to assert whether the test results meet expectations. The `expect` function can be used with various matchers, such as `toBe`, `toEqual`, `toBeTruthy`, etc.
#### Running Unit Tests
Execute unit tests by running the following command:
```
npm run test
```
This will run all unit tests and output the test results.
## Testing Strategy
To write effective test cases, you can consider the following testing strategies:
- **Boundary Testing**: Test the boundary conditions of inputs, such as minimum value, maximum value, empty value, etc.
- **Exception Testing**: Test the code handling exceptional cases, such as error handling, fallback in exceptional situations, etc.
- **Functional Testing**: Test whether various functional modules of the application work properly, including user interaction, data processing, etc.
- **Compatibility Testing**: Test the compatibility of the application on different browsers and devices.
- **Performance Testing**: Test the performance of the application under different loads, such as response time, resource utilization, etc.
Also, ensure that your test cases have good coverage, covering critical code and functionality in the application.
By properly writing and executing unit tests, integration tests, and end-to-end tests, you can improve the quality and stability of the application and promptly identify and fix potential issues.
LobeChat is an open-source, extensible ([Function Calling][fc-url]), high-performance chatbot framework. <br/> It supports one-click free deployment of your private ChatGPT/LLM web application.
- [Code Style and Contribution Guidelines](https://github.com/lobehub/lobe-chat/wiki/Contributing-Guidelines) | [代码风格与贡献指南](https://github.com/lobehub/lobe-chat/wiki/Contributing-Guidelines.zh-CN)
- [Complete Guide to LobeChat Feature Development](https://github.com/lobehub/lobe-chat/wiki/Feature-Development) | [LobeChat 功能开发完全指南](https://github.com/lobehub/lobe-chat/wiki/Feature-Development.zh-CN)
- [Conversation API Implementation Logic](https://github.com/lobehub/lobe-chat/wiki/Chat-API) | [会话 API 实现逻辑](https://github.com/lobehub/lobe-chat/wiki/Chat-API.zh-CN)
- [How to Develop a New Feature](https://github.com/lobehub/lobe-chat/wiki/Feature-Development-Frontend) | [如何开发一个新功能:前端实现](https://github.com/lobehub/lobe-chat/wiki/Feature-Development-Frontend.zh-CN)
- [Resources and References](https://github.com/lobehub/lobe-chat/wiki/Resources) | [资源与参考](https://github.com/lobehub/lobe-chat/wiki/Resources.zh-CN)
- [Technical Development Getting Started Guide](https://github.com/lobehub/lobe-chat/wiki/Intro) | [技术开发上手指南](https://github.com/lobehub/lobe-chat/wiki/Intro.zh-CN)
- [Best Practices for State Management](https://github.com/lobehub/lobe-chat/wiki/State-Management-Intro) | [状态管理最佳实践](https://github.com/lobehub/lobe-chat/wiki/State-Management-Intro.zh-CN)
- [Data Store Selector](https://github.com/lobehub/lobe-chat/wiki/State-Management-Selectors) | [数据存储取数模块](https://github.com/lobehub/lobe-chat/wiki/State-Management-Selectors.zh-CN)
<br/>
### 🤖 Agents
- [Agent Index and Submit](https://github.com/lobehub/lobe-chat-agents) | [助手索引与提交](https://github.com/lobehub/lobe-chat-agents/blob/main/README.zh-CN.md)
<br/>
### 🧩 Plugins
- [Plugin Index and Submit](https://github.com/lobehub/lobe-chat-plugins) | [插件索引与提交](https://github.com/lobehub/lobe-chat-plugins/blob/main/README.zh-CN.md)
LobeChat uses [lobe-i18n](https://github.com/lobehub/lobe-cli-toolbox/tree/master/packages/lobe-i18n) as the i18n solution, which allows for quick addition of new language support in the application.
## TOC
- [Adding New Language Support](#adding-new-language-support)
- [Step 1: Update the Internationalization Configuration File](#step-1-update-the-internationalization-configuration-file)
- [Step 2: Automatically Translate Language Files](#step-2-automatically-translate-language-files)
- [Step 3: Submit and Review Your Changes](#step-3-submit-and-review-your-changes)
To add new language internationalization support in LobeChat (for example, adding Vietnamese `vi-VN`), please follow the steps below:
### Step 1: Update the Internationalization Configuration File
1. Open the `.i18nrc.js` file. You can find this file in the project's root directory.
2. Add the new language code to the configuration file. For example, to add Vietnamese, you need to add `'vi-VN'` to the configuration file.
```js
module.exports={
// ... Other configurations
outputLocales:[
'zh-TW',
'en-US',
'ru-RU',
'ja-JP',
// ...Other languages
'vi-VN',// Add 'vi-VN' to the array
],
};
```
### Step 2: Automatically Translate Language Files
LobeChat uses the `lobe-i18n` tool to automatically translate language files, so manual updating of i18n files is not required.
Run the following command to automatically translate and generate the Vietnamese language files:
```bash
npm run i18n
```
This will utilize the `lobe-i18n` tool to process the language files.
### Step 3: Submit and Review Your Changes
Once you have completed the above steps, you need to submit your changes and create a Pull Request.
Ensure that you follow LobeChat's contribution guidelines and provide a necessary description to explain your changes. For example, refer to a similar previous Pull Request [#759](https://github.com/lobehub/lobe-chat/pull/759).
### Additional Information
- After submitting your Pull Request, please patiently wait for the project maintainers to review it.
- If you encounter any issues, you can reach out to the LobeChat community for assistance.
- For more accurate results, ensure that your Pull Request is based on the latest main branch and stays in sync with the main branch.
By following the above steps, you can successfully add new language support to LobeChat and ensure that the application provides a localized experience for more users.
Welcome to the LobeChat Internationalization Implementation Guide. This document will guide you through understanding the internationalization mechanism of LobeChat, including file structure and how to add new languages. LobeChat uses `i18next` and `lobe-i18n` as the internationalization solution, aiming to provide users with seamless multilingual support.
- [Adding Support for New Languages](#adding-support-for-new-languages)
- [Resources and Further Reading](#resources-and-further-reading)
## Internationalization Overview
Internationalization (i18n for short) is the process of enabling an application to adapt to different languages and regions. In LobeChat, we support multiple languages and achieve dynamic language switching and content localization through the `i18next` library. Our goal is to provide a localized experience for global users.
## File Structure
In the LobeChat project, internationalization-related files are organized as follows:
-`src/locales/default`: Contains translation files for the default development language (Chinese), which we use as Chinese.
-`locales`: Contains folders for all supported languages, with each language folder containing the respective translation files generated by lobe-i18n.
In the directory structure of `src/locales`, the `default` folder contains the original translation files (Chinese), while each other language folder contains JSON translation files for the respective language. The files in each language folder correspond to the TypeScript files in the `default` folder, ensuring consistency in the structure of translation files across languages.
```
src/locales
├── create.ts
├── default
│ ├── chat.ts
│ ├── common.ts
│ ├── error.ts
│ ├── index.ts
│ ├── market.ts
│ ├── migration.ts
│ ├── plugin.ts
│ ├── setting.ts
│ ├── tool.ts
│ └── welcome.ts
└── resources.ts
```
The file structure generated by lobe-i18n is as follows:
```
locales
├── ar
│ ├── chat.json
│ ├── common.json
│ ├── error.json
│ └── ... (other translation files)
├── de-DE
│ ├── chat.json
│ ├── common.json
│ ├── error.json
│ └── ... (other translation files)
├── en-US
├── ... (other language directories)
├── zh-CN
└── zh-TW
```
## Core Implementation Logic
The internationalization core implementation logic of LobeChat is as follows:
- Initialize and configure using the `i18next` library.
- Automatically detect the user's language preference using `i18next-browser-languagedetector`.
- Dynamically load translation resources using `i18next-resources-to-backend`.
- Set the direction of the HTML document (LTR or RTL) based on the user's language preference.
Here is a simplified pseudo code example to illustrate the core implementation logic of internationalization in LobeChat:
// Listen for language change events and dynamically set document direction
i18nInstance.on('languageChanged',(language)=>{
constdirection=isRtlLang(language)?'rtl':'ltr';
document.documentElement.dir=direction;// Set HTML document direction
});
// Initialize i18n instance
i18nInstance.init({
// Relevant configurations
});
returni18nInstance;
};
```
In this example, we demonstrate how to use `i18next` and related plugins to initialize internationalization settings. We dynamically import translation resources and respond to language change events to adjust the text direction of the page. This process provides LobeChat with flexible multilingual support capabilities.
## Adding Support for New Languages
We have already supported a variety of languages globally through the following efforts:
- [✨ feat: adding Arabic Language Support #1049](https://github.com/lobehub/lobe-chat/pull/1049)
- [🌐 style: Add Vietnamese files and add the vi-VN option in the General Settings #860](https://github.com/lobehub/lobe-chat/pull/860)
- [🌐 style: support it-IT nl-NL and pl-PL locales #759](https://github.com/lobehub/lobe-chat/pull/759)
By following this guide, you can better understand and participate in the internationalization work of LobeChat, providing a seamless multilingual experience for global users.
LobeChat differs from traditional CRUD web applications in that it involves a large amount of rich interactive capabilities. Therefore, it is crucial to design a data flow architecture that is easy to develop and maintain. This document will introduce the best practices for data flow management in LobeChat.
| store | The store contains the application's state and actions. It allows access to and modification of the state during application rendering. |
| state | State refers to the data of the application, storing the current state of the application. Any change in the state will **trigger a re-rendering** to reflect the new state. |
| action | An action is an operation function that describes the interactive events occurring in the application. Actions are typically triggered by user interactions, network requests, or timers. Actions can be **synchronous** or **asynchronous**. |
| reducer | A reducer is a pure function that takes the current state and action as parameters and returns a new state. It is used to update the application's state based on the action type. A reducer is a pure function with no side effects, therefore it is always a **synchronous** function. |
| selector | A selector is a function used to retrieve specific data from the application's state. It takes the application's state as a parameter and returns computed or transformed data. Selectors can combine parts of the state or multiple states to generate derived data. Selectors are commonly used to map the application's state to a component's props for the component's use. |
| slice | A slice is a concept used to express a part of the data model state. It specifies a state slice and its related state, action, reducer, and selector. Using slices, a large store can be divided into smaller, maintainable subtypes. |
## Hierarchical Structure
The structure of the Store can vary greatly depending on the complexity:
- **Low Complexity**: Generally includes 2 to 5 states and 3 to 4 actions. In this case, the structure usually consists of a `store.ts` and an `initialState.ts`.
```bash
DataFill/store
├── index.ts
└── initialState.ts
```
- **Moderate Complexity**: Typically involves 5 to 15 states and 5 to 10 actions, with the possibility of selectors for derived states and reducers to simplify data changes. The structure usually includes a `store.ts`, an `initialState.ts`, and a `selectors.ts`/`reducer.ts`.
```bash
IconPicker/store
├── index.ts
├── initialState.ts
├── selectors.ts
└── store.ts
```
```bash
SortableList/store
├── index.ts
├── initialState.ts
├── listDataReducer.ts
└── store.ts
```
- **Medium Complexity**: Involves 15 to 30 states and 10 to 20 actions, often requiring the use of multiple slices to manage different actions. The following code represents the internal data flow of the `SortableTree` component:
```bash
SortableTree/store
├── index.ts
├── initialState.ts
├── selectors.ts
├── slices
│ ├── crudSlice.ts
│ ├── dndSlice.ts
│ └── selectionSlice.ts
├── store.ts
└── treeDataReducer.ts
```
- **High Complexity**: Involves over 30 states and 20 actions, requiring modular cohesion using slices. Each slice declares its own initState, actions, reducers, and selectors.
The directory structure of the previous version of SessionStore for LobeChat, with high complexity, implements a large amount of business logic. However, with the modularization of slices and the fractal architecture, it is easy to find the corresponding modules, making it easy to maintain and iterate on new features.
```bash
LobeChat SessionStore
├── index.ts
├── initialState.ts
├── selectors.ts
├── slices
│ ├── agentConfig
│ │ ├── action.ts
│ │ ├── index.ts
│ │ ├── initialState.ts
│ │ └── selectors.ts
│ ├── chat
│ │ ├── actions
│ │ │ ├── index.ts
│ │ │ ├── message.ts
│ │ │ └── topic.ts
│ │ ├── index.ts
│ │ ├── initialState.ts
│ │ ├── reducers
│ │ │ ├── message.ts
│ │ │ └── topic.ts
│ │ ├── selectors
│ │ │ ├── chat.ts
│ │ │ ├── index.ts
│ │ │ ├── token.ts
│ │ │ ├── topic.ts
│ │ │ └── utils.ts
│ │ └── utils.ts
│ └── session
│ ├── action.ts
│ ├── index.ts
│ ├── initialState.ts
│ ├── reducers
│ │ └── session.ts
│ └── selectors
│ ├── export.ts
│ ├── index.ts
│ └── list.ts
└── store.ts
```
Based on the provided directory structure of LobeChat SessionStore, we can update the previous document and convert the examples to the implementation of LobeChat's SessionStore. The following is a portion of the updated document:
### Best Practices for LobeChat SessionStore Directory Structure
In the LobeChat application, session management is a complex functional module, so we use the Slice pattern to organize the data flow. Below is the directory structure of LobeChat SessionStore, where each directory and file has its specific purpose:
```bash
src/store/session
├── helpers.ts # Helper functions
├── hooks # Custom React hooks
│ ├── index.ts # Export file for hooks
│ ├── useEffectAfterHydrated.ts # Hook for effects after session hydration
│ ├── useOnFinishHydrationSession.ts # Hook for session hydration completion
│ ├── useSessionChatInit.ts # Hook for session chat initialization
│ └── useSessionHydrated.ts # Hook for session hydration status
├── index.ts # Aggregated export file for SessionStore
├── initialState.ts # Aggregated initialState for all slices
├── selectors.ts # Selectors exported from various slices
├── slices # Separated functional modules
│ ├── agent # State and operations related to agents
│ │ ├── action.ts # Action definitions related to agents
│ │ ├── index.ts # Entry file for agent slice
│ │ ├── selectors.test.ts # Tests for agent-related selectors
│ │ └── selectors.ts # Selector definitions related to agents
│ └── session # State and operations related to sessions
│ ├── action.test.ts # Tests for session-related actions
│ ├── action.ts # Action definitions related to sessions
│ ├── helpers.ts # Helper functions related to sessions
│ ├── initialState.ts # Initial state for session slice
│ └── selectors # Session-related selectors and their tests
│ ├── export.ts # Aggregated export for session selectors
│ ├── index.ts # Entry file for session selectors
│ ├── list.test.ts # Tests for list selectors
│ └── list.ts # Definitions for list-related selectors
└── store.ts # Creation and usage of SessionStore
```
## Implementation of SessionStore
In LobeChat, the SessionStore is designed as the core module for managing session state and logic. It consists of multiple Slices, with each Slice managing a relevant portion of state and logic. Below is a simplified example of the SessionStore implementation:
In this `store.ts` file, we create a `useSessionStore` hook that uses the `zustand` library to create a global state manager. We merge the initialState and the state and actions of each Slice to create a complete SessionStore.
#### slices/session/action.ts
```ts
import{StateCreator}from'zustand';
import{SessionStore}from'@/store/session';
exportinterfaceSessionActions{
/**
* A custom hook that uses SWR to fetch sessions data.
*/
useFetchSessions:()=>SWRResponse<any>;
}
exportconstcreateSessionSlice: StateCreator<
SessionStore,
[['zustand/devtools',never]],
[],
SessionAction
>=(set,get)=>({
useFetchSessions:()=>{
// ...logic for initializing sessions
},
// ...implementation of other actions
});
```
In the `action.ts` file, we define a `SessionActions` interface to describe session-related actions and implement a `useFetchSessions` function to create these actions. Then, we merge these actions with the initial state to form the session-related Slice.
Through this layered and modular approach, we can ensure that LobeChat's SessionStore is clear, maintainable, and easy to extend and test.
Selectors are data retrieval modules under the LobeChat data flow development framework. Their role is to extract data from the store using specific business logic for consumption by components.
Taking `src/store/plugin/selectors.ts` as an example:
This TypeScript code snippet defines an object named `pluginSelectors`, which contains a series of selector functions used to retrieve data from the plugin storage state. Selectors are functions that extract and derive data from a Redux store (or similar state management library). This specific example is for managing the state related to the frontend application's plugin system.
Here are some key points to note:
-`enabledSchema`: A function that returns an array of `ChatCompletionFunctions` filtered based on the enabled plugin list `enabledPlugins`. It appends the plugin identifier as a prefix to the API names to ensure uniqueness and uses the `uniqBy` function from the Lodash library to remove duplicates.
-`onlinePluginStore`: Returns the current online plugin list.
-`pluginList`: Returns the list of plugins, including custom plugins and standard plugins.
-`getPluginMetaById`: Returns the plugin metadata based on the plugin ID.
-`getDevPluginById`: Returns information about the custom plugins in development.
-`getPluginManifestById`: Returns the plugin manifest based on the plugin ID.
-`getPluginSettingsById`: Returns the plugin settings based on the plugin ID.
-`getPluginManifestLoadingStatus`: Returns the loading status of the plugin manifest (loading, success, or error) based on the plugin ID.
-`isCustomPlugin`: Checks if the plugin with the given ID is a custom plugin.
-`displayPluginList`: Returns a processed plugin list, including author, avatar, creation time, description, homepage URL, identifier, and title.
-`hasPluginUI`: Determines if the plugin has UI components based on the plugin ID.
Selectors are highly modular and maintainable. By encapsulating complex state selection logic in separate functions, they make the code more concise and intuitive when accessing state data in other parts of the application. Additionally, by using TypeScript, each function can have clear input and output types, which helps improve code reliability and development efficiency.
Taking the `displayPluginList` method as an example, its code is as follows:
-`pluginList` method: Used to retrieve the list of all plugins from the plugin state storage `PluginStoreState`. It creates a new plugin list by combining two arrays: `pluginList` and `customPluginList`.
-`displayPluginList` method: Calls the `pluginList` method to retrieve the merged plugin list and transforms the `title` and `desc` into text displayed on the UI.
In components, the final consumed data can be directly obtained by importing:
```tsx | pure
import { usePluginStore } from '@/store/plugin';
import { pluginSelectors } from '@/store/plugin/selectors';
const Render = ({ plugins }) => {
const list = usePluginStore(pluginSelectors.displayPluginList);
return <> ... </>;
};
```
The benefits of implementing this approach are:
1.**Decoupling and reusability**: By separating selectors from components, we can reuse these selectors across multiple components without rewriting data retrieval logic. This reduces duplicate code, improves development efficiency, and makes the codebase cleaner and easier to maintain.
2.**Performance optimization**: Selectors can be used to compute derived data, avoiding redundant calculations in each component. When the state changes, only the selectors dependent on that part of the state will recalculate, reducing unnecessary rendering and computation.
3.**Ease of testing**: Selectors are pure functions, relying only on the passed parameters. This means they can be tested in an isolated environment without the need to simulate the entire store or component tree.
4.**Type safety**: As LobeChat uses TypeScript, each selector has explicit input and output type definitions. This provides developers with the advantage of auto-completion and compile-time checks, reducing runtime errors.
5.**Maintainability**: Selectors centralize the logic for reading state, making it more intuitive to track state changes and management. If the state structure changes, only the relevant selectors need to be updated, rather than searching and replacing in multiple places throughout the codebase.
6.**Composability**: Selectors can be composed with other selectors to create more complex selection logic. This pattern allows developers to build a hierarchy of selectors, making state selection more flexible and powerful.
7.**Simplified component logic**: Components do not need to know the structure of the state or how to retrieve and compute the required data. Components only need to call selectors to obtain the data needed for rendering, simplifying and clarifying component logic.
With this design, LobeChat developers can focus more on building the user interface and business logic without worrying about the details of data retrieval and processing. This pattern also provides better adaptability and scalability for potential future changes in state structure.
English | [简体中文](https://github.com/lobehub/lobe-chat/wiki/Upstream-Sync.zh-CN)
## `A` Vercel / Zeabur Deployment
If you have deployed your own project following the one-click deployment steps in the README, you might encounter constant prompts indicating "updates available". This is because Vercel defaults to creating a new project instead of forking this one, resulting in an inability to accurately detect updates. We suggest you redeploy using the following steps:
- Remove the original repository;
- Use the <kbd>Fork</kbd> button at the top right corner of the page to fork this project;
- Re-select and deploy on `Vercel`.
## Enabling Automatic Updates
> \[!NOTE]
>
> If you encounter an error executing Upstream Sync, manually Sync Fork once
Once you have forked the project, due to Github restrictions, you will need to manually enable Workflows on the Actions page of your forked project and activate the Upstream Sync Action. Once enabled, you can set up hourly automatic updates.
Upgrading the Docker deployment version is very simple, just redeploy the latest image of LobeChat. Here are the instructions to perform these steps:
1. Stop and delete the currently running LobeChat container (assuming the name of the LobeChat container is `lobe-chat`):
```fish
docker stop lobe-chat
docker rm lobe-chat
```
2. Pull the latest Docker image of LobeChat:
```fish
docker pull lobehub/lobe-chat
```
3. Redeploy the LobeChat container using the newly pulled image:
```fish
docker run -d-p3210:3210\
-eOPENAI_API_KEY=sk-xxxx \
-eOPENAI_PROXY_URL=https://api-proxy.com/v1 \
-eACCESS_CODE=lobe66 \
--name lobe-chat \
lobehub/lobe-chat
```
Make sure you have sufficient permissions to stop and delete the container before executing these commands, and Docker has sufficient permissions to pull the new image.
> \[!NOTE]
>
> If I redeploy, will my local chat history be lost?
>
> Don't worry, all of LobeChat's chat history is stored in your local browser. Therefore, when you redeploy LobeChat using Docker, your chat history will not be lost.
- [Code Style and Contribution Guidelines](https://github.com/lobehub/lobe-chat/wiki/Contributing-Guidelines) | [代码风格与贡献指南](https://github.com/lobehub/lobe-chat/wiki/Contributing-Guidelines.zh-CN)
- [Complete Guide to LobeChat Feature Development](https://github.com/lobehub/lobe-chat/wiki/Feature-Development) | [LobeChat 功能开发完全指南](https://github.com/lobehub/lobe-chat/wiki/Feature-Development.zh-CN)
- [Conversation API Implementation Logic](https://github.com/lobehub/lobe-chat/wiki/Chat-API) | [会话 API 实现逻辑](https://github.com/lobehub/lobe-chat/wiki/Chat-API.zh-CN)
- [How to Develop a New Feature](https://github.com/lobehub/lobe-chat/wiki/Feature-Development-Frontend) | [如何开发一个新功能:前端实现](https://github.com/lobehub/lobe-chat/wiki/Feature-Development-Frontend.zh-CN)
- [Resources and References](https://github.com/lobehub/lobe-chat/wiki/Resources) | [资源与参考](https://github.com/lobehub/lobe-chat/wiki/Resources.zh-CN)
- [Technical Development Getting Started Guide](https://github.com/lobehub/lobe-chat/wiki/Intro) | [技术开发上手指南](https://github.com/lobehub/lobe-chat/wiki/Intro.zh-CN)
- [Best Practices for State Management](https://github.com/lobehub/lobe-chat/wiki/State-Management-Intro) | [状态管理最佳实践](https://github.com/lobehub/lobe-chat/wiki/State-Management-Intro.zh-CN)
- [Data Store Selector](https://github.com/lobehub/lobe-chat/wiki/State-Management-Selectors) | [数据存储取数模块](https://github.com/lobehub/lobe-chat/wiki/State-Management-Selectors.zh-CN)
#### 🤖 Agents
- [Agent Index and Submit](https://github.com/lobehub/lobe-chat-agents) | [助手索引与提交](https://github.com/lobehub/lobe-chat-agents/blob/main/README.zh-CN.md)
#### 🧩 Plugins
- [Plugin Index and Submit](https://github.com/lobehub/lobe-chat-plugins) | [插件索引与提交](https://github.com/lobehub/lobe-chat-plugins/blob/main/README.zh-CN.md)
LobeChat supports using [Azure OpenAI][azure-openai-url] as the model service provider for OpenAI. This document will guide you through the configuration of Azure OpenAI.
#### TOC
- [Usage Limitations](#usage-limitations)
- [Configuration in the Interface](#configuration-in-the-interface)
- [Configuration at Deployment](#configuration-at-deployment)
## Usage Limitations
Considering development costs ([#178][rfc]), the current version of LobeChat does not fully conform to Azure OpenAI's implementation model. Instead, it adopts a solution based on `openai` that is compatible with Azure OpenAI. This brings about the following limitations:
- You can only choose one between OpenAI and Azure OpenAI. Once you enable Azure OpenAI, you will not be able to use OpenAI as the model service provider.
- LobeChat requires deployment names to be the same as the model names in order to function properly. For example, the deployment name for the `gpt-35-turbo` model must be `gpt-35-turbo`, otherwise LobeChat will not be able to match the model correctly.
- Due to the complexity of integrating the Azure OpenAI SDK, it is currently impossible to query the model list of configured resources.
## Configuration in the Interface
Click on "Operation" - "Settings" in the bottom left corner, switch to the "Language Model" tab and enable the "Azure OpenAI" switch to start using Azure OpenAI.
You can fill in the corresponding configuration items as needed:
- **APIKey**: The API key you applied for on the Azure OpenAI account page, which can be found in the "Keys and Endpoints" section.
- **API Address**: Azure API address, which can be found in the "Keys and Endpoints" section when checking resources from the Azure portal.
- **Azure Api Version**: The API version of Azure, which follows the YYYY-MM-DD format, refer to the [latest version][azure-api-verion-url].
After completing the above field configuration, click on "Check". If the prompt says "Check Passed", it means the configuration was successful.
<br/>
## Configuration at Deployment
If you want the deployed version to be directly configured with Azure OpenAI for end users to use immediately, you need to configure the following environment variables at deployment:
| Environment Variable | Required | Description | Default Value | Example |
| `USE_AZURE_OPENAI` | Yes | Set this value to `1` to enable Azure OpenAI configuration | - | `1` |
| `AZURE_API_KEY` | Yes | This is the API key you applied for on the Azure OpenAI account page | - | `c55168be3874490ef0565d9779ecd5a6` |
| `OPENAI_PROXY_URL` | Yes | Azure API address, can be found in the "Keys and Endpoints" section | - | `https://docs-test-001.openai.azure.com` |
| `AZURE_API_VERSION` | No | Azure's API version, follows the YYYY-MM-DD format | 2023-08-01-preview | `2023-05-15`, refer to [latest version][azure-api-verion-url] |
| `ACCESS_CODE` | No | Add a password to access this service, the password should be 6 digits or letters | - | `awCT74` or `e3@09!` |
> **Note**\
> When you enable `USE_AZURE_OPENAI` on the server side, users will not be able to modify and use the OpenAI key in the front-end configuration.
LobeChat provides additional configuration options during deployment, which can be set using environment variables
#### TOC
- [General Variables](#general-variables)
- [`ACCESS_CODE`](#access_code)
- [OpenAI](#openai)
- [`OPENAI_API_KEY`](#openai_api_key)
- [`OPENAI_PROXY_URL`](#openai_proxy_url)
- [Azure OpenAI](#azure-openai)
- [`USE_AZURE_OPENAI`](#use_azure_openai)
- [`AZURE_API_KEY`](#azure_api_key)
- [`AZURE_API_VERSION`](#azure_api_version)
- [Plugin Service](#plugin-service)
- [`PLUGINS_INDEX_URL`](#plugins_index_url)
- [Agent Service](#agent-service)
- [`AGENTS_INDEX_URL`](#agents_index_url)
- [Data Analytics](#data-analytics)
- [Posthog Analytics](#posthog-analytics)
## General Variables
### `ACCESS_CODE`
- Type: Optional
- Description: Add a password to access the LobeChat service, the password should be 6 digits or letters
- Default: -
- Example: `awCT74` or `e3@09!`
<br/>
## OpenAI
### `OPENAI_API_KEY`
- Type: Required
- Description: This is the API key you apply for on the OpenAI account page, you can go [here][openai-api-page] to view
- Default: -
- Example: `sk-xxxxxx...xxxxxx`
### `OPENAI_PROXY_URL`
- Type: Optional
- Description: If you manually configure the OpenAI interface proxy, you can use this configuration item to override the default OpenAI API request base URL
- Default: `https://api.openai.com`
- Example: `https://api.chatanywhere.cn`
<br/>
## Azure OpenAI
If you need to use Azure OpenAI to provide model services, you can refer to the [Deploy with Azure OpenAI](./Deploy-with-Azure-OpenAI.zh-CN.md) section for detailed steps. Here are the environment variables related to Azure OpenAI.
### `USE_AZURE_OPENAI`
- Type: Optional
- Description: Set this value to `1` to enable Azure OpenAI configuration
- Default: -
- Example: `1`
### `AZURE_API_KEY`
- Type: Optional
- Description: This is the API key you apply for on the Azure OpenAI account page
- Default: -
- Example: `c55168be3874490ef0565d9779ecd5a6`
### `AZURE_API_VERSION`
- Type: Optional
- Description: Azure's API version, following the YYYY-MM-DD format
- Default: `2023-08-01-preview`
- Example: `2023-05-15`, refer to [latest version][azure-api-verion-url]
<br/>
## Plugin Service
### `PLUGINS_INDEX_URL`
- Type: Optional
- Description: The index address of the LobeChat plugin market. If you have deployed the plugin market service yourself, you can use this variable to override the default plugin market address
- Default: `https://chat-plugins.lobehub.com`
<br/>
## Agent Service
### `AGENTS_INDEX_URL`
- Type: Optional
- Description: The index address of the LobeChat role market. If you have deployed the role market service yourself, you can use this variable to override the default plugin market address
- Default: `https://chat-agents.lobehub.com`
<br/>
## Data Analytics
### Posthog Analytics
#### `NEXT_PUBLIC_ANALYTICS_POSTHOG`
- Type: Optional
- Description: Environment variable to enable \[PostHog Analytics]\[posthog-analytics-url]. Set to `1` to enable PostHog Analytics.
- Default: -
- Example: `1`
#### `NEXT_PUBLIC_POSTHOG_KEY`
- Type: Optional
- Description: Set the PostHog project key.
- Default: -
- Example: `phc_xxxxxxxx`
#### `NEXT_PUBLIC_POSTHOG_HOST`
- Type: Optional
- Description: Set the deployment address of the PostHog service. Default is the official SAAS address.
LobeChat is a open-source, extensible ([Function Calling][fc-url]), high-performance chatbot framework. <br/> It supports one-click free deployment of your private ChatGPT/LLM web application.
- [Plugin Deployment and Publication](#plugin-deployment-and-publication)
- [Plugin Shield](#plugin-shield)
- [Link](#link)
## Plugin Composition
A LobeChat plugin consists of the following components:
1.**Plugin Index**: Used to display basic information about the plugin, including the plugin name, description, author, version, and a link to the plugin manifest. The official plugin index can be found at [lobe-chat-plugins](https://github.com/lobehub/lobe-chat-plugins). To submit a plugin to the official plugin marketplace, you need to submit a PR to this repository.
2.**Plugin Manifest**: Used to describe the functionality of the plugin, including the server-side description, frontend display information, and version number. For more details about the manifest, please refer to the [manifest][manifest-docs-url].
3.**Plugin Services**: Used to implement the server-side and frontend modules described in the manifest:
- **Server-side**: Implement the API capabilities described in the manifest.
- **Frontend UI** (optional): Implement the interface described in the manifest, which will be displayed in plugin messages to provide richer information display than plain text.
<br/>
## Custom Plugin Workflow
To integrate a plugin into LobeChat, you need to add and use a custom plugin in LobeChat. This section will guide you through the process.
### **`1`** Create and Start a Plugin Project
First, you need to create a plugin project locally. You can use the [lobe-chat-plugin-template][lobe-chat-plugin-template-url] template we have prepared:
When you see `ready started server on 0.0.0.0:3400, url: http://localhost:3400`, it means that the plugin service has been successfully started locally.
Enter `http://localhost:3400/manifest-dev.json` in the `Plugin Manifest URL` field, which is the URL of the locally started plugin manifest.
At this point, you should see that the identifier of the plugin has been automatically recognized as `chat-plugin-template`. Then fill in the remaining form fields (only the title is required) and click the <kbd>Save</kbd> button to complete the custom plugin addition.
After adding the plugin, you can see the newly added plugin in the plugin list. If you need to modify the plugin's configuration, you can click the <kbd>Settings</kbd> button to make changes.
### **`3`** Test the Plugin Functionality in a Session
Next, we need to test the functionality of the custom plugin.
Click the <kbd>Back</kbd> button to go back to the session area, and then send a message to the assistant: "What should I wear?" The assistant will try to ask you about your gender and current mood.
After answering, the assistant will make a plugin call to retrieve recommended clothing data based on your gender and mood from the server and push it to you. Finally, it will summarize the information in a text response.
After completing these steps, you have learned the basic process of adding and using a custom plugin in LobeChat.
<br/>
## Local Plugin Development
In the previous workflow, we have learned how to add and use a plugin. Now let's focus on the development process of custom plugins.
### Manifest
The manifest aggregates information about how the plugin's functionality is implemented. The core fields are `api` and `ui`, which describe the server-side API capabilities and the frontend rendering interface address of the plugin, respectively.
Taking the manifest in our template as an example:
```json
{
"api":[
{
"url":"http://localhost:3400/api/clothes",
"name":"recommendClothes",
"description":"Recommend clothes based on the user's mood",
"parameters":{
"properties":{
"mood":{
"description":"The user's current mood, with optional values: happy, sad, anger, fear, surprise, disgust",
"description":"The gender of the user, which needs to be asked before knowing this information"
}
},
"required":["mood","gender"],
"type":"object"
}
}
],
"gateway":"http://localhost:3400/api/gateway",
"identifier":"chat-plugin-template",
"ui":{
"url":"http://localhost:3400",
"height":200
},
"version":"1"
}
```
In this manifest, the following parts are included:
1.`identifier`: This is the unique identifier of the plugin, used to distinguish different plugins. This field needs to be globally unique.
2.`api`: This is an array that contains all the API interface information provided by the plugin. Each interface includes the `url`, `name`, `description`, and `parameters` fields, all of which are required. The `description` and `parameters` fields will be sent to GPT as the `functions` parameter of the [Function Call](https://sspai.com/post/81986). The parameters need to comply with the [JSON Schema](https://json-schema.org/) specification. In this example, the API interface is named `recommendClothes`, which recommends clothes based on the user's mood and gender. The parameters of the interface include the user's mood and gender, both of which are required.
3.`ui`: This field contains information about the plugin's user interface, indicating where LobeChat loads the frontend interface of the plugin from. Since the plugin interface loading in LobeChat is implemented based on `iframe`, you can specify the height and width of the plugin interface as needed.
4.`gateway`: This field specifies the gateway for LobeChat to query API interfaces. The default plugin gateway in LobeChat is a cloud service, but for custom plugins, the requests need to be sent to the local service. Therefore, by specifying the gateway in the manifest, LobeChat will directly request this address and access the local plugin service. The gateway field does not need to be specified for plugins published online.
5.`version`: This is the version number of the plugin, which is currently not used.
In actual development, you can modify the plugin's manifest according to your needs to declare the functionality you want to implement. For a complete introduction to each field in the manifest, please refer to: [manifest][manifest-docs-url].
### Project Structure
The [lobe-chat-plugin-template][lobe-chat-plugin-template-url] template project uses Next.js as the development framework. Its core directory structure is as follows:
```
➜ chat-plugin-template
├── public
│ └── manifest-dev.json # Manifest file
├── src
│ └── pages
│ │ ├── api # Next.js server-side folder
│ │ │ ├── clothes.ts # Implementation of the recommendClothes interface
│ │ │ └── gateway.ts # Local plugin proxy gateway
│ │ └── index.tsx # Frontend display interface
```
Of course, using Next.js as the development framework in the template is just because we are familiar with Next.js and it is convenient for development. You can use any frontend framework and programming language you are familiar with as long as it can implement the functionality described in the manifest.
We also welcome contributions of plugin templates in more frameworks and languages.
### Server-side
The server-side only needs to implement the API interfaces described in the manifest. In the template, we use Vercel's [Edge Runtime](https://nextjs.org/docs/pages/api-reference/edge) as the server, which eliminates the need for operational maintenance.
#### API Implementation
For Edge Runtime, we provide the `createErrorResponse` method in `@lobehub/chat-plugin-sdk` to quickly return error responses. The currently provided error types can be found at: [PluginErrorType][plugin-error-type-url].
Here is an example of the clothes API implementation in the template:
In this example, `manClothes` and `womanClothes` are hardcoded mock data. In actual scenarios, they can be replaced with database queries.
#### Gateway
Since the default plugin gateway in LobeChat is a cloud service (\</api/plugins>), which sends requests to the API addresses specified in the manifest to solve the cross-origin issue.
For custom plugins, the requests need to be sent to the local service. Therefore, by specifying the gateway in the manifest (<http://localhost:3400/api/gateway>), LobeChat will directly request this address. Then you only need to create a gateway implementation at this address.
[`@lobehub/chat-plugins-gateway`](https://github.com/lobehub/chat-plugins-gateway) includes the implementation of the plugin gateway in LobeChat, which you can use to create a gateway. This allows LobeChat to access the local plugin service.
### Plugin UI Interface
For a plugin, the UI interface is optional. For example, the [Web Crawler](https://github.com/lobehub/chat-plugin-web-crawler) plugin does not provide a corresponding user interface.
If you want to display richer information in plugin messages or include some rich interactions, you can define a user interface for the plugin. For example, the following image shows the user interface of a search engine plugin.
LobeChat uses `iframe` + `postMessage` to load and communicate with plugin UI. Therefore, the implementation of the plugin UI is the same as normal web development. You can use any frontend framework and programming language you are familiar with.
In our template, we use React + Next.js + antd as the frontend framework. You can find the implementation of the user interface in `src/pages/index.tsx`.
Regarding plugin communication, we provide related methods in [`@lobehub/chat-plugin-sdk`](https://github.com/lobehub/chat-plugin-sdk) to simplify the communication between the plugin and LobeChat. You can use the `fetchPluginMessage` method to actively retrieve the data of the current message from LobeChat. For a detailed description of this method, please refer to: [fetchPluginMessage][fetch-plugin-message-url].
// Retrieve the current plugin message from LobeChat
fetchPluginMessage().then((e: ResponseData)=>{
setData(e);
});
},[]);
return<>...</>;
});
exportdefaultRender;
```
<br/>
## Plugin Deployment and Publication
After completing the plugin development, you can deploy the plugin using your preferred method. For example, you can use Vercel or package it as a Docker image for publication.
If you want more people to use your plugin, you are welcome to submit it for review in the plugin marketplace.
# Maintaining Updates with LobeChat Self-Deployment
If you have deployed your own project following the one-click deployment steps in the README, you might encounter constant prompts indicating "updates available". This is because Vercel defaults to creating a new project instead of forking this one, resulting in an inability to accurately detect updates. We suggest you redeploy using the following steps:
- Remove the original repository;
- Use the <kbd>Fork</kbd> button at the top right corner of the page to fork this project;
- Re-select and deploy on `Vercel`.
## Enabling Automatic Updates
> **Note**\
> If you encounter an error executing Upstream Sync, manually Sync Fork once
Once you have forked the project, due to Github restrictions, you will need to manually enable Workflows on the Actions page of your forked project and activate the Upstream Sync Action. Once enabled, you can set up hourly automatic updates.
title: Integrating Data Analytics Services in LobeChat for User Usage Analysis
description: >-
Learn how to integrate free/open-source data analytics services in LobeChat to
collect user usage data efficiently.
tags:
- LobeChat
- data analytics
- user usage analysis
- Vercel Analytics
- web analytics
---
# Data Analysis
To better help analyze the usage of LobeChat users, we have integrated several free/open-source data analytics services in LobeChat for collecting user usage data, which you can enable as needed.
<Callout type={'warning'}>
Currently, the integrated data analytics platforms only support deployment and usage on
Vercel/Zeit platforms and do not support Docker/Docker Compose deployment.
</Callout>
## Vercel Analytics
[Vercel Analytics](https://vercel.com/analytics) is a data analytics service launched by Vercel, which can help you collect website visit data, including traffic, sources, and devices used for access.
We have integrated Vercel Analytics into the code, and you can enable it by setting the environment variable `ENABLE_VERCEL_ANALYTICS=1`, and then open the Analytics tab in your Vercel deployment project to view your app's visit data.
Vercel Analytics provides 2500 free Web Analytics Events per month (which can be understood as page views), which is generally sufficient for personal deployment and self-use products.
If you need to learn more about using Vercel Analytics, please refer to the [Vercel Web Analytics Quick Start](https://vercel.com/docs/analytics/quickstart).
LobeChat Identity Verification Service - Centralized User Authorization
Management
description: >-
Learn about LobeChat's support for configuring external identity verification
services for centralized user authorization within enterprises/organizations.
Explore supported services like Auth0, Microsoft Entra ID, Authentik, Github,
and ZITADEL.
tags:
- Identity Verification Service
- Centralized User Authorization
- SSO Providers
- Auth0
- Microsoft Entra ID
- Authentik
- Github
- ZITADEL
---
# Identity Verification Service
LobeChat supports the configuration of external identity verification services for internal use within enterprises/organizations to centrally manage user authorization.
Currently supported identity verification services include:
Click on the links to view the corresponding platform's configuration documentation.
## Advanced Configuration
To simultaneously enable multiple identity verification sources, please set the `SSO_PROVIDERS` environment variable, separating them with commas, for example, `auth0,azure-ad,authentik`.
The order corresponds to the display order of the SSO providers.
| SSO Provider | Value |
| ------------------ | ----------- |
| Auth0 | `auth0` |
| Microsoft Entra ID | `azure-ad` |
| Authentik | `authentik` |
| Github | `github` |
| ZITADEL | `zitadel` |
## Other SSO Providers
Please refer to the [NextAuth.js](https://next-auth.js.org/providers) documentation and feel free to submit a Pull Request.
title: Customizing Provider Model List in LobeChat for Deployment
description: >-
Learn how to customize the model list in LobeChat for deployment with the
syntax and extension capabilities
tags:
- LobeChat
- model customization
- deployment
- extension capabilities
---
# Model List
LobeChat supports customizing the model list during deployment. You can use `+` to add a model, `-` to hide a model, and use `model name=display name<extension configuration>` to customize the display name of a model, separated by English commas. The basic syntax is as follows:
For example: `+qwen-7b-chat,+glm-6b,-gpt-3.5-turbo,gpt-4-0125-preview=gpt-4-turbo`
In the above example, it adds `qwen-7b-chat` and `glm-6b` to the model list, removes `gpt-3.5-turbo` from the list, and displays the model name of `gpt-4-0125-preview` as `gpt-4-turbo`. If you want to disable all models first and then enable specific models, you can use `-all,+gpt-3.5-turbo`, which means only enabling `gpt-3.5-turbo`.
## Extension Capabilities
Considering the diversity of model capabilities, we started to add extension configuration in version `0.147.8`, with the following rules:
```shell
id=displayName<maxToken:vision:fc:file>
```
The first value in angle brackets is designated as the `maxToken` for this model. The second value and beyond are the model's extension capabilities, separated by colons `:`, and the order is not important.
Examples are as follows:
- `chatglm-6b=ChatGLM 6B<4096>`: ChatGLM 6B, maximum context of 4k, no advanced capabilities;
- `spark-v3.5=讯飞星火 v3.5<8192:fc>`: Xunfei Spark 3.5 model, maximum context of 8k, supports Function Call;
- `gemini-pro-vision=Gemini Pro Vision<16000:vision>`: Google Vision model, maximum context of 16k, supports image recognition;
- `gpt-4-all=ChatGPT Plus<128000:fc:vision:file>`, hacked version of ChatGPT Plus web, context of 128k, supports image recognition, Function Call, file upload.
title: Configure Auth0 Identity Verification Service for LobeChat
description: >-
Learn how to configure Auth0 Identity Verification Service for LobeChat for
your organization, including creating applications, adding users, and
configuring environment variables.
tags:
- Auth0
- Identity Verification
- Single Sign-On
- Environment Variables
- User Management
- SSO Integrations
- Social Login
---
# Configure Auth0 Identity Verification Service
<Steps>
### Create Auth0 Application
Register and log in to [Auth0][auth0-client-page], click on the "Applications" in the left navigation bar to switch to the application management interface, and click "Create Application" in the upper right corner to create an application.
After successful creation, click on the corresponding application to enter the application details page, switch to the "Settings" tab, and you can see the corresponding configuration information.
You can fill in or modify Allowed Callback URLs after deployment, but make sure the filled URL is
consistent with the deployed URL.
</Callout>
### Add Users
Click on the "Users Management" in the left navigation bar to enter the user management interface, where you can create users for your organization to log in to LobeChat.
When deploying LobeChat, you need to configure the following environment variables:
| Environment Variable | Type | Description |
| --- | --- | --- |
| `ENABLE_OAUTH_SSO` | Required | Enable single sign-on (SSO) for LobeChat. Set to `1` to enable single sign-on. |
| `NEXTAUTH_SECRET` | Required | Key used to encrypt Auth.js session tokens. You can generate a key using the following command: `openssl rand -base64 32` |
| `SSO_PROVIDERS` | Optional | Select the single sign-on provider for LoboChat. Use `auth0` for Auth0. |
| `AUTH0_CLIENT_ID` | Required | Client ID of the Auth0 application |
| `AUTH0_CLIENT_SECRET` | Required | Client Secret of the Auth0 application |
| `AUTH0_ISSUER` | Required | Domain of the Auth0 application, `https://example.auth0.com` |
| `ACCESS_CODE` | Required | Add a password to access this service. You can set a sufficiently long random password to "disable" access code authorization. |
| `NEXTAUTH_URL` | Optional | The URL is used to specify the callback address for the execution of OAuth authentication in Auth.js. It needs to be set only when the default address is incorrect. `https://example.com/api/auth` |
<Callout type={'tip'}>
You can refer to the related variable details at [📘Environment Variables](/docs/self-hosting/environment-variable#auth0).
</Callout>
</Steps>
<Callout>
After successful deployment, users will be able to authenticate and use LobeChat using the users
configured in Auth0.
</Callout>
## Advanced Configuration
### Connecting to an Existing Single Sign-On Service
If your enterprise or organization already has a unified identity authentication infrastructure, you can connect to an existing single sign-on service in Applications -> SSO Integrations.
Auth0 supports single sign-on services such as Azure Active Directory, Slack, Google Workspace, Office 365, Zoom, and more. For a detailed list of supported services, please refer to [this link][auth0-sso-integrations].
<Image
alt="Connecting to an Existing Single Sign-On Service"
After the creation is successful, click **Applications** on the left -> **Create**, fill in the name and Slug, select the provider created in the previous step, and click **Create**.
After the application provider is created, click the corresponding provider to enter the details page, click **Edit**, and save the `Client ID` and `Client Secret`.
Copy the URL of `OpenID Configuration Issuer` and save it.
### Configure Environment Variables
When deploying LobeChat, you need to configure the following environment variables:
| Environment Variable | Type | Description |
| --- | --- | --- |
| `ENABLE_OAUTH_SSO` | Required | Enable Single Sign-On (SSO) for LobeChat. Set to `1` to enable SSO. |
| `NEXTAUTH_SECRET` | Required | The secret used to encrypt Auth.js session tokens. You can generate a secret using the following command: `openssl rand -base64 32` |
| `SSO_PROVIDERS` | Required | Select the SSO provider for LoboChat. Use `authentik` for Authentik. |
| `AUTHENTIK_CLIENT_ID` | Required | The Client ID from the Authentik application provider details page |
| `AUTHENTIK_CLIENT_SECRET` | Required | The Client Secret from the Authentik application provider details page |
| `AUTHENTIK_ISSUER` | Required | The OpenID Configuration Issuer from the Authentik application provider details page |
| `ACCESS_CODE` | Required | Add a password to access this service, you can set a sufficiently long random password to "disable" access code authorization |
| `NEXTAUTH_URL` | Optional | This URL is used to specify the callback address for Auth.js when performing OAuth authentication. It only needs to be set when the default generated redirect address is incorrect. `https://example.com/api/auth` |
<Callout type={'tip'}>
Go to [📘 Environment Variables](/docs/self-hosting/environment-variable#Authentik) for details about the variables.
</Callout>
</Steps>
<Callout type={'info'}>
After a successful deployment, users will be able to use LobeChat by authenticating with the users
When deploying LobeChat, you need to configure the following environment variables:
| Environment Variable | Type | Description |
| --- | --- | --- |
| `ENABLE_OAUTH_SSO` | Required | Enable Single Sign-On (SSO) for LobeChat. Set to `1` to enable SSO. |
| `NEXTAUTH_SECRET` | Required | Key used to encrypt Auth.js session tokens. You can generate the key using the command: `openssl rand -base64 32` |
| `SSO_PROVIDERS` | Required | Select the Single Sign-On provider for LobeChat. Use `github` for Github. |
| `GITHUB_CLIENT_ID` | Required | Client ID in the Github App details page. |
| `GITHUB_CLIENT_SECRET` | Required | Client Secret in the Github App details page. |
| `ACCESS_CODE` | Required | Add a password for accessing this service. You can set a long random password to "disable" access code authorization. |
| `NEXTAUTH_URL` | Optional | This URL is used to specify the callback address for Auth.js when performing OAuth authentication. Only set it if the default generated redirect address is incorrect. `https://example.com/api/auth` |
<Callout type={'tip'}>
Go to [📘 Environment Variables](/docs/self-hosting/environment-variable#Github) for detailed
information on these variables.
</Callout>
</Steps>
<Callout type={'info'}>
After successful deployment, users will be able to authenticate with Github and use LobeChat.
Some files were not shown because too many files have changed in this diff
Show More
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.