From a68721fcf29fb8f691576978a591640f55dcb6b1 Mon Sep 17 00:00:00 2001 From: Yifei Zhang Date: Thu, 6 Apr 2023 17:14:19 +0800 Subject: [PATCH 1/3] Update requests.ts --- app/requests.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/requests.ts b/app/requests.ts index 8462f2694..04d801e2e 100644 --- a/app/requests.ts +++ b/app/requests.ts @@ -46,11 +46,10 @@ function getHeaders() { export function requestOpenaiClient(path: string) { return (body: any, method = "POST") => - fetch("/api/openai", { + fetch("/api/openai?_vercel_no_cache=1", { method, headers: { "Content-Type": "application/json", - "Cache-Control": "no-cache", path, ...getHeaders(), }, From 6823839f4b8fd803a2c1074f3fc288222b51a243 Mon Sep 17 00:00:00 2001 From: Yifei Zhang Date: Thu, 6 Apr 2023 17:28:09 +0800 Subject: [PATCH 2/3] fixup --- app/api/openai/route.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/api/openai/route.ts b/app/api/openai/route.ts index cc51dbfc9..3477fc270 100644 --- a/app/api/openai/route.ts +++ b/app/api/openai/route.ts @@ -6,6 +6,7 @@ async function makeRequest(req: NextRequest) { const api = await requestOpenai(req); const res = new NextResponse(api.body); res.headers.set("Content-Type", "application/json"); + res.headers.set("Cache-Control", "no-cache"); return res; } catch (e) { console.error("[OpenAI] ", req.body, e); @@ -16,7 +17,7 @@ async function makeRequest(req: NextRequest) { }, { status: 500, - }, + } ); } } From f7e42179d061a251bad7677af98262f44bc5cd9c Mon Sep 17 00:00:00 2001 From: Yifei Zhang Date: Thu, 6 Apr 2023 17:34:17 +0800 Subject: [PATCH 3/3] fixup --- app/requests.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/requests.ts b/app/requests.ts index 04d801e2e..987434ed4 100644 --- a/app/requests.ts +++ b/app/requests.ts @@ -9,7 +9,7 @@ const makeRequestParam = ( options?: { filterBot?: boolean; stream?: boolean; - }, + } ): ChatRequest => { let sendMessages = messages.map((v) => ({ role: v.role, @@ -76,7 +76,7 @@ export async function requestUsage() { .getDate() .toString() .padStart(2, "0")}`; - const ONE_DAY = 24 * 60 * 60 * 1000; + const ONE_DAY = 2 * 24 * 60 * 60 * 1000; const now = new Date(Date.now() + ONE_DAY); const startOfMonth = new Date(now.getFullYear(), now.getMonth(), 1); const startDate = formatDate(startOfMonth); @@ -84,7 +84,7 @@ export async function requestUsage() { const [used, subs] = await Promise.all([ requestOpenaiClient( - `dashboard/billing/usage?start_date=${startDate}&end_date=${endDate}`, + `dashboard/billing/usage?start_date=${startDate}&end_date=${endDate}` )(null, "GET"), requestOpenaiClient("dashboard/billing/subscription")(null, "GET"), ]); @@ -124,7 +124,7 @@ export async function requestChatStream( onMessage: (message: string, done: boolean) => void; onError: (error: Error, statusCode?: number) => void; onController?: (controller: AbortController) => void; - }, + } ) { const req = makeRequestParam(messages, { stream: true, @@ -213,7 +213,7 @@ export const ControllerPool = { addController( sessionIndex: number, messageId: number, - controller: AbortController, + controller: AbortController ) { const key = this.key(sessionIndex, messageId); this.controllers[key] = controller;