Merge pull request #283 from Yidadaa/fix-credit-cache

fix: #277 no cache for credit query
This commit is contained in:
Yifei Zhang 2023-03-31 18:41:21 +08:00 committed by GitHub
commit c70c311989
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,7 +9,7 @@ const makeRequestParam = (
options?: { options?: {
filterBot?: boolean; filterBot?: boolean;
stream?: boolean; stream?: boolean;
}, }
): ChatRequest => { ): ChatRequest => {
let sendMessages = messages.map((v) => ({ let sendMessages = messages.map((v) => ({
role: v.role, role: v.role,
@ -69,10 +69,9 @@ export async function requestChat(messages: Message[]) {
} }
export async function requestUsage() { export async function requestUsage() {
const res = await requestOpenaiClient("dashboard/billing/credit_grants")( const res = await requestOpenaiClient(
null, "dashboard/billing/credit_grants?_vercel_no_cache=1"
"GET", )(null, "GET");
);
try { try {
const response = (await res.json()) as { const response = (await res.json()) as {
@ -94,7 +93,7 @@ export async function requestChatStream(
onMessage: (message: string, done: boolean) => void; onMessage: (message: string, done: boolean) => void;
onError: (error: Error) => void; onError: (error: Error) => void;
onController?: (controller: AbortController) => void; onController?: (controller: AbortController) => void;
}, }
) { ) {
const req = makeRequestParam(messages, { const req = makeRequestParam(messages, {
stream: true, stream: true,
@ -189,7 +188,7 @@ export const ControllerPool = {
addController( addController(
sessionIndex: number, sessionIndex: number,
messageIndex: number, messageIndex: number,
controller: AbortController, controller: AbortController
) { ) {
const key = this.key(sessionIndex, messageIndex); const key = this.key(sessionIndex, messageIndex);
this.controllers[key] = controller; this.controllers[key] = controller;