Skip to content

Commit 7959f6b

Browse files
authored
Merge pull request #362 from FlowiseAI/bug/fix-on-request-not-used-for-streaming
fix: invoke onRequest callback for streaming prediction requests
2 parents e1bafe4 + c250f29 commit 7959f6b

File tree

4 files changed

+168744
-3
lines changed

4 files changed

+168744
-3
lines changed

dist/components/Bot.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/web.js

Lines changed: 84363 additions & 1 deletion
Large diffs are not rendered by default.

dist/web.umd.js

Lines changed: 84371 additions & 1 deletion
Large diffs are not rendered by default.

src/components/Bot.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,13 +927,22 @@ export const Bot = (botProps: BotProps & { class?: string }) => {
927927
const chatId = params.chatId;
928928
const input = params.question;
929929
params.streaming = true;
930+
931+
const customFetch = async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {
932+
if (props.onRequest && init) {
933+
await props.onRequest(init);
934+
}
935+
return fetch(input, init);
936+
};
937+
930938
fetchEventSource(`${props.apiHost}/api/v1/prediction/${chatflowid}`, {
931939
openWhenHidden: true,
932940
method: 'POST',
933941
body: JSON.stringify(params),
934942
headers: {
935943
'Content-Type': 'application/json',
936944
},
945+
fetch: customFetch,
937946
async onopen(response) {
938947
if (response.ok && response.headers.get('content-type')?.startsWith(EventStreamContentType)) {
939948
return; // everything's good

0 commit comments

Comments
 (0)