24 lines
707 B
TypeScript

import { Context } from "../../types"
/**
* 处理模型代理请求
* @param req
* @returns
*/
export const manageModelProxyReq = async (ctx: Context) => {
const { req, headers, logger, path } = ctx
if (!path.exact("/v1/models")) {
const auth = headers.get("Authorization")
logger.info(`Start Model Proxy, Authorization: ${auth}`)
if (!auth || auth !== "Bearer sk-21a2ce1c2ee94bc2933798eac1bbcadc") {
return ctx.genResp.forbidden("Authorization required")
}
}
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,
})
}