SimaFarazi commited on
Commit
bdb23e1
1 Parent(s): 91a4394

clean up main for only simple stream app

Browse files
Files changed (1) hide show
  1. app_simple_stream/app/main.py +4 -3
app_simple_stream/app/main.py CHANGED
@@ -1,8 +1,8 @@
1
  from fastapi import FastAPI, Request
2
  from langchain_core.runnables import Runnable
3
- from langchain_core.callbacks import BaseCallbackHandler # Implement Server-Sent Event protocol
4
 
5
- from sse_starlette.sse import EventSourceResponse
6
  from langserve.serialization import WellKnownLCSerializer # Encode data because we are using Langserve on the frontend to recieve events, and Langserve is using this class to decode the data
7
  from typing import List
8
 
@@ -17,7 +17,8 @@ async def generate_stream(input_data: schemas.BaseModel, runnable: Runnable, cal
17
  for output in runnable.stream(input_data.dict(), config={"callbacks": callbacks}):
18
  data = WellKnownLCSerializer().dumps(output).decode("utf-8") # Decode data
19
  yield {'data': data, "event": "data"}
20
- yield {"event": "end"}
 
21
 
22
 
23
  @app.post("/simple/stream")
 
1
  from fastapi import FastAPI, Request
2
  from langchain_core.runnables import Runnable
3
+ from langchain_core.callbacks import BaseCallbackHandler # Print what is sent to llm and what was recieved as answer
4
 
5
+ from sse_starlette.sse import EventSourceResponse # Implement Server-Sent Event protocol
6
  from langserve.serialization import WellKnownLCSerializer # Encode data because we are using Langserve on the frontend to recieve events, and Langserve is using this class to decode the data
7
  from typing import List
8
 
 
17
  for output in runnable.stream(input_data.dict(), config={"callbacks": callbacks}):
18
  data = WellKnownLCSerializer().dumps(output).decode("utf-8") # Decode data
19
  yield {'data': data, "event": "data"}
20
+
21
+ yield {"event": "end"}
22
 
23
 
24
  @app.post("/simple/stream")