Select relevant tables given a natural language query
()
| 42 | |
| 43 | @bp.route('/get_tables', methods=['POST']) |
| 44 | def get_tables(): |
| 45 | """ |
| 46 | Select relevant tables given a natural language query |
| 47 | """ |
| 48 | request_body = request.get_json() |
| 49 | natural_language_query = request_body.get("natural_language_query") |
| 50 | session_id = request_body.get("session_id") |
| 51 | parent_id = request_body.get("parent_id") |
| 52 | if parent_id in ["", "None", "null" ]: |
| 53 | parent_id = None |
| 54 | if session_id in ["", "None", "null" ]: |
| 55 | session_id = None |
| 56 | |
| 57 | if not natural_language_query: |
| 58 | error_msg = 'natural_language_query is missing from request body' |
| 59 | return make_response(jsonify({"error": error_msg}), 400) |
| 60 | |
| 61 | # if it's featured, just pull it from the db |
| 62 | scope = request_body.get('scope', "USA") |
| 63 | cached_tables = featured_queries.get_featured_table(natural_language_query, scope) |
| 64 | if cached_tables and len(cached_tables) > 0: |
| 65 | return make_response(jsonify({"table_names": cached_tables}), 200) |
| 66 | |
| 67 | natural_language_query = replace_unsupported_localities(natural_language_query, scope) |
| 68 | |
| 69 | async def run_tasks(): |
| 70 | relevant_tables_task = asyncio.create_task(get_relevant_tables_async(natural_language_query, scope, session_id = session_id)) |
| 71 | labels_task = asyncio.create_task(create_labels(natural_language_query, scope, parent_id=parent_id, session_id = session_id)) |
| 72 | |
| 73 | table_names = await relevant_tables_task |
| 74 | generation_id = await labels_task |
| 75 | return table_names, generation_id |
| 76 | |
| 77 | table_names, generation_id = asyncio.run(run_tasks()) |
| 78 | |
| 79 | return make_response(jsonify({"table_names": table_names, 'generation_id': generation_id}), 200) |
| 80 | |
| 81 | |
| 82 | @bp.route('/explain_sql', methods=['POST']) |
nothing calls this directly
no test coverage detected