fix: use of proxy, use undici

This commit is contained in:
Danny Avila 2025-04-13 15:55:22 -04:00
parent a326c18b74
commit 83153cd582
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956
5 changed files with 20 additions and 7 deletions

View file

@ -1,5 +1,5 @@
const { ProxyAgent } = require('undici');
const Anthropic = require('@anthropic-ai/sdk');
const { HttpsProxyAgent } = require('https-proxy-agent');
const {
Constants,
ErrorTypes,
@ -193,7 +193,7 @@ class AnthropicClient extends BaseClient {
};
if (this.options.proxy) {
options.httpAgent = new HttpsProxyAgent(this.options.proxy);
options.httpAgent = new ProxyAgent(this.options.proxy);
}
if (this.options.reverseProxyUrl) {

View file

@ -1,6 +1,6 @@
const OpenAI = require('openai');
const { ProxyAgent } = require('undici');
const { OllamaClient } = require('./OllamaClient');
const { HttpsProxyAgent } = require('https-proxy-agent');
const { SplitStreamHandler } = require('@librechat/agents');
const {
Constants,
@ -674,8 +674,7 @@ class OpenAIClient extends BaseClient {
}
if (this.options.proxy) {
configOptions.httpAgent = new HttpsProxyAgent(this.options.proxy);
configOptions.httpsAgent = new HttpsProxyAgent(this.options.proxy);
configOptions.httpAgent = new ProxyAgent(this.options.proxy);
}
const { req, res, debug } = this.options;
@ -1173,7 +1172,7 @@ ${convo}
}
if (this.options.proxy) {
opts.httpAgent = new HttpsProxyAgent(this.options.proxy);
opts.httpAgent = new ProxyAgent(this.options.proxy);
}
/** @type {TAzureConfig | undefined} */

View file

@ -1,3 +1,4 @@
const { fetch } = require('undici');
const { GraphEvents } = require('@librechat/agents');
const { logger, sendEvent } = require('~/config');
@ -15,12 +16,15 @@ function createFetch({ directEndpoint = false, reverseProxyUrl = '' }) {
* @param {RequestInit} [init] - Optional init options for the request.
* @returns {Promise<Response>} - A promise that resolves to the response of the fetch request.
*/
return async (_url, init) => {
return async (_url, { agent, ...init }) => {
let url = _url;
if (directEndpoint) {
url = reverseProxyUrl;
}
logger.debug(`Making request to ${url}`);
if (agent != null) {
init.dispatcher = agent;
}
if (typeof Bun !== 'undefined') {
return await fetch(url, init);
}

View file

@ -108,6 +108,7 @@
"tiktoken": "^1.0.15",
"traverse": "^0.6.7",
"ua-parser-js": "^1.0.36",
"undici": "^7.8.0",
"winston": "^3.11.0",
"winston-daily-rotate-file": "^4.7.1",
"youtube-transcript": "^1.2.1",

9
package-lock.json generated
View file

@ -124,6 +124,7 @@
"tiktoken": "^1.0.15",
"traverse": "^0.6.7",
"ua-parser-js": "^1.0.36",
"undici": "^7.8.0",
"winston": "^3.11.0",
"winston-daily-rotate-file": "^4.7.1",
"youtube-transcript": "^1.2.1",
@ -40965,6 +40966,14 @@
"integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==",
"dev": true
},
"node_modules/undici": {
"version": "7.8.0",
"resolved": "https://registry.npmjs.org/undici/-/undici-7.8.0.tgz",
"integrity": "sha512-vFv1GA99b7eKO1HG/4RPu2Is3FBTWBrmzqzO0mz+rLxN3yXkE4mqRcb8g8fHxzX4blEysrNZLqg5RbJLqX5buA==",
"engines": {
"node": ">=20.18.1"
}
},
"node_modules/undici-types": {
"version": "5.26.5",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",