- About
- Start
- ChatGPT
- DALL·E
- Stable Diffusion
- Account and buy
- API tokens
- Database
- How to deploy
- License
Nowadays neural networks are able to conduct a dialogue, quickly search for the information we need, answer questions and draw pictures from words. This is a Telegram bot written in Python that allows you to chat with ChatGPT and generate images using DALL·E and Stable Diffusion, payments are implemented using Crypto Bot. I think it is very comfortable to unite these neural networks in one Telegram bot.
When the user enters the start command, the bot sends him a welcome message stating that the user has free 3000 ChatGPT tokens, 3 DALL·E image generations and 3 Stable Diffusion image generations and displays 4 buttons: "💭Chatting — ChatGPT-4o", "🌄Image generation — DALL·E 3", "🌅Image generation — Stable Diffusion 3" and "👤My account | 💰Buy". If the user is already registered, the bot only displays buttons.
If the user wants to chat with ChatGPT, he presses the "💭Chatting — ChatGPT" button and chats.
This bot saves the context of the dialogue!
In openaitools.py in the OpenAiTools class there are three parameters in the get_chatgpt function:
model
- The model which is used for generation.
max_tokens
- The maximum number of tokens that can be generated in the chat completion.
temperature
- What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.
If the user wants to generate image with DALL·E, he presses the "🌄Image generation — DALL·E" button and generates.
Generated image:
In openaitools.py in the OpenAiTools class there are three parameters in the get_dalle function:
model
- The model which is used for generation.
n
- The number of images to generate. Must be between 1 and 10.
size
- The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024.
If the user wants to generate image with Stable Diffusion, he presses the "🌅Image generation — Stable Diffusion" button and generates.
Generated image:
In stablediffusion.py there is one parameter:
model
- The model to use for generation: sd3-medium requires 3.5 credits per generation, sd3-large requires 6.5 credits per generation, sd3-large-turbo requires 4 credits per generation.
If the user wants to see account information or buy tokens and generations, he presses the "👤My account | 💰Buy" button. After pressing the button, the bot displays information about the rest of the user's ChatGPT tokens, DALL·E image generations and Stable Diffusion image generations. If the user wants to buy tokens and generations, he presses the "💰Buy tokens and generations" button, selects the product and currency. After that, the user needs to press the "💰Buy" button and pay in Crypto Bot if he wants to pay. If the user has paid, he should press "☑️Check" button and tokens or image generations will be added to his account. If the user hasn't paid, the bot will display the message "⌚️We have not received payment yet".
Payments are processed via webhooks.
These project needs these API tokens:
OPENAI_API_KEY
- OpenAI API key which you can get here: OpenAI API key
STABLE_DIFFUSION_API_KEY
- Stable Diffusion API key which you can get here: Stable Diffusion API key
TELEGRAM_BOT_TOKEN
- Telegram Bot API key which you can get here after creation of your bot: @BotFather
CRYPTOPAY_KEY
- Crypto Bot API key which you can get here after registration in bot (Crypto Pay - Create App): @CryptoBot
This project requires PostgreSQL database with two tables: users(user_id, username, chatgpt, dall_e, stable_diffusion), orders(invoice_id, user_id, product) and messages(id, user_id, role, content, messages).
Users and information about them will be added to the "users" table, orders will be added to the "orders" table and ChatGPT context window messages will be added to the "messages" table.
DATABASE_URL
- url to database.
This project was deployed on the Railway.
For deployment you just need to create the GitHub repository, click "Start a New Project" button on the Railway website.
After that you need to choose "Deploy from GitHub repo".
Here you need to choose your repository.
After that click "add variables".
Add your project's variables. For example, for this project you need to add here 4 variables: CRYPTOPAY_KEY, OPENAI_API_KEY, STABLE_DIFFUSION_API_KEY and TELEGRAM_BOT_TOKEN.
Return to your project and add database.
Choose PostgreSQL.
Go back to the variables and add DATABASE_URL via "Add reference".
Also go to worker – Settings – Public network and click “Generate Domain”. Copy this domain and add it to the "BASE_WEBHOOK_URL" variable. It should be something like “https://Your unique part.up.railway.app/”. After that, go to Crypto Bot - Crypto Pay - My Applications - Your Application - Webhooks, click "Enable Webhooks" and send the URL "https://Your unique part.up.railway.app/CRYPTO BOT API TOKEN".
All variables:
License - this project is licensed under Apache-2.0 license.