Skip to content

This is ChatGPT, DALL·E, Stable Diffusion python-telegram-bot with cryptocurrency payments. It allows you to generate images and chat with ChatGPT.

License

Notifications You must be signed in to change notification settings

vladislav-bordiug/ChatGPT_DALL_E_StableDiffusion_Telegram_Bot

Repository files navigation

ChatGPT, DALL·E, Stable Diffusion Telegram bot

Table of Contents

About

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.

Start

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.

Видео без названия — сделано в Clipchamp (5)

ChatGPT

If the user wants to chat with ChatGPT, he presses the "💭Chatting — ChatGPT" button and chats.

This bot saves the context of the dialogue!

Видео без названия — сделано в Clipchamp

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.

DALL·E

If the user wants to generate image with DALL·E, he presses the "🌄Image generation — DALL·E" button and generates.

Видео без названия — сделано в Clipchamp (1)

Generated image:

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.

Stable Diffusion

If the user wants to generate image with Stable Diffusion, he presses the "🌅Image generation — Stable Diffusion" button and generates.

Видео без названия — сделано в Clipchamp (2)

Generated image:

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.

Account and buy

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.

Видео без названия — сделано в Clipchamp (4)

API tokens

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

Database

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.

How to deploy

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.

image

After that you need to choose "Deploy from GitHub repo".

image

Here you need to choose your repository.

image

After that click "add variables".

image

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.

image

Return to your project and add database.

image

Choose PostgreSQL.

image

Here you need to press create tables.

image

For example, tables for this project:

Table for storing users:

image_2024-10-04_12-18-46

Table for storing orders:

image_2024-10-04_12-19-25

Table for storing context:

image_2024-10-04_12-17-50

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:

image

License

License - this project is licensed under Apache-2.0 license.

Releases

No releases published

Packages

No packages published