Spaces:
Runtime error
Runtime error
Download tools/explain_tool.py from AgamP/llm_recommendation_backend: direct link, hf CLI and curl.
- Browser
- Download file 1.4 kB
-
https://huggingface.co/spaces/AgamP/llm_recommendation_backend/resolve/main/tools/explain_tool.py
- Command line
-
hf download hf://spaces/AgamP/llm_recommendation_backend/tools/explain_tool.py
-
curl -L -o explain_tool.py https://huggingface.co/spaces/AgamP/llm_recommendation_backend/resolve/main/tools/explain_tool.py
1.4 kB
| from __future__ import annotations | |
| from typing import List, Optional | |
| from schemas.query_plan import QueryPlan | |
| from schemas.candidates import RankedList | |
| def explain(plan: QueryPlan, ranked: RankedList, catalog_lookup) -> str: | |
| """ | |
| Generate a simple textual explanation using catalog metadata. | |
| catalog_lookup: callable(assessment_id) -> dict with fields like name/url/test_type/duration. | |
| """ | |
| lines: List[str] = [] | |
| lines.append("Top recommendations:") | |
| for item in ranked.items: | |
| meta = catalog_lookup(item.assessment_id) or {} | |
| name = meta.get("name", item.assessment_id) | |
| url = meta.get("url", "") | |
| tt = meta.get("test_type_full") or meta.get("test_type") | |
| dur = meta.get("duration_minutes") or meta.get("duration") | |
| parts = [f"- {name}"] | |
| if tt: | |
| parts.append(f"[{tt}]") | |
| if dur: | |
| parts.append(f"~{dur} min") | |
| if url: | |
| parts.append(f"({url})") | |
| lines.append(" ".join(parts)) | |
| # Brief note on matching | |
| lines.append("") | |
| lines.append("Matched intent: " + plan.intent) | |
| if plan.must_have_skills: | |
| lines.append("Key skills: " + ", ".join(plan.must_have_skills[:5])) | |
| if plan.duration and plan.duration.minutes: | |
| lines.append(f"Duration preference: {plan.duration.mode or 'TARGET'} {plan.duration.minutes} minutes") | |
| return "\n".join(lines) | |