Spaces:
Sleeping
Sleeping
| """ | |
| Public API for the LangGraph chatbot used by the Streamlit app. | |
| Mirrors the public surface of the original `chatbot_agents.py` but: | |
| - the LLM client comes from `llm_client.create_chat_client()` (HF Inference Providers) | |
| - the DB-query function comes from `db.get_metrics_from_db_filtered` | |
| """ | |
| from __future__ import annotations | |
| from typing import Any | |
| import pandas as pd | |
| from agents.supervisor import build_chatbot_graph | |
| from tools.state import create_initial_state | |
| def build_langgraph_chatbot( | |
| metrics_df: pd.DataFrame | None = None, | |
| chat_client: Any | None = None, | |
| db_query_fn: Any | None = None, | |
| column_values: dict | None = None, | |
| ): | |
| """Build and compile the LangGraph chatbot app. | |
| Pass either ``metrics_df`` (in-memory mode) or ``db_query_fn`` + ``column_values`` | |
| (SQL mode: targeted SQLite query per user message). | |
| """ | |
| return build_chatbot_graph( | |
| metrics_df=metrics_df, | |
| azure_openai_client=chat_client, | |
| db_query_fn=db_query_fn, | |
| column_values=column_values, | |
| ) | |
| def invoke_langgraph_chatbot( | |
| app: Any, | |
| user_query: str, | |
| conversation_history: list[dict] | None = None, | |
| prior_filters: dict | None = None, | |
| ) -> dict: | |
| """Invoke chatbot graph and return final graph state.""" | |
| initial_state = create_initial_state( | |
| user_query=user_query, | |
| conversation_history=conversation_history, | |
| prior_filters=prior_filters, | |
| ) | |
| return app.invoke(initial_state) | |