shafkevi / lambda-bedrock-s3-streaming-rag

Fully serverless streaming RAG application
MIT No Attribution
26 stars 7 forks source link

Rendering error due to this broken item: Azure/fetch-event-source #1

Closed weisisheng closed 6 months ago

weisisheng commented 6 months ago

How the heck did you get the react app working well? I hit this long standing microsoft bug right way. Devs complaining about it for 1-2 years.

https://github.com/Azure/fetch-event-source/issues/18

WARNING in ./node_modules/@microsoft/fetch-event-source/lib/esm/fetch.js Module Warning (from ./node_modules/source-map-loader/dist/cjs.js): Failed to parse source map from '/[REDACTED]/node_modules/@microsoft/fetch-event-source/src/fetch.ts' file: Error: ENOENT: no such file or directory, open '/[REDACTED]/node_modules/@microsoft/fetch-event-source/src/fetch.ts'

shafkevi commented 6 months ago

@weisisheng

I actually since have moved away from that library for other projects as it seemed unnecessary and cumbersome.

Here is the new react code for receiving the streaming data, and then the callback that I used just to pump the data into an object iteratively.

export const streamingLambda = async (url, method, payload, callback)=>{
    let response;
    try {
      // TODO: catch error codes here.
      response = await window.fetch(url, {
          method,
          body: JSON.stringify(payload),
          headers: {
            'Content-Type': 'text/plain',
          },
          mode: "cors"
        });
      const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
      while (true){
        const {value, done} = await reader.read();
        if (done) break;
        callback(value);
      }
    }
    catch (err){
      console.log('Something went wrong');
      console.log(err);
      return;
    }
  }
(value) => { setResults((data) => [...data, value]); }
weisisheng commented 6 months ago

Thanks, will give it a study! Best.

shafkevi commented 5 months ago

@weisisheng I have updated the code to reflect my above changes in commit: https://github.com/shafkevi/lambda-bedrock-s3-streaming-rag/commit/6895da1f95a203601034e609694283e19ba0a73c