mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
fix: use of proxy, use undici
This commit is contained in:
parent
a326c18b74
commit
83153cd582
5 changed files with 20 additions and 7 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
|
const { ProxyAgent } = require('undici');
|
||||||
const Anthropic = require('@anthropic-ai/sdk');
|
const Anthropic = require('@anthropic-ai/sdk');
|
||||||
const { HttpsProxyAgent } = require('https-proxy-agent');
|
|
||||||
const {
|
const {
|
||||||
Constants,
|
Constants,
|
||||||
ErrorTypes,
|
ErrorTypes,
|
||||||
|
|
@ -193,7 +193,7 @@ class AnthropicClient extends BaseClient {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.options.proxy) {
|
if (this.options.proxy) {
|
||||||
options.httpAgent = new HttpsProxyAgent(this.options.proxy);
|
options.httpAgent = new ProxyAgent(this.options.proxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.options.reverseProxyUrl) {
|
if (this.options.reverseProxyUrl) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
const OpenAI = require('openai');
|
const OpenAI = require('openai');
|
||||||
|
const { ProxyAgent } = require('undici');
|
||||||
const { OllamaClient } = require('./OllamaClient');
|
const { OllamaClient } = require('./OllamaClient');
|
||||||
const { HttpsProxyAgent } = require('https-proxy-agent');
|
|
||||||
const { SplitStreamHandler } = require('@librechat/agents');
|
const { SplitStreamHandler } = require('@librechat/agents');
|
||||||
const {
|
const {
|
||||||
Constants,
|
Constants,
|
||||||
|
|
@ -674,8 +674,7 @@ class OpenAIClient extends BaseClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.options.proxy) {
|
if (this.options.proxy) {
|
||||||
configOptions.httpAgent = new HttpsProxyAgent(this.options.proxy);
|
configOptions.httpAgent = new ProxyAgent(this.options.proxy);
|
||||||
configOptions.httpsAgent = new HttpsProxyAgent(this.options.proxy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const { req, res, debug } = this.options;
|
const { req, res, debug } = this.options;
|
||||||
|
|
@ -1173,7 +1172,7 @@ ${convo}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.options.proxy) {
|
if (this.options.proxy) {
|
||||||
opts.httpAgent = new HttpsProxyAgent(this.options.proxy);
|
opts.httpAgent = new ProxyAgent(this.options.proxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {TAzureConfig | undefined} */
|
/** @type {TAzureConfig | undefined} */
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
const { fetch } = require('undici');
|
||||||
const { GraphEvents } = require('@librechat/agents');
|
const { GraphEvents } = require('@librechat/agents');
|
||||||
const { logger, sendEvent } = require('~/config');
|
const { logger, sendEvent } = require('~/config');
|
||||||
|
|
||||||
|
|
@ -15,12 +16,15 @@ function createFetch({ directEndpoint = false, reverseProxyUrl = '' }) {
|
||||||
* @param {RequestInit} [init] - Optional init options for the request.
|
* @param {RequestInit} [init] - Optional init options for the request.
|
||||||
* @returns {Promise<Response>} - A promise that resolves to the response of the fetch 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;
|
let url = _url;
|
||||||
if (directEndpoint) {
|
if (directEndpoint) {
|
||||||
url = reverseProxyUrl;
|
url = reverseProxyUrl;
|
||||||
}
|
}
|
||||||
logger.debug(`Making request to ${url}`);
|
logger.debug(`Making request to ${url}`);
|
||||||
|
if (agent != null) {
|
||||||
|
init.dispatcher = agent;
|
||||||
|
}
|
||||||
if (typeof Bun !== 'undefined') {
|
if (typeof Bun !== 'undefined') {
|
||||||
return await fetch(url, init);
|
return await fetch(url, init);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,7 @@
|
||||||
"tiktoken": "^1.0.15",
|
"tiktoken": "^1.0.15",
|
||||||
"traverse": "^0.6.7",
|
"traverse": "^0.6.7",
|
||||||
"ua-parser-js": "^1.0.36",
|
"ua-parser-js": "^1.0.36",
|
||||||
|
"undici": "^7.8.0",
|
||||||
"winston": "^3.11.0",
|
"winston": "^3.11.0",
|
||||||
"winston-daily-rotate-file": "^4.7.1",
|
"winston-daily-rotate-file": "^4.7.1",
|
||||||
"youtube-transcript": "^1.2.1",
|
"youtube-transcript": "^1.2.1",
|
||||||
|
|
|
||||||
9
package-lock.json
generated
9
package-lock.json
generated
|
|
@ -124,6 +124,7 @@
|
||||||
"tiktoken": "^1.0.15",
|
"tiktoken": "^1.0.15",
|
||||||
"traverse": "^0.6.7",
|
"traverse": "^0.6.7",
|
||||||
"ua-parser-js": "^1.0.36",
|
"ua-parser-js": "^1.0.36",
|
||||||
|
"undici": "^7.8.0",
|
||||||
"winston": "^3.11.0",
|
"winston": "^3.11.0",
|
||||||
"winston-daily-rotate-file": "^4.7.1",
|
"winston-daily-rotate-file": "^4.7.1",
|
||||||
"youtube-transcript": "^1.2.1",
|
"youtube-transcript": "^1.2.1",
|
||||||
|
|
@ -40965,6 +40966,14 @@
|
||||||
"integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==",
|
"integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==",
|
||||||
"dev": true
|
"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": {
|
"node_modules/undici-types": {
|
||||||
"version": "5.26.5",
|
"version": "5.26.5",
|
||||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
|
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue