Skip to content

Commit

Permalink
✨ feat: add Environment Variable for custom model name when deploying (
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx authored Nov 8, 2023
1 parent 3618de3 commit 15f9fa2
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 20 deletions.
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -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 ############
Expand Down
39 changes: 32 additions & 7 deletions docs/Environment-Variable.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -26,18 +28,23 @@ 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

### `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: -
- Default: `-`
- Example: `sk-xxxxxx...xxxxxx`

### `OPENAI_PROXY_URL`
Expand All @@ -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`
Expand Down Expand Up @@ -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`
Expand All @@ -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
26 changes: 14 additions & 12 deletions docs/Environment-Variable.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -30,7 +31,12 @@ LobeChat 在部署时提供了一些额外的配置项,使用环境变量进
- 默认值:-
- 示例:`awCT74``e3@09!`

<br/>
### `NEXT_PUBLIC_CUSTOM_MODELS`

- 类型:可选
- 描述:添加自定义模型名称,多个模型需要使用逗号 `,` 隔开。 比如: `gpt-3.5-1106,gpt-4-1106`
- 默认值:`-`
- 示例:`model1,model2,model3`

## OpenAI

Expand Down Expand Up @@ -75,8 +81,6 @@ LobeChat 在部署时提供了一些额外的配置项,使用环境变量进
- 默认值:`2023-08-01-preview`
- 示例:`2023-05-15`,查阅[最新版本][azure-api-verion-url]

<br/>

## 插件服务

### `PLUGINS_INDEX_URL`
Expand All @@ -85,8 +89,6 @@ LobeChat 在部署时提供了一些额外的配置项,使用环境变量进
- 描述:LobeChat 插件市场的索引地址,如果你自行部署了插件市场的服务,可以使用该变量来覆盖默认的插件市场地址
- 默认值:`https://chat-plugins.lobehub.com`

<br/>

## 角色服务

### `AGENTS_INDEX_URL`
Expand All @@ -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
Expand All @@ -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`
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/config/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions src/const/settings.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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,
},
};
Expand Down

0 comments on commit 15f9fa2

Please sign in to comment.