fixes circluar dependency that broke tsc but not esbuild

This commit is contained in:
nai-degen 2023-05-30 04:01:03 -05:00
parent 6723cbf662
commit f621031ec1
7 changed files with 19 additions and 18 deletions

View File

@ -101,7 +101,7 @@ export class OpenAIKeyChecker {
this.lastCheck + MIN_CHECK_INTERVAL
);
this.log.info(
this.log.debug(
{ key: oldestKey.hash, nextCheck: new Date(nextCheck) },
"Scheduling next check."
);
@ -119,7 +119,7 @@ export class OpenAIKeyChecker {
return;
}
this.log.info({ key: key.hash }, "Checking key...");
this.log.debug({ key: key.hash }, "Checking key...");
let isInitialCheck = !key.lastChecked;
try {
// During the initial check we need to get the subscription first because

View File

@ -8,6 +8,7 @@ import {
finalizeBody,
languageFilter,
limitOutputTokens,
setApiFormat,
transformOutboundPayload,
} from "./middleware/request";
import {
@ -16,7 +17,6 @@ import {
handleInternalError,
} from "./middleware/response";
import { createQueueMiddleware } from "./queue";
import { setApiFormat } from "./routes";
const rewriteAnthropicRequest = (
proxyReq: http.ClientRequest,

View File

@ -7,12 +7,12 @@ import { createProxyMiddleware } from "http-proxy-middleware";
import { config } from "../config";
import { logger } from "../logger";
import { ipLimiter } from "./rate-limit";
import { setApiFormat } from "./routes";
import {
addKey,
finalizeBody,
languageFilter,
limitOutputTokens,
setApiFormat,
transformKoboldPayload,
} from "./middleware/request";
import {

View File

@ -7,6 +7,7 @@ export { finalizeBody } from "./finalize-body";
export { languageFilter } from "./language-filter";
export { limitCompletions } from "./limit-completions";
export { limitOutputTokens } from "./limit-output-tokens";
export { setApiFormat } from "./set-api-format";
export { transformKoboldPayload } from "./transform-kobold-payload";
export { transformOutboundPayload } from "./transform-outbound-payload";

View File

@ -0,0 +1,13 @@
import { Request, RequestHandler } from "express";
import { AIService } from "../../../key-management";
export const setApiFormat = (api: {
in: Request["inboundApi"];
out: AIService;
}): RequestHandler => {
return (req, _res, next) => {
req.inboundApi = api.in;
req.outboundApi = api.out;
next();
};
};

View File

@ -11,6 +11,7 @@ import {
finalizeBody,
limitOutputTokens,
limitCompletions,
setApiFormat,
transformOutboundPayload,
} from "./middleware/request";
import {
@ -18,7 +19,6 @@ import {
handleInternalError,
ProxyResHandlerWithBody,
} from "./middleware/response";
import { setApiFormat } from "./routes";
const rewriteRequest = (
proxyReq: http.ClientRequest,

View File

@ -5,7 +5,6 @@ subset of the API is supported. Kobold requests must be transformed into
equivalent OpenAI requests. */
import * as express from "express";
import { AIService } from "../key-management";
import { gatekeeper } from "./auth/gatekeeper";
import { kobold } from "./kobold";
import { openai } from "./openai";
@ -17,16 +16,4 @@ router.use(gatekeeper);
router.use("/kobold", kobold);
router.use("/openai", openai);
router.use("/anthropic", anthropic);
export function setApiFormat(api: {
in: express.Request["inboundApi"];
out: AIService;
}): express.RequestHandler {
return (req, _res, next) => {
req.inboundApi = api.in;
req.outboundApi = api.out;
next();
};
}
export { router as proxyRouter };