Skip to content

Instantly share code, notes, and snippets.

@njspok
Last active January 5, 2024 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save njspok/d0272aab1d2f0c9e52b92548fb4faef5 to your computer and use it in GitHub Desktop.
Save njspok/d0272aab1d2f0c9e52b92548fb4faef5 to your computer and use it in GitHub Desktop.
Скрипт для работы с chadgpt.ru, позволяет из консоли обращаться к боту
#!/usr/bin/env python3
# place file to execute directory
# chmod +x sgpt.py
# optional: mv sgpt.py sgpt
# run example: sgpt how find all pytohn files in direcotry in linux system
import requests
import sys
query = " ".join(sys.argv[1:])
# Ключ из личного кабинета, подставьте свой
CHAD_API_KEY = 'INSERT TOKEN HERE'
# Формируем запрос
request_json = {
"message": query,
"api_key": CHAD_API_KEY
}
# Отправляем запрос и дожидаемся ответа
response = requests.post(
url='https://ask.chadgpt.ru/api/public/gpt-3.5',
json=request_json
)
if response.status_code != 200:
print(f'Ошибка! Код http-ответа: {response.status_code}')
else:
# Получаем текст ответа и преобразовываем в dict
resp_json = response.json()
# Если успешен ответ, то выводим
if resp_json['is_success']:
resp_msg = resp_json['response']
used_words = resp_json['used_words_count']
print(f'Ответ от бота: {resp_msg}\nПотрачено слов: {used_words}')
else:
error = resp_json['error_message']
print(f'Ошибка: {error}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment