Skip to content

Commit

Permalink
feat: allow user disable openai API debug log (Chanzhaoyu#1041)
Browse files Browse the repository at this point in the history
* feat: allow user disable openai API debug log

* chore: fix pnpm lock
  • Loading branch information
zcong1993 authored and Equim-chan committed Mar 31, 2023
1 parent 64161d6 commit 71cef41
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ pnpm dev
- `OPENAI_API_KEY``OPENAI_ACCESS_TOKEN` 二选一
- `OPENAI_API_MODEL` 设置模型,可选,默认:`gpt-3.5-turbo`
- `OPENAI_API_BASE_URL` 设置接口地址,可选,默认:`https://api.openai.com`
- `OPENAI_API_DISABLE_DEBUG` 设置接口关闭 debug 日志,可选,默认:empty 不关闭

`ACCESS_TOKEN` 可用:

Expand Down
3 changes: 3 additions & 0 deletions service/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ OPENAI_API_BASE_URL=
# OpenAI API Model - https://platform.openai.com/docs/models
OPENAI_API_MODEL=

# set `true` to disable OpenAI API debug log
OPENAI_API_DISABLE_DEBUG=

# Reverse Proxy
API_REVERSE_PROXY=

Expand Down
5 changes: 3 additions & 2 deletions service/src/chatgpt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const ErrorCodeMessage: Record<string, string> = {
}

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

Expand All @@ -45,8 +46,8 @@ let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI
const options: ChatGPTAPIOptions = {
apiKey: process.env.OPENAI_API_KEY,
completionParams: { model },
debug: true,
messageStore,
debug: !disableDebug,
}

// increase max token limit if use gpt-4
Expand All @@ -73,7 +74,7 @@ let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI
else {
const options: ChatGPTUnofficialProxyAPIOptions = {
accessToken: process.env.OPENAI_ACCESS_TOKEN,
debug: true,
debug: !disableDebug,
}

if (isNotEmptyString(process.env.API_REVERSE_PROXY))
Expand Down

0 comments on commit 71cef41

Please sign in to comment.