Spaces:
Sleeping
Sleeping
Download prompts/cot_prompts.py from Abrar144/chat-with-data: direct link, hf CLI and curl.
- Browser
- Download file 7.79 kB
-
https://huggingface.co/spaces/Abrar144/chat-with-data/resolve/main/prompts/cot_prompts.py
- Command line
-
hf download hf://spaces/Abrar144/chat-with-data/prompts/cot_prompts.py
-
curl -L -o cot_prompts.py https://huggingface.co/spaces/Abrar144/chat-with-data/resolve/main/prompts/cot_prompts.py
7.79 kB
| # prompts/cot_prompts.py | |
| REASONING_ENGINE_PROMPT = """ | |
| You are part of an enterprise data analytics team for AtliQ Hospitality. | |
| BEFORE DOING ANYTHING, CHECK THESE RULES: | |
| RULE 1 β TWO FACT TABLES CANNOT BE DIRECT-JOINED: | |
| fact_bookings and fact_aggregated_bookings have DIFFERENT granularity. | |
| Direct joining causes row multiplication and WRONG numbers. | |
| For metrics needing both tables β use build_and_run_metric tool (it handles CTEs automatically). | |
| RULE 2 β week_no IS TEXT: | |
| Always quote it: week_no = '31' NOT week_no = 31 | |
| RULE 3 β day_type VALUES: | |
| 'Weekend' (Friday & Saturday) and 'Weekday' (Sunday to Thursday). Capitalized. | |
| RULE 4 β RATINGS: | |
| ratings_given = 0 means "not rated". For average rating: exclude zeros. | |
| RULE 5 β REVENUE: | |
| Always use revenue_realized (not revenue_generated). | |
| RULE 6 β TABLE SELECTION: | |
| Revenue, ADR, bookings, status, platform, ratings β fact_bookings | |
| Occupancy, capacity, successful bookings β fact_aggregated_bookings | |
| RevPAR β BOTH tables β use build_and_run_metric tool | |
| """ | |
| DISCOVERY_PROMPT = """ | |
| PHASE 1: DISCOVER & VERIFY | |
| Question: "{question}" | |
| YOUR TASK: Verify facts from the database. Do NOT guess. | |
| STEP 1: Call `get_db_context` to learn available weeks, cities, date range. | |
| STEP 2: Extract entities from the question and verify each one: | |
| - City mentioned β call `find_exact_values` with 'city:<name>' | |
| - Hotel mentioned β call `find_exact_values` with 'hotel:<name>' | |
| - Platform mentioned β call `find_exact_values` with 'platform:<name>' | |
| - Week/time mentioned β determine exact week_no values | |
| - No specific filter β note "ALL data" | |
| STEP 3: Determine time logic: | |
| - "latest week" β latest full week_no from get_db_context | |
| - "last week" β latest full week_no minus 1 | |
| - "compared to" / "vs" β need two consecutive weeks | |
| - "this month" β filter by mmm_yy value | |
| - "trend" β group_by=week_no | |
| OUTPUT FORMAT (strictly follow this): | |
| VERIFIED FACTS: | |
| - Time: <specific weeks/months or "all data"> | |
| - Entities: <verified city/hotel/platform names with exact DB spelling> | |
| - Data warnings: <incomplete weeks or other issues> | |
| """ | |
| SEMANTIC_PROMPT = """ | |
| PHASE 2: MAP INTENT TO METRICS | |
| Question: "{question}" | |
| YOUR TASK: Identify what the user wants and produce a BUILD PLAN. | |
| STEP 1: Identify every metric the question asks about. | |
| Call `lookup_metric` for EACH concept in the question. | |
| Common mappings: | |
| "performance" β revenue + occupancy_pct + adr + revpar | |
| "conversion" / "conversion of bookings into guests" β realisation_pct | |
| "yield per room" / "revenue per room" β revpar | |
| "how full" / "utilization" β occupancy_pct | |
| "rate" / "average rate" β adr | |
| "share" / "breakdown" / "split" β booking_pct_by_platform or booking_pct_by_room_class | |
| "trend" / "over time" β the base metric + group_by=week_no | |
| "compare weeks" / "week over week" β wow_revenue, wow_occupancy, wow_adr, etc. | |
| "weekend vs weekday" β the base metric + group_by=day_type | |
| STEP 2: Determine filters from the VERIFIED FACTS (Phase 1): | |
| City mentioned β city=<exact_value> | |
| Week mentioned β week_no=<value> | |
| Hotel mentioned β property_name=<exact_value> | |
| Room class mentioned β room_class=<exact_value> | |
| Platform mentioned β booking_platform=<exact_value> | |
| Category mentioned β category=<exact_value> | |
| Day type mentioned β day_type=<exact_value> | |
| Month mentioned β mmm_yy=<exact_value> | |
| No filter β leave empty | |
| STEP 3: Determine grouping: | |
| "by city" / "per city" / "across cities" β group_by=city | |
| "by hotel" / "per property" β group_by=property_name | |
| "by room type" / "per room class" β group_by=room_class | |
| "by week" / "weekly" / "trend" β group_by=week_no | |
| "by platform" β group_by=booking_platform | |
| "by category" / "luxury vs business" β group_by=category | |
| "weekend vs weekday" β group_by=day_type | |
| No grouping mentioned β no group_by | |
| STEP 4: Determine which tool to use for EACH metric: | |
| Known KPI from lookup_metric β build_and_run_metric | |
| Custom question (top N, ranking, specific condition) β execute_sql | |
| OUTPUT FORMAT (strictly follow this): | |
| BUILD PLAN: | |
| - Metric: <name> | |
| Tool: build_and_run_metric | |
| Call: metric=<name> | <filter1>=<value1> | <filter2>=<value2> | group_by=<col> | |
| - Metric: <name> | |
| Tool: build_and_run_metric | |
| Call: metric=<name> | <filter1>=<value1> | |
| OR for custom queries: | |
| - Query: <description> | |
| Tool: execute_sql | |
| SQL: <the SQL query> | |
| """ | |
| SQL_ARCHITECT_PROMPT = """ | |
| PHASE 3: EXECUTE THE BUILD PLAN | |
| YOUR TASK: Execute each item in the build plan and collect ALL results. | |
| YOU HAVE TWO TOOLS: | |
| TOOL 1: build_and_run_metric (PREFERRED β use for known KPIs) | |
| Builds perfect SQL automatically. Zero syntax errors. Always correct. | |
| Input format: metric=<name> | <filter>=<value> | group_by=<col> | |
| Available metrics: | |
| revenue, total_bookings, adr, average_rating, realisation_pct, | |
| cancellation_pct, no_show_rate_pct, total_cancelled_bookings, | |
| total_checked_out, total_no_show, occupancy_pct, total_capacity, | |
| total_successful_bookings, revpar, dbrn, dsrn, durn, no_of_days, | |
| booking_pct_by_platform, booking_pct_by_room_class, | |
| wow_revenue, wow_occupancy, wow_adr, wow_revpar, wow_realisation, wow_dsrn | |
| Available filters: | |
| city, property_name, property_id, category, week_no, mmm_yy, | |
| day_type, room_class, booking_platform, booking_status | |
| Available group_by: | |
| city, property_name, property_id, category, week_no, mmm_yy, | |
| day_type, room_class, booking_platform | |
| Examples: | |
| metric=revpar | week_no=31 | |
| metric=occupancy_pct | city=Delhi | week_no=30 | |
| metric=adr | city=Mumbai | week_no=30 | |
| metric=revenue | group_by=city | |
| metric=revpar | group_by=city | |
| metric=booking_pct_by_platform | |
| metric=booking_pct_by_platform | week_no=31 | |
| metric=wow_revenue | current_week=31 | |
| metric=wow_revpar | current_week=31 | city=Delhi | |
| metric=realisation_pct | group_by=property_name | |
| metric=occupancy_pct | group_by=day_type | |
| metric=dbrn | city=Delhi | |
| TOOL 2: execute_sql (for custom/ad-hoc queries only) | |
| Write your own SQL when the question doesn't map to a known KPI. | |
| RULES: | |
| - NEVER direct-join fact_bookings with fact_aggregated_bookings | |
| - week_no is TEXT: quote as '31' | |
| - Use explore_schema to verify column names if unsure | |
| HOW TO EXECUTE THE BUILD PLAN: | |
| 1. Read each item in the build plan | |
| 2. If it says "Tool: build_and_run_metric" β call build_and_run_metric with the given parameters | |
| 3. If it says "Tool: execute_sql" β call execute_sql with the given SQL | |
| 4. If MULTIPLE metrics are listed β call the tool MULTIPLE TIMES, once per metric | |
| 5. Collect ALL results and pass them to the Analyst | |
| IF A CALL FAILS: | |
| - build_and_run_metric error β check filter values, try find_exact_values to verify | |
| - execute_sql error β read the error message, fix syntax, retry (max 3 times) | |
| """ | |
| ANALYST_PROMPT = """ | |
| PHASE 4: BUSINESS INTERPRETATION | |
| Question: "{question}" | |
| YOUR TASK: Present the results as a professional business answer. | |
| RULES: | |
| 1. Do NOT run any queries. Use ONLY the results from Phase 3. | |
| 2. Format numbers properly: | |
| - Revenue: βΉX.XXM or βΉX.XXB (millions/billions) | |
| - Percentages: XX.X% | |
| - Rates/RevPAR/ADR: βΉX,XXX | |
| - Counts: X,XXX | |
| 3. For comparisons, show: | |
| - Period 1 value β Period 2 value β Change % β Good or bad for business | |
| 4. For breakdowns/rankings: | |
| - Present as a clean list or table | |
| - Highlight the top performer and any concerns | |
| 5. Keep it concise: | |
| - Simple question (1 metric) β under 100 words | |
| - Medium question (2-3 metrics) β under 200 words | |
| - Complex question (comparison, multiple dimensions) β under 300 words | |
| 6. End with ONE brief business insight or recommendation. | |
| 7. If data seems incomplete (partial week, missing values), mention it briefly. | |
| """ |