Compare commits
2 Commits
198e2bed9a
...
794fcef380
| Author | SHA1 | Date | |
|---|---|---|---|
| 794fcef380 | |||
| 93d45a7bcd |
@ -1,5 +1,7 @@
|
|||||||
# Telegram Bot with ChatGPT
|
# Telegram Bot with ChatGPT
|
||||||
|
|
||||||
|
[Русский](./Readme.ru.md)
|
||||||
|
|
||||||
This is a simple Telegram bot that uses the ChatGPT model to generate responses to user messages. The bot is built using Python and the pyTelegramBotAPI package for interacting with the Telegram Bot API, and the OpenAI API for generating responses using the ChatGPT model.
|
This is a simple Telegram bot that uses the ChatGPT model to generate responses to user messages. The bot is built using Python and the pyTelegramBotAPI package for interacting with the Telegram Bot API, and the OpenAI API for generating responses using the ChatGPT model.
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
@ -45,3 +47,4 @@ If you find any issues or have any suggestions for improving the bot, please fee
|
|||||||
## License
|
## License
|
||||||
|
|
||||||
This project is licensed under the MIT License - see the `LICENSE` file for details.
|
This project is licensed under the MIT License - see the `LICENSE` file for details.
|
||||||
|
|
||||||
|
|||||||
48
Readme.ru.md
Normal file
48
Readme.ru.md
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
# Телеграм-бот с ChatGPT
|
||||||
|
|
||||||
|
Это простой Телеграм-бот, который использует модель ChatGPT для генерации ответов на сообщения пользователей. Бот создан на языке Python с использованием пакета pyTelegramBotAPI для взаимодействия с API ботов Телеграм и API OpenAI для генерации ответов с помощью модели ChatGPT.
|
||||||
|
|
||||||
|
## Требования
|
||||||
|
|
||||||
|
Для работы с этим ботом вам понадобятся:
|
||||||
|
|
||||||
|
- Python версии 3.6 или выше
|
||||||
|
- Токен Телеграм-бота (получить его можно, следуя инструкциям [здесь](https://core.telegram.org/bots#creating-a-new-bot))
|
||||||
|
- Ключ API OpenAI (получить его можно, зарегистрировавшись на сайте [здесь](https://beta.openai.com/signup/))
|
||||||
|
|
||||||
|
## Установка
|
||||||
|
|
||||||
|
Чтобы установить необходимые пакеты Python, выполните следующую команду:
|
||||||
|
|
||||||
|
`pip install -r requirements.txt`
|
||||||
|
|
||||||
|
Это установит пакеты pyTelegramBotAPI и openai, необходимые для работы бота.
|
||||||
|
|
||||||
|
## Использование
|
||||||
|
|
||||||
|
Чтобы запустить бота, выполните следующую команду:
|
||||||
|
|
||||||
|
`python bot.py`
|
||||||
|
|
||||||
|
Бот начнет работу и будет прослушивать входящие сообщения от пользователей. Когда пользователь отправит сообщение, бот сгенерирует ответ с помощью модели ChatGPT и отправит его пользователю.
|
||||||
|
|
||||||
|
## Использование 2
|
||||||
|
|
||||||
|
Для запуска бота просто выполните команду docker-compose up. Это запустит Docker-контейнер с работающим ботом.
|
||||||
|
|
||||||
|
## Настройка
|
||||||
|
|
||||||
|
Чтобы настроить бота, вам нужно изменить файл bot.py и заменить следующие заполнители на свои значения:
|
||||||
|
|
||||||
|
- YOUR_TELEGRAM_BOT_TOKEN_HERE: замените это на токен вашего Телеграм-бота
|
||||||
|
- YOUR_OPENAI_API_KEY_HERE: замените это на ключ API OpenAI
|
||||||
|
|
||||||
|
Вы также можете изменить функцию generate_response в файле bot.py, чтобы настроить генерацию ответов моделью ChatGPT.
|
||||||
|
|
||||||
|
## Внесение изменений
|
||||||
|
|
||||||
|
Если вы обнаружите какие-либо проблемы или у вас есть предложения по улучшению бота, не стесняйтесь открывать issue или отправлять запрос на изменение (pull request).
|
||||||
|
|
||||||
|
## Лицензия
|
||||||
|
|
||||||
|
Этот проект лицензирован под лицензией MIT - см. файл LICENSE для получения подробной информации.
|
||||||
4
bot.py
4
bot.py
@ -202,9 +202,9 @@ def handle_message(message):
|
|||||||
|
|
||||||
# Send the response back to the user with markdown formatting
|
# Send the response back to the user with markdown formatting
|
||||||
try:
|
try:
|
||||||
ans = bot.edit_message_text(chat_id=message.chat.id, message_id=answer.message_id, text=response_text , parse_mode='Markdown')
|
ans = bot.edit_message_text(chat_id=message.chat.id, message_id=answer.message_id, text=f"Finish reason: {reason} \nCost: {cost}" )
|
||||||
# Send response text with reason and cost formated
|
# Send response text with reason and cost formated
|
||||||
bot.reply_to(ans, f"Finish reason: {reason} \nCost: {cost}")
|
bot.reply_to(ans, response_text, parse_mode='Markdown')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
bot.reply_to(message, "Что-то пошло не так c ответом. Пробую другой метод...")
|
bot.reply_to(message, "Что-то пошло не так c ответом. Пробую другой метод...")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user