| | import fetch from 'node-fetch'; |
| | import { logger } from '@librechat/data-schemas'; |
| | import { GraphEvents, sleep } from '@librechat/agents'; |
| | import type { Response as ServerResponse } from 'express'; |
| | import type { ServerSentEvent } from '~/types'; |
| | import { sendEvent } from './events'; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | export function createFetch({ |
| | directEndpoint = false, |
| | reverseProxyUrl = '', |
| | }: { |
| | directEndpoint?: boolean; |
| | reverseProxyUrl?: string; |
| | }) { |
| | |
| | |
| | |
| | |
| | |
| | |
| | return async function ( |
| | _url: fetch.RequestInfo, |
| | init: fetch.RequestInit, |
| | ): Promise<fetch.Response> { |
| | let url = _url; |
| | if (directEndpoint) { |
| | url = reverseProxyUrl; |
| | } |
| | logger.debug(`Making request to ${url}`); |
| | if (typeof Bun !== 'undefined') { |
| | return await fetch(url, init); |
| | } |
| | return await fetch(url, init); |
| | }; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | export function createStreamEventHandlers(res: ServerResponse) { |
| | return { |
| | [GraphEvents.ON_RUN_STEP]: function (event: ServerSentEvent) { |
| | if (res) { |
| | sendEvent(res, event); |
| | } |
| | }, |
| | [GraphEvents.ON_MESSAGE_DELTA]: function (event: ServerSentEvent) { |
| | if (res) { |
| | sendEvent(res, event); |
| | } |
| | }, |
| | [GraphEvents.ON_REASONING_DELTA]: function (event: ServerSentEvent) { |
| | if (res) { |
| | sendEvent(res, event); |
| | } |
| | }, |
| | }; |
| | } |
| |
|
| | export function createHandleLLMNewToken(streamRate: number) { |
| | return async function () { |
| | if (streamRate) { |
| | await sleep(streamRate); |
| | } |
| | }; |
| | } |
| |
|