[Bug] no proxying with batch vectorization
📦 Platform
Other
📦 Deploymenet mode
client db (lobe-chat image)
📌 Version
v1.51.1
💻 Operating System
Windows
🌐 Browser
Chrome, Edge
🐛 Bug Description
Batch requests made via lambdaClient bypass the proxy, leading to service unavailability in case of using proxy. In contrast, single-file requests successfully go through the proxy, indicating an issue with how httpBatchLink handles network routing.
Actual Behavior
- Single requests pass through the proxy successfully.
- Batch requests bypass the proxy, resulting in a service availability restriction.
Code Analysis
- File: src/store/file/slices/fileManager/action.ts Calls embeddingChunks and parseFilesToChunks, triggering requests in batch mode.
- File: src/services/ragService.ts Methods like createParseFileTask and createEmbeddingChunksTask use lambdaClient to send requests.
- File: src/libs/trpc/client/lambda.ts lambdaClient is configured with httpBatchLink, but the fetch function does not explicitly route requests through the proxy.
Possible Fix Modify fetch inside httpBatchLink in lambda.ts to explicitly send batch requests through the proxy, ensuring consistency with single requests.
📷 Recurrence Steps
Steps to Reproduce
- Attempt to process files in batch mode using the embeddingChunks or parseFilesToChunks functions.
- Observe that requests fail with a "service unavailable in your country" error.
- Process a single file instead, and notice that it succeeds.
- Inspect network requests and confirm that batch requests do not go through the proxy.
- Expected Behavior
- All requests, including batch requests, should pass through the configured proxy to bypass regional restrictions.
🚦 Expected Behavior
requests should be passed trough proxy
📝 Additional Information
No response
👀 @dab512
Thank you for raising an issue. We will investigate into the matter and get back to you as soon as possible.
Please make sure you have given us as much context as possible.
非常感谢您提交 issue。我们会尽快调查此事,并尽快回复您。 请确保您已经提供了尽可能多的背景信息。
Hey @dab512! I'm here to help you with any bugs, questions, or contributions you have. Let's work together to solve this issue.
To address the issue where batch requests made via lambdaClient bypass the proxy, you can modify the fetch function inside httpBatchLink in lambda.ts to ensure that these requests are routed through the proxy. Here's a suggested modification:
import { createTRPCClient, httpBatchLink } from '@trpc/client';
import { createTRPCReact } from '@trpc/react-query';
import superjson from 'superjson';
import { ModelProvider } from '@/libs/agent-runtime';
import type { LambdaRouter } from '@/server/routers/lambda';
import { ErrorResponse } from './types';
const links = [
httpBatchLink({
fetch: async (input, init) => {
// Modify the fetch function to include proxy settings
const proxyUrl = 'http://your-proxy-url.com'; // Replace with your proxy URL
const proxiedInput = new URL(input.toString(), proxyUrl).toString();
const response = await fetch(proxiedInput, init);
if (response.ok) return response;
const errorRes: ErrorResponse = await response.clone().json();
const { loginRequired } = await import('@/components/Error/loginRequiredNotification');
const { fetchErrorNotification } = await import('@/components/Error/fetchErrorNotification');
errorRes.forEach((item) => {
const errorData = item.error.json;
const status = errorData.data.httpStatus;
switch (status) {
case 401: {
loginRequired.redirect();
break;
}
default: {
fetchErrorNotification.error({ errorMessage: errorData.message, status });
}
}
});
return response;
},
headers: async () => {
// dynamic import to avoid circular dependency
const { createHeaderWithAuth } = await import('@/services/_auth');
// TODO: we need to support provider select
return createHeaderWithAuth({ provider: ModelProvider.OpenAI });
},
maxURLLength: 2083,
transformer: superjson,
url: '/trpc/lambda',
}),
];
export const lambdaClient = createTRPCClient<LambdaRouter>({
links,
});
export const lambdaQuery = createTRPCReact<LambdaRouter>();
export const lambdaQueryClient = lambdaQuery.createClient({ links });
This change ensures that the batch requests are routed through the specified proxy by constructing the request URL with the proxy URL. Make sure to replace 'http://your-proxy-url.com' with the actual proxy URL you intend to use [1].
To continue talking to Dosu, mention @dosu.
Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other