chore: optimize code (#1328)
This commit is contained in:
parent
ddc7066f4e
commit
20aa35f209
|
@ -27,7 +27,7 @@ const timeoutMs: number = !isNaN(+process.env.TIMEOUT_MS) ? +process.env.TIMEOUT
|
|||
const disableDebug: boolean = process.env.OPENAI_API_DISABLE_DEBUG === 'true'
|
||||
|
||||
let apiModel: ApiModel
|
||||
let model = 'gpt-3.5-turbo'
|
||||
const model = isNotEmptyString(process.env.OPENAI_API_MODEL) ? process.env.OPENAI_API_MODEL : 'gpt-3.5-turbo'
|
||||
|
||||
if (!isNotEmptyString(process.env.OPENAI_API_KEY) && !isNotEmptyString(process.env.OPENAI_ACCESS_TOKEN))
|
||||
throw new Error('Missing OPENAI_API_KEY or OPENAI_ACCESS_TOKEN environment variable')
|
||||
|
@ -39,8 +39,6 @@ let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI
|
|||
|
||||
if (isNotEmptyString(process.env.OPENAI_API_KEY)) {
|
||||
const OPENAI_API_BASE_URL = process.env.OPENAI_API_BASE_URL
|
||||
const OPENAI_API_MODEL = process.env.OPENAI_API_MODEL
|
||||
model = isNotEmptyString(OPENAI_API_MODEL) ? OPENAI_API_MODEL : 'gpt-3.5-turbo'
|
||||
|
||||
const options: ChatGPTAPIOptions = {
|
||||
apiKey: process.env.OPENAI_API_KEY,
|
||||
|
@ -70,19 +68,13 @@ let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI
|
|||
apiModel = 'ChatGPTAPI'
|
||||
}
|
||||
else {
|
||||
const OPENAI_API_MODEL = process.env.OPENAI_API_MODEL
|
||||
const options: ChatGPTUnofficialProxyAPIOptions = {
|
||||
accessToken: process.env.OPENAI_ACCESS_TOKEN,
|
||||
apiReverseProxyUrl: isNotEmptyString(process.env.API_REVERSE_PROXY) ? process.env.API_REVERSE_PROXY : 'https://bypass.churchless.tech/api/conversation',
|
||||
model,
|
||||
debug: !disableDebug,
|
||||
}
|
||||
|
||||
if (isNotEmptyString(OPENAI_API_MODEL))
|
||||
options.model = OPENAI_API_MODEL
|
||||
|
||||
options.apiReverseProxyUrl = isNotEmptyString(process.env.API_REVERSE_PROXY)
|
||||
? process.env.API_REVERSE_PROXY
|
||||
: 'https://bypass.churchless.tech/api/conversation'
|
||||
|
||||
setupProxy(options)
|
||||
|
||||
api = new ChatGPTUnofficialProxyAPI({ ...options })
|
||||
|
|
Loading…
Reference in New Issue