Skip to content

Telegram chatbot that uses OpenAI's GPT API to generate responses. Chatbot also translates voice messages to text and uses them as input when user says # /new, start a new conversation # /role, set the role of the user # /stats, show usage statistics # /suggestions <number>, show <number> suggestions in keyboard # /help writes the help message

License

Notifications You must be signed in to change notification settings

veonua/openai-telegram-bot

 
 

Repository files navigation

openai-telegram-bot

Telegram chatbot that uses OpenAI's GPT API to generate responses Chatbot also translates voice messages to text and uses them as input when user says

  • /new, start a new conversation
  • /role, set the role of the user
  • /stats, show usage statistics
  • /suggestions , show suggestions in keyboard
  • /help writes the help message

VOICE_MODEL = "whisper-1" TEXT_MODEL = "gpt-3.5-turbo"

Screenshot

Capture

Installation

To use this script, you will need to have Python 3.7 or later installed. You can download Python from the official website.

You will also need to install the following Python packages:

openai
aiogram
pydub

also you will need to install ffmpeg to convert voice messages to format that Whisper can transcribe to text

Usage

  1. Clone this repository to your local machine.
  2. Create an account on the OpenAI website and obtain an API key.
  3. Create a api_key.py file in the same directory as the script, and add your OpenAI API key to it.
key = "YOUR_API_KEY"
  1. Create a new bot on Telegram and obtain the bot_token.
  2. Run the script using the following command:
python openaitelegram.py
  1. Start a conversation with the bot on Telegram
  2. use /new command to start a new conversation.

To Do

  • Add basic statistics
  • Add suggestions keyboard
  • Add incoming voice messages support
  • Add feedback pool
  • Add outgoing voice messages support
  • Add web-site summary and Q&A
  • Add document Q&A using langchain

Note

You need to run this script on a server so that it can run 24/7, otherwise it will run only when you run the script on your local machine. Works on my Raspberry Pi 2 Model B

Additional Resources

Telethon documentation

OpenAI API documentation

Creating a Telegram bot

License

This script is licensed under the MIT license. Feel free to use and modify it for your own projects

Contribution

Feel free to contribute to this project by creating a pull request. Any contributions are welcome and appreciated.

About

Telegram chatbot that uses OpenAI's GPT API to generate responses. Chatbot also translates voice messages to text and uses them as input when user says # /new, start a new conversation # /role, set the role of the user # /stats, show usage statistics # /suggestions <number>, show <number> suggestions in keyboard # /help writes the help message

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%