diff --git a/bun.lockb b/bun.lockb index 03dbd99..070c6c1 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/index.ts b/index.ts index 4a036d2..e21b672 100644 --- a/index.ts +++ b/index.ts @@ -4,6 +4,7 @@ import initAppConfig from "./constant/config" import { manageBotReq } from "./routes/bot" import { manageMessageReq } from "./routes/message" import { manageMicroAppReq } from "./routes/microApp" +import { manageModelProxyReq } from "./routes/modelProxy" import { manageSheetReq } from "./routes/sheet" import { initSchedule } from "./schedule" import genContext from "./utils/genContext" @@ -39,6 +40,8 @@ const bunServer = Bun.serve({ if (path.exact("/sheet")) return await manageSheetReq(ctx) // 小程序 if (path.startsWith("/micro_app")) return await manageMicroAppReq(ctx) + // 转发到模型代理服务 + if (path.startsWith("/v1")) return manageModelProxyReq(ctx) // 健康检查 if (path.full("/health")) return genResp.healthCheck() // 其他 diff --git a/package.json b/package.json index 674e18b..45c5280 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "@types/jsdom": "^21.1.7", "@types/node-schedule": "^2.1.7", "@types/uuid": "^10.0.0", - "bun-types": "^1.2.2", + "bun-types": "^1.2.4", "eslint": "^9.19.0", "eslint-plugin-simple-import-sort": "^12.1.1", "eslint-plugin-unused-imports": "^4.1.4", diff --git a/routes/modelProxy/index.ts b/routes/modelProxy/index.ts new file mode 100644 index 0000000..b2d3f0c --- /dev/null +++ b/routes/modelProxy/index.ts @@ -0,0 +1,17 @@ +import { Context } from "../../types" + +/** + * 处理模型代理请求 + * @param req + * @returns + */ +export const manageModelProxyReq = async (ctx: Context) => { + const { req, logger } = ctx + logger.info("model proxy") + const PROXY_URL = + "http://ms-13871-nstruct-lmdeploy-2-0109140455.kscn-tj5-prod2-cloudml.xiaomi.srv" + return fetch(PROXY_URL + new URL(req.url).pathname, { + method: req.method, + body: req.body, + }) +}