Spaces:
Running
Running
SimaFarazi
commited on
Commit
•
295606c
1
Parent(s):
2fa9347
finalize simple stream app
Browse files
app_simple_stream/app/main.py
CHANGED
@@ -16,7 +16,7 @@ app = FastAPI()
|
|
16 |
async def generate_stream(input_data: schemas.BaseModel, runnable: Runnable, callbacks: List[BaseCallbackHandler]=[]):
|
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 |
|
|
|
16 |
async def generate_stream(input_data: schemas.BaseModel, runnable: Runnable, callbacks: List[BaseCallbackHandler]=[]):
|
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"} # Use yield to create generator, which can pause the execution and return a value
|
20 |
|
21 |
yield {"event": "end"}
|
22 |
|