From 4ae57ee075126364fa4c084c528313ae95d9184a Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Sat, 11 Mar 2023 20:40:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20openAiBaseUrl=E4=B8=BA=E7=A9=BA=E7=9A=84?= =?UTF-8?q?=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/common.js | 2 +- utils/dalle.js | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/utils/common.js b/utils/common.js index 13b5bdc..a2d5182 100644 --- a/utils/common.js +++ b/utils/common.js @@ -363,7 +363,7 @@ export async function isCN () { try { let response = await fetch('https://ipinfo.io/country') let countryCode = (await response.text()).trim() - await redis.set('CHATGPT:COUNTRY_CODE', countryCode, { EX: 3600 * 24 * 7 }) + await redis.set('CHATGPT:COUNTRY_CODE', countryCode, { EX: 3600 }) if (countryCode !== 'CN') { return false } diff --git a/utils/dalle.js b/utils/dalle.js index 0b627fa..361eee5 100644 --- a/utils/dalle.js +++ b/utils/dalle.js @@ -1,7 +1,7 @@ import { Configuration, OpenAIApi } from 'openai' -import {Config, defaultOpenAIReverseProxy, officialChatGPTAPI} from './config.js' +import {Config, defaultOpenAIAPI, defaultOpenAIReverseProxy, officialChatGPTAPI} from './config.js' import fs from 'fs' -import { mkdirs } from './common.js' +import {isCN, mkdirs} from './common.js' let proxy if (Config.proxy) { try { @@ -24,7 +24,7 @@ export async function createImage (prompt, n = 1, size = '512x512') { basePath = defaultOpenAIReverseProxy } if (!Config.openAiBaseUrl) { - basePath = defaultOpenAIReverseProxy + basePath = await isCN() ? defaultOpenAIReverseProxy : defaultOpenAIAPI } const configuration = new Configuration({ apiKey: Config.apiKey, @@ -54,7 +54,7 @@ export async function imageVariation (imageUrl, n = 1, size = '512x512') { basePath = defaultOpenAIReverseProxy } if (!Config.openAiBaseUrl) { - basePath = defaultOpenAIReverseProxy + basePath = await isCN() ? defaultOpenAIReverseProxy : defaultOpenAIAPI } const configuration = new Configuration({ apiKey: Config.apiKey, @@ -131,7 +131,7 @@ export async function editImage (originalImage, mask = [], prompt, num = 1, size basePath = defaultOpenAIReverseProxy } if (!Config.openAiBaseUrl) { - basePath = defaultOpenAIReverseProxy + basePath = await isCN() ? defaultOpenAIReverseProxy : defaultOpenAIAPI } const configuration = new Configuration({ apiKey: Config.apiKey,