PlainSQL / backend /test_api_query.py
LalitChaudhari3's picture
feat: synchronize text-to-sql-bot codebase with Hugging Face Space repository, including Docker build configurations
6086e71
Raw
History Blame Contribute Delete
1.09 kB
import requests
import json
# 1. Login to get token
login_url = "http://127.0.0.1:8000/api/v1/auth/login"
login_payload = {
"username": "analyst",
"password": "analyst123"
}
try:
print("Logging in...")
login_response = requests.post(login_url, json=login_payload)
login_response.raise_for_status()
token_data = login_response.json()
token = token_data["access_token"]
print("Login successful. Token acquired.")
# 2. Call generate-sql endpoint
query_url = "http://127.0.0.1:8000/api/v1/generate-sql"
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
query_payload = {
"question": "show me top 5 employees",
"history": []
}
print("Sending query 'show me top 5 employees'...")
query_response = requests.post(query_url, json=query_payload, headers=headers)
print("Response Status:", query_response.status_code)
print("Response Body:")
print(json.dumps(query_response.json(), indent=2))
except Exception as e:
print("Request failed:", e)