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

Works in Postman but not in UI #225

Open
Sritharan-racap opened this issue Dec 28, 2023 · 0 comments
Open

Works in Postman but not in UI #225

Sritharan-racap opened this issue Dec 28, 2023 · 0 comments

Comments

@Sritharan-racap
Copy link

Sritharan-racap commented Dec 28, 2023

Hi I'm using EventSource for making SSE call to my Java backend to build internal ChatGPT like application.
Java Code below:

    @GET
    @Path("/chat-stream")
    @Produces("text/event-stream")
    @Timed(absolute = true, name = "GET./chat-stream")
    // @formatter:on
    public void getChatStream(@Context SseEventSink sseEventSink, @Context Sse sse,
            @BeanParam AiChatRequestFilter filter) {
        executor.execute(() -> {
            int count = 10;
            while (count > 0) {
                try {
                    Thread.sleep(500);
                    sseEventSink.send(sse.newEvent("message", "Hello World -    " + count));
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                count--;
            }
            sseEventSink.close();
        });
    }

The above code works in Postman, i.e when i make the api call, i get the message registered right away after 500ms.
But when I do the same call via UI, the message is not logged right away after 500ms. It waits for the connection to complete (i.e after 5s, i get all the message logged in the console)

UI code attached below:

sseTest() {
    const authToken = this.localStorageService.get('tokenInfo')['accessToken'];
    const eventSourceInitDict = {
      headers: {
        Authorization: 'Bearer ' + authToken
      }
    };
    let url = '/api/ai/notes/chat-stream';
    url += '?prompt=' + encodeURIComponent('How is Macrogenics addressing the toxicity issues seen with Vobra Duo in the dose expansion cohort?');
    url += '&domainName=' + encodeURIComponent('AML_OVN_2021');
    const es = new EventSourcePolyfill(url, eventSourceInitDict);
    const listener = function(event) {
      console.log(event);
    };
    es.addEventListener('open', listener);
    es.addEventListener('message', (event) => {
        console.log(event);
    });
    es.addEventListener('error', listener);
  }

And the call is getting repeated in an infinite loop even if i'm calling the function only once.That's a weird part as well.

Any help on this will be greatly appreciated pls ?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant