Python script that connects a Telegram bot with OpenAI gpt-3.5 and whisper API. You can set the system prompt using the /start command and then send a user prompt writing a message. Also, you can send voice messages to transcript it.
- Python 3.7.1
- openai 0.27.0
- python-telegram-bot 20.1
- python-dotenv 0.21.1
- pydub 0.25.1
- ffprobe 0.5
- Copy the .env-template file and renamed it .env
- Create an account on OpenAI
- On the side menu go to USER > API Keys (https://platform.openai.com/account/api-keys)
- Click on Create a new secret key
- Copy your secret API key and set it as the OPENAI_API_KEY in the .env file
- Find BotFather in telegram and write the command /newbot
- Set the name of your bot
- Set the username of your bot (it must end with _bot)
- Copy your bot secret API key and set it as the TELEGRAM_TOKEN in the .env file
python3 main.py
- Find your bot and send the command /start to set the system prompt. This prompt set the context for the chatbot. By default, the system prompt is "You are a helpful assistant"
- Write a message to send a user prompt with the system prompt as context
- You can also send a voice message to get a transcription