Skip to content

Commit

Permalink
Add timeout env keys
Browse files Browse the repository at this point in the history
  • Loading branch information
memochou1993 committed Feb 10, 2023
1 parent 1c7705b commit 8524df0
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ APP_MAX_USERS=

BOT_NAME=

VERCEL_TIMEOUT=
VERCEL_PROJECT_NAME=gpt-ai-assistant
VERCEL_ACCESS_TOKEN=
VERCEL_DEPLOY_HOOK_URL=

OPENAI_TIMEOUT=
OPENAI_API_KEY=
OPENAI_COMPLETION_MODEL=
OPENAI_COMPLETION_TEMPERATURE=
Expand All @@ -20,5 +22,6 @@ OPENAI_COMPLETION_FREQUENCY_PENALTY=
OPENAI_COMPLETION_PRESENCE_PENALTY=
OPENAI_IMAGE_GENERATION_SIZE=

LINE_TIMEOUT=
LINE_CHANNEL_ACCESS_TOKEN=
LINE_CHANNEL_SECRET=
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 2.3.0 (2023-02-11)

### New Features

- Add `VERCEL_TIMEOUT` environment variable
- Add `OPENAI_TIMEOUT` environment variable
- Add `LINE_TIMEOUT` environment variable

## 2.2.0 (2023-02-04)

