SQL-ChatBot / app.py
AliInamdar's picture
Update app.py
2fba167 verified
raw
history blame
955 Bytes
import os
import requests
def test_together_api():
TOGETHER_API_KEY = os.environ.get("TOGETHER_API_KEY")
print("πŸ” API Key starts with:", TOGETHER_API_KEY[:8] if TOGETHER_API_KEY else "None")
if not TOGETHER_API_KEY:
raise RuntimeError("❌ TOGETHER_API_KEY not found. Set it in Hugging Face > Settings > Secrets.")
url = "https://api.together.xyz/v1/chat/completions"
headers = {
"Authorization": f"Bearer {TOGETHER_API_KEY}",
"Content-Type": "application/json"
}
payload = {
"model": "mistralai/Mixtral-8x7B-Instruct-v0.1",
"messages": [{"role": "user", "content": "Write a SQL query to select all rows from table `df`"}],
"temperature": 0.2,
"max_tokens": 200
}
response = requests.post(url, headers=headers, json=payload)
print("βœ… API call status:", response.status_code)
print("πŸ“¦ Response JSON:", response.json())
test_together_api()