This commit is contained in:
KmBase 2023-04-07 19:45:02 +08:00
parent 98d007287c
commit 3d271fae90

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,
@ -39,9 +39,10 @@ function getHeaders() {
if (accessStore.token && accessStore.token.length > 0) { if (accessStore.token && accessStore.token.length > 0) {
headers["token"] = accessStore.token; headers["token"] = accessStore.token;
}
if (accessStore.host && accessStore.host.length > 0) {
headers["userhost"] = accessStore.host; headers["userhost"] = accessStore.host;
} }
return headers; return headers;
} }
@ -85,7 +86,7 @@ export async function requestUsage() {
const [used, subs] = await Promise.all([ const [used, subs] = await Promise.all([
requestOpenaiClient( requestOpenaiClient(
`dashboard/billing/usage?start_date=${startDate}&end_date=${endDate}` `dashboard/billing/usage?start_date=${startDate}&end_date=${endDate}`,
)(null, "GET"), )(null, "GET"),
requestOpenaiClient("dashboard/billing/subscription")(null, "GET"), requestOpenaiClient("dashboard/billing/subscription")(null, "GET"),
]); ]);
@ -125,7 +126,7 @@ export async function requestChatStream(
onMessage: (message: string, done: boolean) => void; onMessage: (message: string, done: boolean) => void;
onError: (error: Error, statusCode?: number) => void; onError: (error: Error, statusCode?: number) => void;
onController?: (controller: AbortController) => void; onController?: (controller: AbortController) => void;
} },
) { ) {
const req = makeRequestParam(messages, { const req = makeRequestParam(messages, {
stream: true, stream: true,
@ -214,7 +215,7 @@ export const ControllerPool = {
addController( addController(
sessionIndex: number, sessionIndex: number,
messageId: number, messageId: number,
controller: AbortController controller: AbortController,
) { ) {
const key = this.key(sessionIndex, messageId); const key = this.key(sessionIndex, messageId);
this.controllers[key] = controller; this.controllers[key] = controller;