Spaces:
Runtime error
Runtime error
feat: synchronize text-to-sql-bot codebase with Hugging Face Space repository, including Docker build configurations
6086e71 Download backend/app/ai_features/explainer.py from LalitChaudhari3/PlainSQL: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/spaces/LalitChaudhari3/PlainSQL/resolve/main/backend/app/ai_features/explainer.py
- Command line
-
hf download hf://spaces/LalitChaudhari3/PlainSQL/backend/app/ai_features/explainer.py
-
curl -L -o explainer.py https://huggingface.co/spaces/LalitChaudhari3/PlainSQL/resolve/main/backend/app/ai_features/explainer.py
1.05 kB
| """ | |
| SQL Explainer — Converts SQL queries into plain English explanations. | |
| Uses LLM to generate non-technical descriptions of what a query does. | |
| """ | |
| import structlog | |
| from app.prompts.registry import get_prompt_registry | |
| logger = structlog.get_logger() | |
| class SQLExplainer: | |
| """Explains SQL queries in natural language for non-technical users.""" | |
| def __init__(self, llm_router): | |
| self.llm_router = llm_router | |
| def explain(self, sql: str, results_count: int = 0) -> str: | |
| """ | |
| Generate a plain English explanation of a SQL query. | |
| """ | |
| try: | |
| prompt_template = get_prompt_registry().get("sql_explanation") | |
| messages = prompt_template.render(sql=sql, results_count=results_count) | |
| explanation = self.llm_router.generate(messages, model_preference="fast", max_tokens=256) | |
| return explanation.strip() | |
| except Exception as e: | |
| logger.warning("sql_explanation_failed", error=str(e)) | |
| return "Unable to generate explanation at this time." | |