0

when I send a sse get request to server,this is the get request look like:

https://example.com/ai/stream/chat/ask?prompt=balabala.....

shows error 413 request entity too large. I read the react EventSource only support GET, what should I do to fixed this issue? how to send a long text to server side? This is the current code:

import { ChatAsk } from '@/models/request/chat/ChatAsk';
import { EventSourcePolyfill } from 'event-source-polyfill';
import { v4 as uuid } from 'uuid';

export function doSseChatAsk(params: ChatAsk, onSseMessage: (msg: string) => void,) {
  let eventSource: EventSourcePolyfill;
  const accessToken = localStorage.getItem("x-access-token");
  var queryString = Object.keys(params).map(key => key + '=' + params[key as keyof ChatAsk]).join('&');
  eventSource = new EventSourcePolyfill('/ai/stream/chat/ask?' + queryString, {
    headers: {
      'x-access-token': accessToken ?? "",
      'x-request-id': uuid(),
    }
  });
  eventSource.onopen = () => {
    console.log("onopen....")
  }
  eventSource.onerror = (error) => {
    console.log("onerror",error)
    if(eventSource){
      eventSource.close();
    }
  }
  eventSource.onmessage = e => {
    onSseMessage(e.data);
  };

  eventSource.addEventListener('complete', () => {
    console.log('Transfer of data is complete');
  });
  
  eventSource.addEventListener('onclose', () => {
    console.log('Transfer of data is complete');
  });
}
Dolphin
  • 29,069
  • 61
  • 260
  • 539
  • This is a duplicate of https://stackoverflow.com/q/75928278/841830 (looks like you might even be using the same openai service?) – Darren Cook Apr 20 '23 at 09:02
  • not the same service, seems no way to fixed this issue. – Dolphin Apr 20 '23 at 11:19
  • 1
    As it says on that other question, the only way round it is to pass the large data string in a separate http request before starting the SSE connection. – Darren Cook Apr 20 '23 at 14:39

0 Answers0