Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# With inspiration from uv's example multistage dockerfile.

FROM python:3.13-slim-bookworm AS builder
FROM python:3.13-slim-trixie AS builder
WORKDIR /app

COPY --from=ghcr.io/astral-sh/uv:0.7 /uv /uvx /bin/
Expand All @@ -26,7 +26,7 @@ RUN --mount=type=cache,target=/root/.cache/uv \
#&& uv run -m nltk.downloader all -d /app/.venv/nltk_data


FROM python:3.13-slim-bookworm AS runtime
FROM python:3.13-slim-trixie AS runtime

COPY --from=builder /app /app

Expand Down
47 changes: 20 additions & 27 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,31 @@
from fastapi import FastAPI
from pydantic import BaseModel
from . import papa

import traceback

# TODO: Flesh this out?
class Xaif(BaseModel):
AIF: dict
text: str
OVA: dict | None = None
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel, ConfigDict
from . import papa


class RequestBody(BaseModel):
xaif: Xaif
node_level: bool | None = None
speaker: bool | None = None
forecast: bool | None = None
model_config = ConfigDict(
extra="allow",
)
xaif: dict


app = FastAPI()
app = FastAPI(title="papa", summary="Papa: Amazing Python Analytics")


@app.post("/api/all_analytics")
# Call without async so that fastapi does the work on a threadpool as
# all_analytics is cpu-bound and we don't want to block the current thread.
def all_analytics(body: RequestBody | Xaif):
if isinstance(body, RequestBody):
xaif = dict(body.xaif)
kwargs = {}
for name, value in body:
if name == "xaif":
continue

kwargs[name] = value if value is not None else False
else:
xaif = dict(body)

return papa.all_analytics(xaif)
def all_analytics(body: RequestBody | dict) -> dict:
"""Wrapper around papa's all_analytics function."""
try:
if isinstance(body, RequestBody):
return papa.all_analytics(
body.xaif, **{k: v for k, v in body if k != "xaif"}
)
else:
return papa.all_analytics(body)
except Exception:
raise HTTPException(status_code=500, detail=traceback.format_exc())