Refactor Api Common [Server Side] [Console Log]

- [+] refactor(common.ts): remove unnecessary console.log for [Org ID] in requestOpenai function
- [+] refactor(common.ts): conditionally delete OpenAI-Organization header from response if [Org ID] is not set up in ENV
This commit is contained in:
H0llyW00dzZ 2023-12-01 19:48:10 +07:00
parent cf50299b14
commit 36e9c6ac4d
No known key found for this signature in database
GPG Key ID: 05C7FFFC0845C930
1 changed files with 17 additions and 4 deletions

View File

@ -30,10 +30,6 @@ export async function requestOpenai(req: NextRequest) {
console.log("[Proxy] ", path);
console.log("[Base Url]", baseUrl);
// this fix [Org ID] undefined in server side if not using custom point
if (serverConfig.openaiOrgId !== undefined) {
console.log("[Org ID]", serverConfig.openaiOrgId);
}
const timeoutId = setTimeout(
() => {
@ -103,12 +99,29 @@ export async function requestOpenai(req: NextRequest) {
try {
const res = await fetch(fetchUrl, fetchOptions);
// Extract the OpenAI-Organization header from the response
const openaiOrganizationHeader = res.headers.get("OpenAI-Organization");
// Check if serverConfig.openaiOrgId is defined
if (serverConfig.openaiOrgId !== undefined) {
// If openaiOrganizationHeader is present, log it; otherwise, log that the header is not present
console.log("[Org ID]", openaiOrganizationHeader);
} else {
console.log("[Org ID] is not set up.");
}
// to prevent browser prompt for credentials
const newHeaders = new Headers(res.headers);
newHeaders.delete("www-authenticate");
// to disable nginx buffering
newHeaders.set("X-Accel-Buffering", "no");
// Conditionally delete the OpenAI-Organization header from the response if [Org ID] is undefined (not setup in ENV)
// Also This one is to prevent the header from being sent to the client
if (!serverConfig.openaiOrgId) {
newHeaders.delete("OpenAI-Organization");
}
return new Response(res.body, {
status: res.status,
statusText: res.statusText,