A telegram bot to interact with OpenAI API.
 
 
 
Go to file
pluja 9767c18110 small optimizations 2023-05-03 12:45:55 +02:00
piper replace spanish voice to hispanic 2023-04-28 17:56:17 +02:00
.gitignore Use piper for realistic TTS, remove google tts 2023-04-28 15:48:52 +02:00
Dockerfile Use piper for realistic TTS, remove google tts 2023-04-28 15:48:52 +02:00
README.md Use piper for realistic TTS, remove google tts 2023-04-28 15:48:52 +02:00
database.py Fix database connection 2023-04-19 20:58:59 +02:00
docker-compose.yml fix compose 2023-04-19 18:17:43 +02:00
entrypoint.sh improve piper script and better quaility for language guessing 2023-04-28 17:50:01 +02:00
example.env Bug fixes and optimizations 2023-04-29 18:34:20 +02:00
main.py small optimizations 2023-05-03 12:45:55 +02:00
requirements.txt Use piper for realistic TTS, remove google tts 2023-04-28 15:48:52 +02:00
utils.py Use piper for realistic TTS, remove google tts 2023-04-28 15:48:52 +02:00

README.md

Please don't upload to GitHub

OpenAI API Telegram Bot

A telegram bot to interact with OpenAI API. You can:

  • Generate images with DALL-E: /imagine
  • Chat with ChatGPT: Just chat!
  • Transcribe audio and video to text: Just send a voice message or a video file!
  • Voice chat with ChatGPT:
    • Send voice message.
    • Receive voice messages.
    • Use 100% local Text-To-Speech with Language Recognition to give ChatGPT a voice in many languages!

Other features include:

  • Talk to ChatGPT with audio transcriptions (whisper).
  • Clear ChatGPT context history (to save tokens).
  • Reply to any message to use it as context for ChatGPT.
  • Per-user context.
  • See usage metrics and spent $.
  • Persistent data with sqlite3 database.
  • Lightweight: few lines of code.

Jump to selfhosting guide

Self-hosting

Self hosting this chatbot is pretty easy. You just need to follow this steps:

  1. Get your OPENAI Token from here.

    • You will need to set a payment method.
  2. Generate a new bot:

    1. Start a new chat with @BotFather bot.
    2. Type /newbot command. Set a name and a username.
    3. Copy the Token that BotFather will give you.
  3. Get allowed users' IDs:

    1. Start a new chat with @RawDataBot.
    2. Send a message or forward a message from any desired user.
    3. Copy the message.from.id field value. Should be an ID like: 1234567890
  4. Setup the bot:

    1. Clone this repo.
    2. Rename the example.env file to .env.
    3. Edit the environment variables from the .env file:
      • Set your OPENAI_TOKEN.
      • Set your BOT_TOKEN.
      • Set your ALLOWED_USERS (comma separated user ids). Set it to * to allow all users.
      • Set the SYSTEM_PROMPT for ChatGPT. This is always instructed to ChatGPT as the system.
      • Optional: Edit the MAX_CONTEXT. This variable sets the number of messages that will be sent to ChatGPT API as context for the conversation.
      • WHISPER_TO_GPT allows you to choose wether Whisper transcripts should be instructed to ChatGPT or not.
        • You can also configure this using /settings in chat.
      • ENABLE_GOOGLE_TTS the TTS service will be provided by GoogleTTS, producing more natural voices. If disabled, it fallsback to local voice generation using Espeak.
      • VOICE_LANGUAGE country code for the default voice accent.
    4. Build and start the bot: docker compose up --build -d.
  5. Enjoy!

Usage

  • By simply sending normal chat messages, you will be interacting with ChatGPT.

    • The last 5 messages (from user and bot) are sent to ChatGPT API as context.
    • Use the command /clear to clear your context and start over a completely new chat.
  • By using the /imagine <prompt> command, you will be getting images generated by DALL-E.

    • Example: /imagine A cat with a red hat.
  • Sending a voice message to the bot, it will transcribe it to text using Whisper.

  • Using /setttings you can configure a few settings.

  • /info command allows you to see your usage statistics.