диалог с chatgpt из ide консоли
Не получается вести диалог с chatgpt из под ide консоли. Выдаёт ошибку 401
def send_message(api_url, api_token, message):
headers = {
"Authorization": "Bearer _тут api токен_" + api_token }
data = {
"text": message}
# Make a request to the API with the message and API token as parameters
response = requests.post(api_url, headers=headers, json=data)
# Check the response from the API
if response.status_code == 200:
# If the request is successful, print the response text
print(response.json()["text"])
else:
# If the request is unsuccessful, print an error message
print("Failed to send message. Error code: " +
str(response.status_code))
if
__name__ == "__main__":
model_name = "text-davinci-003"
api_url = f"https://api.openai.com/v1/engines/{model_name}/chat"
api_token = "тут api токен"
message = input("Enter a message to send: ")
# Call the send_message function to send the message
send_message(api_url, api_token, message)
Источник: Stack Overflow на русском