API: Use FastAPI streaming instead of sse_starlette

sse_starlette kept firing a ping response if it was taking too long
to set an event. Rather than using a hacky workaround, switch to
FastAPI's inbuilt streaming response and construct SSE requests with
a utility function.

This helps the API become more robust and removes an extra requirement.

Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
kingbri
2023-12-01 01:54:35 -05:00
parent 6493b1d2aa
commit ae69b18583
4 changed files with 15 additions and 12 deletions

View File

@@ -26,4 +26,7 @@ def get_generator_error(exception: Exception):
# Log and send the exception
print(f"\n{generator_error.error.trace}")
return generator_error.json()
return get_sse_packet(generator_error.json(ensure_ascii = False))
def get_sse_packet(json_data: str):
return f"data: {json_data}\n\n"