From 08b5772420fac883493100b3c2a68b2349d0e446 Mon Sep 17 00:00:00 2001 From: ChenZhaoYu <790348264@qq.com> Date: Fri, 17 Mar 2023 13:19:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9F=A5=E8=AF=A2=E4=BD=99=E9=A2=9D?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=20API=5FBASE=5FURL=20=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/src/chatgpt/index.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/service/src/chatgpt/index.ts b/service/src/chatgpt/index.ts index b76c780..c0994ee 100644 --- a/service/src/chatgpt/index.ts +++ b/service/src/chatgpt/index.ts @@ -102,15 +102,18 @@ async function chatReplyProcess( async function fetchBalance() { const OPENAI_API_KEY = process.env.OPENAI_API_KEY + const OPENAI_API_BASE_URL = process.env.OPENAI_API_BASE_URL + if (!isNotEmptyString(OPENAI_API_KEY)) return Promise.resolve('-') + const API_BASE_URL = isNotEmptyString(OPENAI_API_BASE_URL) + ? OPENAI_API_BASE_URL + : 'https://api.openai.com' + try { - const headers = { - 'Content-Type': 'application/json', - 'Authorization': `Bearer ${OPENAI_API_KEY}`, - } - const response = await axios.get('https://api.openai.com/dashboard/billing/credit_grants', { headers }) + const headers = { 'Content-Type': 'application/json', 'Authorization': `Bearer ${OPENAI_API_KEY}` } + const response = await axios.get(`${API_BASE_URL}/dashboard/billing/credit_grants`, { headers }) const balance = response.data.total_available ?? 0 return Promise.resolve(balance.toFixed(3)) }