### New Features
Expand Down
3 changes: 3 additions & 0 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,19 @@ Name | Default Value | Description
`APP_MAX_GROUPS` | `1` | Maximum groups. The `VERCEL_ACCESS_TOKEN` environment variable is required.
`APP_MAX_USERS` | `5` | Maximum users. The `VERCEL_ACCESS_TOKEN` environment variable is required.
`BOT_NAME` | `AI` | Name of AI Assistant. This is used to call AI Assistant when auto-reply is deactivated.
`VERCEL_TIMEOUT` | 9000 | Timeout for Vercel API calls.
`VERCEL_PROJECT_NAME` | `gpt-ai-assistant` | Custom Vercel project name. You can use this environment variable when the Vercel project name differs from the GitHub project name.
`VERCEL_ACCESS_TOKEN` | `null` | Vercel [access token](/demo/vercel-access-token.png)
`VERCEL_DEPLOY_HOOK_URL` | `null` | Vercel [deploy hook URL](/demo/vercel-deploy-hook-url.png)
`OPENAI_TIMEOUT` | 9000 | Timeout for OpenAI API calls.
`OPENAI_API_KEY` | `null` | OpenAI [API key](/demo/openai-api-key.png)
`OPENAI_COMPLETION_MODEL` | `text-davinci-003` | Refer to [model](https://beta.openai.com/docs/api-reference/completions/create#completions/create-model) parameter for details.
`OPENAI_COMPLETION_TEMPERATURE` | `0.9` | Refer to [temperature](https://beta.openai.com/docs/api-reference/completions/create#completions/create-temperature) parameter for details.
`OPENAI_COMPLETION_MAX_TOKENS` | `160` | Refer to [max_tokens](https://beta.openai.com/docs/api-reference/completions/create#completions/create-max_tokens) parameter for details.
`OPENAI_COMPLETION_FREQUENCY_PENALTY` | `0` | Refer to [frequency_penalty](https://beta.openai.com/docs/api-reference/completions/create#completions/create-frequency_penalty) parameter for details.
`OPENAI_COMPLETION_PRESENCE_PENALTY` | `0.6` | Refer to [presence_penalty](https://beta.openai.com/docs/api-reference/completions/create#completions/create-presence_penalty) parameter for details.
`OPENAI_IMAGE_GENERATION_SIZE` | `256x256` | Refer to [size](https://beta.openai.com/docs/api-reference/images/create#images/create-size) parameter for details.
`LINE_TIMEOUT` | 9000 | Timeout for LINE Messaging API calls.
`LINE_CHANNEL_ACCESS_TOKEN` | `null` | LINE [channel access token](/demo/line-channel-access-token.png)
`LINE_CHANNEL_SECRET` | `null` | LINE [channel secret](/demo/line-channel-secret.png)

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,19 @@ GPT AI Assistant 是基於 OpenAI API 與 LINE Messaging API 實作的應用程
`APP_MAX_GROUPS` | `1` | 群組數量上限,須搭配 `VERCEL_ACCESS_TOKEN` 環境變數。
`APP_MAX_USERS` | `5` | 用戶數量上限,須搭配 `VERCEL_ACCESS_TOKEN` 環境變數。
`BOT_NAME` | `AI` | AI 助理的名字,在關閉自動回覆時用來呼叫。
`VERCEL_TIMEOUT` | 9000 | 呼叫 Vercel API 的超時時間。
`VERCEL_PROJECT_NAME` | `gpt-ai-assistant` | Vercel 的專案名稱。當 Vercel 的專案名稱與 GitHub 的專案名稱不一樣時,可以使用此環境變數指定。
`VERCEL_ACCESS_TOKEN` | `null` | Vercel 的 [access token](/demo/vercel-access-token.png)
`VERCEL_DEPLOY_HOOK_URL` | `null` | Vercel 的 [deploy hook URL](/demo/vercel-deploy-hook-url.png)
`OPENAI_TIMEOUT` | 9000 | 呼叫 OpenAI API 的超時時間。
`OPENAI_API_KEY` | `null` | OpenAI 的 [API key](/demo/openai-api-key.png)
`OPENAI_COMPLETION_MODEL` | `text-davinci-003` | 詳見 [model](https://beta.openai.com/docs/api-reference/completions/create#completions/create-model) 參數說明。
`OPENAI_COMPLETION_TEMPERATURE` | `0.9` | 詳見 [temperature](https://beta.openai.com/docs/api-reference/completions/create#completions/create-temperature) 參數說明。
`OPENAI_COMPLETION_MAX_TOKENS` | `160` | 詳見 [max_tokens](https://beta.openai.com/docs/api-reference/completions/create#completions/create-max_tokens) 參數說明。
`OPENAI_COMPLETION_FREQUENCY_PENALTY` | `0` | 詳見 [frequency_penalty](https://beta.openai.com/docs/api-reference/completions/create#completions/create-frequency_penalty) 參數說明。
`OPENAI_COMPLETION_PRESENCE_PENALTY` | `0.6` | 詳見 [presence_penalty](https://beta.openai.com/docs/api-reference/completions/create#completions/create-presence_penalty) 參數說明。
`OPENAI_IMAGE_GENERATION_SIZE` | `256x256` | 詳見 [size](https://beta.openai.com/docs/api-reference/images/create#images/create-size) 參數說明。
`LINE_TIMEOUT` | 9000 | 呼叫 LINE Messaging API 的超時時間。
`LINE_CHANNEL_ACCESS_TOKEN` | `null` | LINE 的 [channel access token](/demo/line-channel-access-token.png)
`LINE_CHANNEL_SECRET` | `null` | LINE 的 [channel secret](/demo/line-channel-secret.png)

Expand Down
3 changes: 3 additions & 0 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ const config = Object.freeze({
APP_MAX_USERS: Number(env.APP_MAX_USERS) || 5,
BOT_NAME: env.BOT_NAME || 'AI',
VERCEL_ENV: env.VERCEL_ENV || null,
VERCEL_TIMEOUT: env.VERCEL_TIMEOUT || 9000,
VERCEL_PROJECT_NAME: env.VERCEL_PROJECT_NAME || env.VERCEL_GIT_REPO_SLUG || null,
VERCEL_ACCESS_TOKEN: env.VERCEL_ACCESS_TOKEN || null,
VERCEL_DEPLOY_HOOK_URL: env.VERCEL_DEPLOY_HOOK_URL || null,
OPENAI_TIMEOUT: env.OPENAI_TIMEOUT || 9000,
OPENAI_API_KEY: env.OPENAI_API_KEY || null,
OPENAI_COMPLETION_MODEL: env.OPENAI_COMPLETION_MODEL || 'text-davinci-003',
OPENAI_COMPLETION_TEMPERATURE: Number(env.OPENAI_COMPLETION_TEMPERATURE) || 0.9,
OPENAI_COMPLETION_MAX_TOKENS: Number(env.OPENAI_COMPLETION_MAX_TOKENS) || 160,
OPENAI_COMPLETION_FREQUENCY_PENALTY: Number(env.OPENAI_COMPLETION_FREQUENCY_PENALTY) || 0,
OPENAI_COMPLETION_PRESENCE_PENALTY: Number(env.OPENAI_COMPLETION_PRESENCE_PENALTY) || 0.6,
OPENAI_IMAGE_GENERATION_SIZE: env.OPENAI_IMAGE_GENERATION_SIZE || '256x256',
LINE_TIMEOUT: env.LINE_TIMEOUT || 9000,
LINE_CHANNEL_ACCESS_TOKEN: env.LINE_CHANNEL_ACCESS_TOKEN || null,
LINE_CHANNEL_SECRET: env.LINE_CHANNEL_SECRET || null,
});
Expand Down
2 changes: 1 addition & 1 deletion services/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const QUICK_REPLY_TYPE_ACTION = 'action';

const instance = axios.create({
baseURL: 'https://api.line.me',
timeout: 9 * 1000,
timeout: config.LINE_TIMEOUT,
headers: {
'Accept-Encoding': 'gzip, deflate, compress',
},
Expand Down
2 changes: 1 addition & 1 deletion services/openai.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const IMAGE_SIZE_1024 = '1024x1024';

const instance = axios.create({
baseURL: 'https://api.openai.com',
timeout: 9 * 1000,
timeout: config.OPENAI_TIMEOUT,
headers: {
'Accept-Encoding': 'gzip, deflate, compress',
},
Expand Down
2 changes: 1 addition & 1 deletion services/vercel.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const ENV_TARGET_DEVELOPMENT = 'development';

const instance = axios.create({
baseURL: 'https://api.vercel.com',
timeout: 9 * 1000,
timeout: config.VERCEL_TIMEOUT,
headers: {
'Accept-Encoding': 'gzip, deflate, compress',
},
Expand Down

0 comments on commit 8524df0

Please sign in to comment.