fixes google ai gemini
This commit is contained in:
parent
29638cf26e
commit
a7fed3136e
|
@ -105,8 +105,8 @@ function transformGoogleAIResponse(
|
|||
const googleAIProxy = createQueuedProxyMiddleware({
|
||||
target: ({ signedRequest }) => {
|
||||
if (!signedRequest) throw new Error("Must sign request before proxying");
|
||||
const { protocol, hostname, path } = signedRequest;
|
||||
return `${protocol}//${hostname}${path}`;
|
||||
const { protocol, hostname} = signedRequest;
|
||||
return `${protocol}//${hostname}`;
|
||||
},
|
||||
mutations: [addGoogleAIKey, finalizeSignedRequest],
|
||||
blockingResponseHandler: googleAIBlockingResponseHandler,
|
||||
|
@ -120,11 +120,7 @@ googleAIRouter.post(
|
|||
"/v1beta/models/:modelId:(generateContent|streamGenerateContent)",
|
||||
ipLimiter,
|
||||
createPreprocessorMiddleware(
|
||||
{
|
||||
inApi: "google-ai",
|
||||
outApi: "google-ai",
|
||||
service: "google-ai",
|
||||
},
|
||||
{ inApi: "google-ai", outApi: "google-ai", service: "google-ai" },
|
||||
{ beforeTransform: [maybeReassignModel], afterTransform: [setStreamFlag] }
|
||||
),
|
||||
googleAIProxy
|
||||
|
|
|
@ -107,23 +107,16 @@ function pinoLoggerPlugin(proxyServer: ProxyServer<Request>) {
|
|||
"Error occurred while proxying request to target"
|
||||
);
|
||||
});
|
||||
proxyServer.on("proxyReq", (proxyReq, req, res) => {
|
||||
const originalUrl = req.originalUrl;
|
||||
const targetHost = `${proxyReq.protocol}//${proxyReq.host}`;
|
||||
const targetPath = res.req.url;
|
||||
proxyServer.on("proxyReq", (proxyReq, req) => {
|
||||
const from = req.originalUrl;
|
||||
req.log.info(
|
||||
{ originalUrl, targetHost, targetPath },
|
||||
{ from, to: `${proxyReq.protocol}//${proxyReq.host}${proxyReq.path}` },
|
||||
"Sending request to upstream API..."
|
||||
);
|
||||
});
|
||||
proxyServer.on("proxyRes", (proxyRes: ProxiedResponse, req, _res) => {
|
||||
const originalUrl = req.originalUrl;
|
||||
const targetHost = `${proxyRes.req.protocol}//${proxyRes.req.hostname}`;
|
||||
const targetPath = proxyRes.req.path;
|
||||
const target = `${proxyRes.req.protocol}//${proxyRes.req.host}${proxyRes.req.path}`;
|
||||
const statusCode = proxyRes.statusCode;
|
||||
req.log.info(
|
||||
{ originalUrl, targetHost, targetPath, statusCode },
|
||||
"Got response from upstream API."
|
||||
);
|
||||
req.log.info({ target, statusCode }, "Got response from upstream API.");
|
||||
});
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ export function getHttpAgents() {
|
|||
process.env.HTTP_PROXY = proxyUrl;
|
||||
process.env.HTTPS_PROXY = proxyUrl;
|
||||
process.env.WS_PROXY = proxyUrl;
|
||||
process.env.WSS_PROXY = proxyUrl;
|
||||
httpAgent = new ProxyAgent();
|
||||
httpsAgent = httpAgent; // ProxyAgent automatically handles HTTPS
|
||||
const proxy = proxyUrl.replace(/:.*@/, "@******");
|
||||
|
|
Loading…
Reference in New Issue