From 868d60078a424e98bf327edfec2487a4ab665b6d Mon Sep 17 00:00:00 2001 From: Jakub Novak Date: Thu, 4 Jul 2024 09:29:12 +0200 Subject: [PATCH] Change response to json --- template/server/main.py | 6 ++++-- template/server/messaging.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/template/server/main.py b/template/server/main.py index 58aafed..ba950b4 100644 --- a/template/server/main.py +++ b/template/server/main.py @@ -1,6 +1,7 @@ import uuid from fastapi import FastAPI +from starlette.responses import JSONResponse from messaging import JupyterKernelWebSocket from api.models.execution import Execution @@ -26,5 +27,6 @@ def health(): @app.post("/execute", response_model=Execution) -def execute(request: ExecutionRequest): - return ws.execute(code=request.code) +def execute(request: ExecutionRequest) -> JSONResponse: + result = ws.execute(code=request.code) + return JSONResponse(content=result) diff --git a/template/server/messaging.py b/template/server/messaging.py index a377b2e..136c7d5 100644 --- a/template/server/messaging.py +++ b/template/server/messaging.py @@ -55,7 +55,7 @@ def __init__( on_stderr: Optional[Callable[[CellMessage], Any]] = None, on_result: Optional[Callable[[Result], Any]] = None, ): - self.partial_result = Execution() + self.partial_result = Execution(results=[]) self.execution = Future() self.on_stdout = on_stdout self.on_stderr = on_stderr