-
-
Save 4l3j4ndr0/13856bb291af88bce51928c7b0ee294f to your computer and use it in GitHub Desktop.
REST API for Natural Language Queries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @app.route('/api/sql-query', methods=['POST', 'OPTIONS']) | |
| def natural_language_sql(): | |
| """Process a natural language query, convert it to SQL, and execute it""" | |
| # Get request data | |
| data = request.get_json() | |
| natural_language_query = data['query'] | |
| # Process natural language to SQL query and execute | |
| result = bedrock_service.natural_language_to_sql_result(natural_language_query) | |
| # Prepare response | |
| response = { | |
| 'natural_language_query': natural_language_query, | |
| 'sql_query': result.get('sql_query'), | |
| 'result': result.get('result', []), | |
| 'row_count': result.get('row_count', 0), | |
| 'column_names': result.get('column_names', []) | |
| } | |
| return jsonify(response), 200 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment