Skip to content

Commit 2ced623

Browse files
committed
Added alive endpoint and renamed templates one
1 parent 449aa08 commit 2ced623

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/sciwyrm/main.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import json
66
from typing import Annotated
77

8+
import uvicorn
89
from fastapi import Depends, FastAPI, Request, Response
910
from fastapi.exceptions import RequestValidationError
1011
from fastapi.responses import JSONResponse
@@ -19,13 +20,28 @@
1920
notebook_template_path,
2021
)
2122

23+
import logging
24+
2225
app = FastAPI()
2326

27+
logger = logging.getLogger(__name__)
28+
logger.setLevel(logging.INFO)
29+
logger.addHandler(logging.StreamHandler())
30+
31+
32+
@app.get("/alive", response_description="The service is alive")
33+
async def list_templates(
34+
config: Annotated[AppConfig, Depends(app_config)]
35+
) -> bool:
36+
"""Return a list of available notebook templates."""
37+
return True
38+
2439

25-
@app.get("/notebook/templates", response_description="Available templates")
40+
@app.get("/templates", response_description="Available templates")
2641
async def list_templates(
2742
config: Annotated[AppConfig, Depends(app_config)]
2843
) -> list[notebook.TemplateSummary]:
44+
logger.info("Templates")
2945
"""Return a list of available notebook templates."""
3046
return notebook.available_templates(config)
3147

@@ -44,12 +60,13 @@ def _inject_app_config(
4460
raise RequestValidationError(errors) from None
4561

4662

47-
@app.post("/notebook", response_model=dict, response_description="Rendered notebook")
48-
async def format_notebook(
63+
@app.post("/notebook", response_model=dict, response_description="Rendered notebook with json input")
64+
async def format_notebook_from_json(
4965
request: Request,
5066
templates: Annotated[Jinja2Templates, Depends(get_templates)],
5167
spec: notebook.NotebookSpecWithConfig = Depends(_inject_app_config), # noqa: B008
5268
) -> Response:
69+
5370
"""Format and return a notebook."""
5471
formatted = templates.TemplateResponse(
5572
name=notebook_template_path(spec.template_id),
@@ -59,3 +76,7 @@ async def format_notebook(
5976
nb = json.loads(formatted.body)
6077
nb["metadata"]["sciwyrm"] = notebook.notebook_metadata(spec)
6178
return JSONResponse(nb)
79+
80+
81+
if __name__ == "__main__":
82+
uvicorn.run(app, host="0.0.0.0", port=8000)

0 commit comments

Comments
 (0)