feat: add Environment Variable for custom model name when deploying (#429)

This commit is contained in:
Arvin Xu
2023-11-08 12:32:52 +08:00
committed by GitHub
parent 3618de30f4
commit 15f9fa273e
5 changed files with 57 additions and 20 deletions
+4 -1
View File
@@ -1,7 +1,10 @@
# add a access code to lock your lobe-chat application, it should be a six length string
ACCESS_CODE=lobe66
# only choose one from OpenAI Service and Azure OpenAI Service
# add your custom model name, multi model seperate by comma. for example gpt-3.5-1106,gpt-4-1106
# NEXT_PUBLIC_CUSTOM_MODELS=model1,model2,model3
# ---- only choose one from OpenAI Service and Azure OpenAI Service ---- #
########################################
############ OpenAI Service ############
+32 -7
View File
@@ -6,6 +6,7 @@ LobeChat provides additional configuration options during deployment, which can
- [General Variables](#general-variables)
- [`ACCESS_CODE`](#access_code)
- [`NEXT_PUBLIC_CUSTOM_MODELS`](#next_public_custom_models)
- [OpenAI](#openai)
- [`OPENAI_API_KEY`](#openai_api_key)
- [`OPENAI_PROXY_URL`](#openai_proxy_url)
@@ -18,6 +19,7 @@ LobeChat provides additional configuration options during deployment, which can
- [Agent Service](#agent-service)
- [`AGENTS_INDEX_URL`](#agents_index_url)
- [Data Analytics](#data-analytics)
- [Vercel Analytics](#vercel-analytics)
- [Posthog Analytics](#posthog-analytics)
## General Variables
@@ -26,10 +28,15 @@ LobeChat provides additional configuration options during deployment, which can
- Type: Optional
- Description: Add a password to access the LobeChat service, the password should be 6 digits or letters
- Default: -
- Default: `-`
- Example: `awCT74` or `e3@09!`
<br/>
### `NEXT_PUBLIC_CUSTOM_MODELS`
- Type: Optional
- Description: add your custom model name, multi model seperate by comma. for example: `gpt-3.5-1106,gpt-4-1106`
- Default: `-`
- Example: `model1,model2,model3`
## OpenAI
@@ -37,7 +44,7 @@ LobeChat provides additional configuration options during deployment, which can
- 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: -
- Default: `-`
- Example: `sk-xxxxxx...xxxxxx`
### `OPENAI_PROXY_URL`
@@ -57,14 +64,14 @@ If you need to use Azure OpenAI to provide model services, you can refer to the
- Type: Optional
- Description: Set this value to `1` to enable Azure OpenAI configuration
- Default: -
- Default: `-`
- Example: `1`
### `AZURE_API_KEY`
- Type: Optional
- Description: This is the API key you apply for on the Azure OpenAI account page
- Default: -
- Default: `-`
- Example: `c55168be3874490ef0565d9779ecd5a6`
### `AZURE_API_VERSION`
@@ -98,13 +105,29 @@ If you need to use Azure OpenAI to provide model services, you can refer to the
## Data Analytics
### Vercel Analytics
#### `NEXT_PUBLIC_ANALYTICS_VERCEL`
- Type: Optional
- Description: Environment variable to enable [Vercel Analytics][vercel-analytics-url]. Set to `1` to enable Vercel Analytics.
- Default: `-`
- Example: `1`
#### `NEXT_PUBLIC_VERCEL_DEBUG`
- Type: Optional
- Description: Enable debug mode for Vercel Analytics.
- Default: `-`
- Example: `1`
### 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: -
- Description: Environment variable to enable [PostHog Analytics][posthog-analytics-url]. Set to `1` to enable PostHog Analytics.
- Default: `-`
- Example: `1`
#### `NEXT_PUBLIC_POSTHOG_KEY`
@@ -130,3 +153,5 @@ If you need to use Azure OpenAI to provide model services, you can refer to the
[azure-api-verion-url]: https://docs.microsoft.com/zh-cn/azure/developer/javascript/api-reference/es-modules/azure-sdk/ai-translation/translationconfiguration?view=azure-node-latest#api-version
[openai-api-page]: https://platform.openai.com/account/api-keys
[posthog-analytics-url]: https://posthog.com
[vercel-analytics-url]: https://vercel.com/analytics
+14 -12
View File
@@ -6,6 +6,7 @@ LobeChat 在部署时提供了一些额外的配置项,使用环境变量进
- [通用变量](#通用变量)
- [`ACCESS_CODE`](#access_code)
- [`NEXT_PUBLIC_CUSTOM_MODELS`](#next_public_custom_models)
- [OpenAI](#openai)
- [`OPENAI_API_KEY`](#openai_api_key)
- [`OPENAI_PROXY_URL`](#openai_proxy_url)
@@ -30,7 +31,12 @@ LobeChat 在部署时提供了一些额外的配置项,使用环境变量进
- 默认值:-
- 示例:`awCT74``e3@09!`
<br/>
### `NEXT_PUBLIC_CUSTOM_MODELS`
- 类型:可选
- 描述:添加自定义模型名称,多个模型需要使用逗号 `,` 隔开。 比如: `gpt-3.5-1106,gpt-4-1106`
- 默认值:`-`
- 示例:`model1,model2,model3`
## OpenAI
@@ -75,8 +81,6 @@ LobeChat 在部署时提供了一些额外的配置项,使用环境变量进
- 默认值:`2023-08-01-preview`
- 示例:`2023-05-15`,查阅[最新版本][azure-api-verion-url]
<br/>
## 插件服务
### `PLUGINS_INDEX_URL`
@@ -85,8 +89,6 @@ LobeChat 在部署时提供了一些额外的配置项,使用环境变量进
- 描述:LobeChat 插件市场的索引地址,如果你自行部署了插件市场的服务,可以使用该变量来覆盖默认的插件市场地址
- 默认值:`https://chat-plugins.lobehub.com`
<br/>
## 角色服务
### `AGENTS_INDEX_URL`
@@ -102,15 +104,15 @@ LobeChat 在部署时提供了一些额外的配置项,使用环境变量进
#### `NEXT_PUBLIC_ANALYTICS_VERCEL`
- 类型:可选
- 描述:用于配置 Vercel Analytics 的环境变量,当设为 `0` 则关闭 Vercel Analytics
- 默认值: -
- 示例:`0`
- 描述:用于配置 Vercel Analytics 的环境变量,当设为 `1` 时开启 Vercel Analytics
- 默认值: `-`
- 示例:`1`
#### `NEXT_PUBLIC_VERCEL_DEBUG`
- 类型:可选
- 描述:用于开启 Vercel Analytics 的调试模式
- 默认值: -
- 默认值: `-`
- 示例:`1`
### Posthog Analytics
@@ -119,14 +121,14 @@ LobeChat 在部署时提供了一些额外的配置项,使用环境变量进
- 类型:可选
- 描述:用于开启 [PostHog Analytics][posthog-analytics-url] 的环境变量,设为 `1` 时开启 PostHog Analytics
- 默认值: -
- 默认值: `-`
- 示例:`1`
#### `NEXT_PUBLIC_POSTHOG_KEY`
- 类型:可选
- 描述:设置 PostHog 项目 Key
- 默认值: -
- 默认值: `-`
- 示例:`phc_xxxxxxxx`
#### `NEXT_PUBLIC_POSTHOG_HOST`
@@ -140,7 +142,7 @@ LobeChat 在部署时提供了一些额外的配置项,使用环境变量进
- 类型:可选
- 描述:开启 PostHog 的调试模式
- 默认值: -
- 默认值: `-`
- 示例:`1`
[azure-api-verion-url]: https://docs.microsoft.com/zh-cn/azure/developer/javascript/api-reference/es-modules/azure-sdk/ai-translation/translationconfiguration?view=azure-node-latest#api-version
+4
View File
@@ -7,6 +7,8 @@ declare global {
AGENTS_INDEX_URL?: string;
PLUGINS_INDEX_URL?: string;
NEXT_PUBLIC_CUSTOM_MODELS?: string;
NEXT_PUBLIC_ANALYTICS_VERCEL?: string;
NEXT_PUBLIC_VERCEL_DEBUG?: string;
@@ -33,6 +35,8 @@ declare global {
export const getClientConfig = () => ({
AGENTS_INDEX_URL: process.env.AGENTS_INDEX_URL,
PLUGINS_INDEX_URL: process.env.PLUGINS_INDEX_URL,
// custom model names
CUSTOM_MODELS: process.env.NEXT_PUBLIC_CUSTOM_MODELS,
// Vercel Analytics
ANALYTICS_VERCEL: process.env.NEXT_PUBLIC_ANALYTICS_VERCEL === '1',
+3
View File
@@ -1,3 +1,4 @@
import { getClientConfig } from '@/config/client';
import { DEFAULT_OPENAI_MODEL_LIST } from '@/const/llm';
import { DEFAULT_AGENT_META } from '@/const/meta';
import { LanguageModel } from '@/types/llm';
@@ -34,6 +35,8 @@ export const DEFAULT_AGENT_CONFIG: LobeAgentConfig = {
export const DEFAULT_LLM_CONFIG: GlobalLLMConfig = {
openAI: {
OPENAI_API_KEY: '',
// support user custom model names with env var
customModelName: getClientConfig().CUSTOM_MODELS,
models: DEFAULT_OPENAI_MODEL_LIST,
},
};