Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚀 refactor: Use Undici Instead of Node-Fetch, prevent Event Close, add Index #3052

Merged
merged 3 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion api/app/clients/BaseClient.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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 { getConvo, getMessages, saveMessage, updateMessage, saveConvo } = require('~/models');
const { addSpaceIfNeeded, isEnabled } = require('~/server/utils');
Expand Down Expand Up @@ -69,6 +70,9 @@ class BaseClient {
url = this.options.reverseProxyUrl;
}
logger.debug(`Making request to ${url}`);
if (typeof Bun !== 'undefined') {
return await nodeFetch(url, init);
}
return await fetch(url, init);
}

Expand Down
1 change: 1 addition & 0 deletions api/models/schema/messageSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const messageSchema = mongoose.Schema(
},
conversationId: {
type: String,
index: true,
required: true,
meiliIndex: true,
},
Expand Down
1 change: 0 additions & 1 deletion client/src/hooks/SSE/useSSE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,6 @@ export default function useSSE(submission: TSubmission | null, index = 0) {
events.onerror = function (e: MessageEvent) {
console.log('error in server stream.');
startupConfig?.checkBalance && balanceQuery.refetch();
events.close();

let data: TResData | undefined = undefined;
try {
Expand Down
Loading