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). Themodelfield selects the agent. - LangServe —
/consumerand/query-optimizerwith the built-in/invoke,/streamand/playgroundroutes, 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.
_consumer_runnable_input
¶
LangServe input → consumer_agent call.
Accepts {"question": str, "thread_id": str?}.
_query_optimizer_runnable_input
¶
LangServe input → query_optimizer_agent call.
Accepts {"question": str, "sql_query": str?, "process_id": str?, "thread_id": str?}.
_add_langserve_routes
¶
Attach LangServe routes; no-op with a warning if langserve is absent.
_add_optimize_route
¶
Register POST /v1/optimize — SQL-in / structured-JSON-out query optimizer.
create_app
¶
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
¶
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
¶
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
¶
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.