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

View File

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

View File

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

View File

@ -7,6 +7,7 @@ export { finalizeBody } from "./finalize-body";
export { languageFilter } from "./language-filter"; export { languageFilter } from "./language-filter";
export { limitCompletions } from "./limit-completions"; export { limitCompletions } from "./limit-completions";
export { limitOutputTokens } from "./limit-output-tokens"; export { limitOutputTokens } from "./limit-output-tokens";
export { setApiFormat } from "./set-api-format";
export { transformKoboldPayload } from "./transform-kobold-payload"; export { transformKoboldPayload } from "./transform-kobold-payload";
export { transformOutboundPayload } from "./transform-outbound-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, finalizeBody,
limitOutputTokens, limitOutputTokens,
limitCompletions, limitCompletions,
setApiFormat,
transformOutboundPayload, transformOutboundPayload,
} from "./middleware/request"; } from "./middleware/request";
import { import {
@ -18,7 +19,6 @@ import {
handleInternalError, handleInternalError,
ProxyResHandlerWithBody, ProxyResHandlerWithBody,
} from "./middleware/response"; } from "./middleware/response";
import { setApiFormat } from "./routes";
const rewriteRequest = ( const rewriteRequest = (
proxyReq: http.ClientRequest, proxyReq: http.ClientRequest,

View File

@ -5,7 +5,6 @@ subset of the API is supported. Kobold requests must be transformed into
equivalent OpenAI requests. */ equivalent OpenAI requests. */
import * as express from "express"; import * as express from "express";
import { AIService } from "../key-management";
import { gatekeeper } from "./auth/gatekeeper"; import { gatekeeper } from "./auth/gatekeeper";
import { kobold } from "./kobold"; import { kobold } from "./kobold";
import { openai } from "./openai"; import { openai } from "./openai";
@ -17,16 +16,4 @@ router.use(gatekeeper);
router.use("/kobold", kobold); router.use("/kobold", kobold);
router.use("/openai", openai); router.use("/openai", openai);
router.use("/anthropic", anthropic); 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 }; export { router as proxyRouter };