mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 00:40:14 +01:00
🚀 refactor: Use Undici Instead of Node-Fetch, prevent Event Close, add Index (#3052)
* feat: Add index to conversationId field in messageSchema * refactor: prevent immediate event close on error * refactor: use undici instead of node-fetch in non-Bun environment
This commit is contained in:
parent
29e71e98ad
commit
4416f69a9b
3 changed files with 6 additions and 2 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const fetch = require('node-fetch');
|
const { fetch } = require('undici');
|
||||||
|
const nodeFetch = require('node-fetch');
|
||||||
const { supportsBalanceCheck, Constants } = require('librechat-data-provider');
|
const { supportsBalanceCheck, Constants } = require('librechat-data-provider');
|
||||||
const { getConvo, getMessages, saveMessage, updateMessage, saveConvo } = require('~/models');
|
const { getConvo, getMessages, saveMessage, updateMessage, saveConvo } = require('~/models');
|
||||||
const { addSpaceIfNeeded, isEnabled } = require('~/server/utils');
|
const { addSpaceIfNeeded, isEnabled } = require('~/server/utils');
|
||||||
|
|
@ -69,6 +70,9 @@ class BaseClient {
|
||||||
url = this.options.reverseProxyUrl;
|
url = this.options.reverseProxyUrl;
|
||||||
}
|
}
|
||||||
logger.debug(`Making request to ${url}`);
|
logger.debug(`Making request to ${url}`);
|
||||||
|
if (typeof Bun !== 'undefined') {
|
||||||
|
return await nodeFetch(url, init);
|
||||||
|
}
|
||||||
return await fetch(url, init);
|
return await fetch(url, init);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ const messageSchema = mongoose.Schema(
|
||||||
},
|
},
|
||||||
conversationId: {
|
conversationId: {
|
||||||
type: String,
|
type: String,
|
||||||
|
index: true,
|
||||||
required: true,
|
required: true,
|
||||||
meiliIndex: true,
|
meiliIndex: true,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -604,7 +604,6 @@ export default function useSSE(submission: TSubmission | null, index = 0) {
|
||||||
events.onerror = function (e: MessageEvent) {
|
events.onerror = function (e: MessageEvent) {
|
||||||
console.log('error in server stream.');
|
console.log('error in server stream.');
|
||||||
startupConfig?.checkBalance && balanceQuery.refetch();
|
startupConfig?.checkBalance && balanceQuery.refetch();
|
||||||
events.close();
|
|
||||||
|
|
||||||
let data: TResData | undefined = undefined;
|
let data: TResData | undefined = undefined;
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue