feat: allow user disable openai API debug log (#1041)

* feat: allow user disable openai API debug log

* chore: fix pnpm lock
This commit is contained in:
cong 2023-03-31 11:40:01 +08:00 committed by GitHub
parent 0878af0239
commit 468bed7705
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 1813 additions and 1754 deletions

View File

@ -161,6 +161,7 @@ pnpm dev
- `OPENAI_API_KEY``OPENAI_ACCESS_TOKEN` 二选一 - `OPENAI_API_KEY``OPENAI_ACCESS_TOKEN` 二选一
- `OPENAI_API_MODEL` 设置模型,可选,默认:`gpt-3.5-turbo` - `OPENAI_API_MODEL` 设置模型,可选,默认:`gpt-3.5-turbo`
- `OPENAI_API_BASE_URL` 设置接口地址,可选,默认:`https://api.openai.com` - `OPENAI_API_BASE_URL` 设置接口地址,可选,默认:`https://api.openai.com`
- `OPENAI_API_DISABLE_DEBUG` 设置接口关闭 debug 日志可选默认empty 不关闭
`ACCESS_TOKEN` 可用: `ACCESS_TOKEN` 可用:

File diff suppressed because it is too large Load Diff

View File

@ -10,6 +10,9 @@ OPENAI_API_BASE_URL=
# OpenAI API Model - https://platform.openai.com/docs/models # OpenAI API Model - https://platform.openai.com/docs/models
OPENAI_API_MODEL= OPENAI_API_MODEL=
# set `true` to disable OpenAI API debug log
OPENAI_API_DISABLE_DEBUG=
# Reverse Proxy # Reverse Proxy
API_REVERSE_PROXY= API_REVERSE_PROXY=

File diff suppressed because it is too large Load Diff

View File

@ -25,6 +25,7 @@ const ErrorCodeMessage: Record<string, string> = {
} }
const timeoutMs: number = !isNaN(+process.env.TIMEOUT_MS) ? +process.env.TIMEOUT_MS : 30 * 1000 const timeoutMs: number = !isNaN(+process.env.TIMEOUT_MS) ? +process.env.TIMEOUT_MS : 30 * 1000
const disableDebug: boolean = process.env.OPENAI_API_DISABLE_DEBUG === 'true'
let apiModel: ApiModel let apiModel: ApiModel
@ -44,7 +45,7 @@ let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI
const options: ChatGPTAPIOptions = { const options: ChatGPTAPIOptions = {
apiKey: process.env.OPENAI_API_KEY, apiKey: process.env.OPENAI_API_KEY,
completionParams: { model }, completionParams: { model },
debug: true, debug: !disableDebug,
} }
// increase max token limit if use gpt-4 // increase max token limit if use gpt-4
@ -72,7 +73,7 @@ let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI
const OPENAI_API_MODEL = process.env.OPENAI_API_MODEL const OPENAI_API_MODEL = process.env.OPENAI_API_MODEL
const options: ChatGPTUnofficialProxyAPIOptions = { const options: ChatGPTUnofficialProxyAPIOptions = {
accessToken: process.env.OPENAI_ACCESS_TOKEN, accessToken: process.env.OPENAI_ACCESS_TOKEN,
debug: true, debug: !disableDebug,
} }
if (isNotEmptyString(OPENAI_API_MODEL)) if (isNotEmptyString(OPENAI_API_MODEL))
options.model = OPENAI_API_MODEL options.model = OPENAI_API_MODEL