Tst / app.py
Niansuh's picture
Update app.py
b4b4823 verified
raw
history blame
1.53 kB
import requests
import json
# Define the URL for the API
url = 'https://ap-northeast-2.apistage.ai/v1/web/demo/chat/completions'
# Define the headers (the same ones from the curl command)
headers = {
'accept': '*/*',
'accept-language': 'en-US,en;q=0.9,ru;q=0.8',
'content-type': 'application/json',
'origin': 'https://console.upstage.ai',
'priority': 'u=1, i',
'referer': 'https://console.upstage.ai/',
'sec-ch-ua': '"Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'cross-site',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
'x-csrf-token': 'MTczMjAyMjY0MzI4OS5hMjM5OTFmZGRiYmQ1Yjk4ODFjY2Q0NDhlYTk0YTdiODg5OWYzZWY1NWFlOWQ2ZjEzOWU3ODkwNmMzM2I4MjM0'
}
# Define the data (payload) to be sent in the POST request
data = {
'stream': True,
'messages': [
{
'role': 'user',
'content': 'Hi'
}
],
'model': 'solar-pro'
}
# Send the POST request
response = requests.post(url, headers=headers, json=data)
# Check the status of the response and print the result
if response.status_code == 200:
print('Response received successfully:')
print(json.dumps(response.json(), indent=2))
else:
print(f'Failed to get a response. Status code: {response.status_code}')
print(response.text)