Skip to content

tdfs4ds.serve.app

tdfs4ds.serve.app

FastAPI application factory for the tdfs4ds agent server.

Mounts two surfaces over the same two agents:

  • OpenAI-compatible — /v1/models + /v1/chat/completions (see :mod:tdfs4ds.serve.openai_router). The model field selects the agent.
  • LangServe — /consumer and /query-optimizer with the built-in /invoke, /stream and /playground routes, for interactive debugging.

The consumer / query-optimizer entry points are plain functions, so each is wrapped in a RunnableLambda before being handed to add_routes.

logger module-attribute

logger = getLogger('tdfs4ds.serve')

_consumer_runnable_input

_consumer_runnable_input(payload: dict) -> str

LangServe input → consumer_agent call.

Accepts {"question": str, "thread_id": str?}.

_query_optimizer_runnable_input

_query_optimizer_runnable_input(payload: dict) -> str

LangServe input → query_optimizer_agent call.

Accepts {"question": str, "sql_query": str?, "process_id": str?, "thread_id": str?}.

_add_langserve_routes

_add_langserve_routes(app: FastAPI) -> None

Attach LangServe routes; no-op with a warning if langserve is absent.

_add_optimize_route

_add_optimize_route(app: FastAPI) -> None

Register POST /v1/optimize — SQL-in / structured-JSON-out query optimizer.

create_app

create_app(run_bootstrap: bool = True, root_path: str | None = None) -> FastAPI

Build the FastAPI app.

Parameters

run_bootstrap: When True (default) the Teradata context + vector index are initialised on the application startup event. Pass False to build the app object for import-only checks (e.g. GET /v1/models needs no database). root_path: External URL path prefix the app is mounted under (e.g. "/myapp" behind a reverse proxy). Defaults to TDFS4DS_SERVE_ROOT_PATH (or empty). FastAPI uses it for OpenAPI/redirects; the admin shell reads it from each request so its assets / fetch calls resolve under the prefix.

_add_admin_ui

_add_admin_ui(app: FastAPI, root_path: str = '') -> None

Mount the Gradio chatbot at /chatbot and the admin web shell at /.

The shell (static HTML/JS + /ui/* JSON/HTML endpoints over :mod:tdfs4ds.serve.panels) reproduces the Teradata "Tera" console look and embeds the chatbot in an iframe. One process, one port.

_add_reports_routes

_add_reports_routes(app: FastAPI) -> None

Serve query-optimizer reports for download under /reports.

GET /reports → JSON listing of available report files. GET /reports/{path} → download a single .md report.

Files live under QUERY_OPTIMIZER_REPORT_DIR ({domain}/{file}.md); the path is resolved safely against that root to prevent traversal.

_add_lineage_route

_add_lineage_route(app: FastAPI) -> None

Serve an interactive lineage graph at GET /lineage.

Reads the persisted FS_LINEAGE_GRAPH temporal table and returns a self-contained HTML page (vis.js inlined) rendered by pyvis.

Query parameters

seed : str, optional Restrict the graph to the subgraph of a single object, e.g. /lineage?seed=MY_DB.MY_VIEW. Omit for the full graph.