Last active
July 5, 2024 05:47
-
-
Save elijahbenizzy/23ef6d500f9dca11268d1cada5c1abf6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.post("/response/{project_id}/{app_id}", response_class=StreamingResponse) | |
async def chat_response(project_id: str, app_id: str, prompt: PromptInput) -> StreamingResponse: | |
burr_app = _get_application(project_id, app_id) | |
chat_history = burr_app.state.get("chat_history", []) | |
action, streaming_container = await burr_app.astream_result( | |
halt_after=chat_application.TERMINAL_ACTIONS, inputs=dict(prompt=prompt.prompt) | |
) | |
async def sse_generator(): | |
yield f"data: {json.dumps({'type': 'chat_history', 'value': chat_history})}\n\n" | |
async for item in streaming_container: | |
yield f"data: {json.dumps({'type': 'delta', 'value': item['delta']})} \n\n" | |
return StreamingResponse(sse_generator()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment