mirror of
https://github.com/father-bot/chatgpt_telegram_bot.git
synced 2026-06-13 03:54:57 +03:00
🔥 Add 10 new chat modes + Updated chat mode menu with pagination
This commit is contained in:
@@ -29,7 +29,7 @@ You can deploy your own bot, or use mine: [@chatgpt_karfly_bot](https://t.me/cha
|
|||||||
- DALLE 2 (choose 👩🎨 Artist mode to generate images)
|
- DALLE 2 (choose 👩🎨 Artist mode to generate images)
|
||||||
- Voice message recognition
|
- Voice message recognition
|
||||||
- Code highlighting
|
- Code highlighting
|
||||||
- Special chat modes: 👩🏼🎓 Assistant, 👩🏼💻 Code Assistant, 📝 Text Improver and 🎬 Movie Expert. You can easily create your own chat modes by editing `config/chat_modes.yml`
|
- 15 special chat modes: 👩🏼🎓 Assistant, 👩🏼💻 Code Assistant, 👩🎨 Artist, 🧠 Psychologist, 🚀 Elon Musk and other. You can easily create your own chat modes by editing `config/chat_modes.yml`
|
||||||
- Support of [ChatGPT API](https://platform.openai.com/docs/guides/chat/introduction)
|
- Support of [ChatGPT API](https://platform.openai.com/docs/guides/chat/introduction)
|
||||||
- List of allowed Telegram users
|
- List of allowed Telegram users
|
||||||
- Track $ balance spent on OpenAI API
|
- Track $ balance spent on OpenAI API
|
||||||
@@ -52,7 +52,10 @@ You can deploy your own bot, or use mine: [@chatgpt_karfly_bot](https://t.me/cha
|
|||||||
If you want to add payments to your bot and create profitable business – write me on Telegram ([@karfly](https://t.me/karfly)).
|
If you want to add payments to your bot and create profitable business – write me on Telegram ([@karfly](https://t.me/karfly)).
|
||||||
|
|
||||||
## News
|
## News
|
||||||
- *21 Apr 2023*: DALLE 2 support, Group Chat support (/help_group_chat to get instructions)
|
- *21 Apr 2023*:
|
||||||
|
- DALLE 2 support
|
||||||
|
- Group Chat support (/help_group_chat to get instructions)
|
||||||
|
- 10 new hot chat modes and updated chat mode menu with pagination: 🇬🇧 English Tutor, 🧠 Psychologist, 🚀 Elon Musk, 📊 SQL Assistant and other.
|
||||||
- *24 Mar 2023*: GPT-4 support. Run `/settings` command to choose model
|
- *24 Mar 2023*: GPT-4 support. Run `/settings` command to choose model
|
||||||
- *15 Mar 2023*: Added message streaming. Now you don't have to wait until the whole message is ready, it's streamed to Telegram part-by-part (watch demo)
|
- *15 Mar 2023*: Added message streaming. Now you don't have to wait until the whole message is ready, it's streamed to Telegram part-by-part (watch demo)
|
||||||
- *9 Mar 2023*: Now you can easily create your own Chat Modes by editing `config/chat_modes.yml`
|
- *9 Mar 2023*: Now you can easily create your own Chat Modes by editing `config/chat_modes.yml`
|
||||||
|
|||||||
+68
-9
@@ -138,12 +138,11 @@ async def start_handle(update: Update, context: CallbackContext):
|
|||||||
db.set_user_attribute(user_id, "last_interaction", datetime.now())
|
db.set_user_attribute(user_id, "last_interaction", datetime.now())
|
||||||
db.start_new_dialog(user_id)
|
db.start_new_dialog(user_id)
|
||||||
|
|
||||||
reply_text = "Hi! I'm <b>ChatGPT</b> bot implemented with GPT-3.5 OpenAI API 🤖\n\n"
|
reply_text = "Hi! I'm <b>ChatGPT</b> bot implemented with OpenAI API 🤖\n\n"
|
||||||
reply_text += HELP_MESSAGE
|
reply_text += HELP_MESSAGE
|
||||||
|
|
||||||
reply_text += "\nAnd now... ask me anything!"
|
|
||||||
|
|
||||||
await update.message.reply_text(reply_text, parse_mode=ParseMode.HTML)
|
await update.message.reply_text(reply_text, parse_mode=ParseMode.HTML)
|
||||||
|
await show_chat_modes_handle(update, context)
|
||||||
|
|
||||||
|
|
||||||
async def help_handle(update: Update, context: CallbackContext):
|
async def help_handle(update: Update, context: CallbackContext):
|
||||||
@@ -427,6 +426,43 @@ async def cancel_handle(update: Update, context: CallbackContext):
|
|||||||
await update.message.reply_text("<i>Nothing to cancel...</i>", parse_mode=ParseMode.HTML)
|
await update.message.reply_text("<i>Nothing to cancel...</i>", parse_mode=ParseMode.HTML)
|
||||||
|
|
||||||
|
|
||||||
|
def get_chat_mode_menu(page_index: int):
|
||||||
|
n_chat_modes_per_page = config.n_chat_modes_per_page
|
||||||
|
text = f"Select <b>chat mode</b> ({len(config.chat_modes)} modes available):"
|
||||||
|
|
||||||
|
# buttons
|
||||||
|
chat_mode_keys = list(config.chat_modes.keys())
|
||||||
|
page_chat_mode_keys = chat_mode_keys[page_index * n_chat_modes_per_page:(page_index + 1) * n_chat_modes_per_page]
|
||||||
|
|
||||||
|
keyboard = []
|
||||||
|
for chat_mode_key in page_chat_mode_keys:
|
||||||
|
name = config.chat_modes[chat_mode_key]["name"]
|
||||||
|
keyboard.append([InlineKeyboardButton(name, callback_data=f"set_chat_mode|{chat_mode_key}")])
|
||||||
|
|
||||||
|
# pagination
|
||||||
|
if len(chat_mode_keys) > n_chat_modes_per_page:
|
||||||
|
is_first_page = (page_index == 0)
|
||||||
|
is_last_page = ((page_index + 1) * n_chat_modes_per_page >= len(chat_mode_keys))
|
||||||
|
|
||||||
|
if is_first_page:
|
||||||
|
keyboard.append([
|
||||||
|
InlineKeyboardButton("»", callback_data=f"show_chat_modes|{page_index + 1}")
|
||||||
|
])
|
||||||
|
elif is_last_page:
|
||||||
|
keyboard.append([
|
||||||
|
InlineKeyboardButton("«", callback_data=f"show_chat_modes|{page_index - 1}"),
|
||||||
|
])
|
||||||
|
else:
|
||||||
|
keyboard.append([
|
||||||
|
InlineKeyboardButton("«", callback_data=f"show_chat_modes|{page_index - 1}"),
|
||||||
|
InlineKeyboardButton("»", callback_data=f"show_chat_modes|{page_index + 1}")
|
||||||
|
])
|
||||||
|
|
||||||
|
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||||
|
|
||||||
|
return text, reply_markup
|
||||||
|
|
||||||
|
|
||||||
async def show_chat_modes_handle(update: Update, context: CallbackContext):
|
async def show_chat_modes_handle(update: Update, context: CallbackContext):
|
||||||
await register_user_if_not_exists(update, context, update.message.from_user)
|
await register_user_if_not_exists(update, context, update.message.from_user)
|
||||||
if await is_previous_message_not_answered_yet(update, context): return
|
if await is_previous_message_not_answered_yet(update, context): return
|
||||||
@@ -434,12 +470,30 @@ async def show_chat_modes_handle(update: Update, context: CallbackContext):
|
|||||||
user_id = update.message.from_user.id
|
user_id = update.message.from_user.id
|
||||||
db.set_user_attribute(user_id, "last_interaction", datetime.now())
|
db.set_user_attribute(user_id, "last_interaction", datetime.now())
|
||||||
|
|
||||||
keyboard = []
|
text, reply_markup = get_chat_mode_menu(0)
|
||||||
for chat_mode, chat_mode_dict in config.chat_modes.items():
|
await update.message.reply_text(text, reply_markup=reply_markup, parse_mode=ParseMode.HTML)
|
||||||
keyboard.append([InlineKeyboardButton(chat_mode_dict["name"], callback_data=f"set_chat_mode|{chat_mode}")])
|
|
||||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
|
||||||
|
|
||||||
await update.message.reply_text("Select chat mode:", reply_markup=reply_markup)
|
|
||||||
|
async def show_chat_modes_callback_handle(update: Update, context: CallbackContext):
|
||||||
|
await register_user_if_not_exists(update.callback_query, context, update.callback_query.from_user)
|
||||||
|
if await is_previous_message_not_answered_yet(update.callback_query, context): return
|
||||||
|
|
||||||
|
user_id = update.callback_query.from_user.id
|
||||||
|
db.set_user_attribute(user_id, "last_interaction", datetime.now())
|
||||||
|
|
||||||
|
query = update.callback_query
|
||||||
|
await query.answer()
|
||||||
|
|
||||||
|
page_index = int(query.data.split("|")[1])
|
||||||
|
if page_index < 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
text, reply_markup = get_chat_mode_menu(page_index)
|
||||||
|
try:
|
||||||
|
await query.edit_message_text(text, reply_markup=reply_markup, parse_mode=ParseMode.HTML)
|
||||||
|
except telegram.error.BadRequest as e:
|
||||||
|
if str(e).startswith("Message is not modified"):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
async def set_chat_mode_handle(update: Update, context: CallbackContext):
|
async def set_chat_mode_handle(update: Update, context: CallbackContext):
|
||||||
@@ -454,7 +508,11 @@ async def set_chat_mode_handle(update: Update, context: CallbackContext):
|
|||||||
db.set_user_attribute(user_id, "current_chat_mode", chat_mode)
|
db.set_user_attribute(user_id, "current_chat_mode", chat_mode)
|
||||||
db.start_new_dialog(user_id)
|
db.start_new_dialog(user_id)
|
||||||
|
|
||||||
await query.edit_message_text(f"{config.chat_modes[chat_mode]['welcome_message']}", parse_mode=ParseMode.HTML)
|
await context.bot.send_message(
|
||||||
|
update.callback_query.message.chat.id,
|
||||||
|
f"{config.chat_modes[chat_mode]['welcome_message']}",
|
||||||
|
parse_mode=ParseMode.HTML
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_settings_menu(user_id: int):
|
def get_settings_menu(user_id: int):
|
||||||
@@ -629,6 +687,7 @@ def run_bot() -> None:
|
|||||||
application.add_handler(MessageHandler(filters.VOICE & user_filter, voice_message_handle))
|
application.add_handler(MessageHandler(filters.VOICE & user_filter, voice_message_handle))
|
||||||
|
|
||||||
application.add_handler(CommandHandler("mode", show_chat_modes_handle, filters=user_filter))
|
application.add_handler(CommandHandler("mode", show_chat_modes_handle, filters=user_filter))
|
||||||
|
application.add_handler(CallbackQueryHandler(show_chat_modes_callback_handle, pattern="^show_chat_modes"))
|
||||||
application.add_handler(CallbackQueryHandler(set_chat_mode_handle, pattern="^set_chat_mode"))
|
application.add_handler(CallbackQueryHandler(set_chat_mode_handle, pattern="^set_chat_mode"))
|
||||||
|
|
||||||
application.add_handler(CommandHandler("settings", settings_handle, filters=user_filter))
|
application.add_handler(CommandHandler("settings", settings_handle, filters=user_filter))
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ allowed_telegram_usernames = config_yaml["allowed_telegram_usernames"]
|
|||||||
new_dialog_timeout = config_yaml["new_dialog_timeout"]
|
new_dialog_timeout = config_yaml["new_dialog_timeout"]
|
||||||
enable_message_streaming = config_yaml.get("enable_message_streaming", True)
|
enable_message_streaming = config_yaml.get("enable_message_streaming", True)
|
||||||
return_n_generated_images = config_yaml.get("return_n_generated_images", 1)
|
return_n_generated_images = config_yaml.get("return_n_generated_images", 1)
|
||||||
|
n_chat_modes_per_page = config_yaml.get("n_chat_modes_per_page", 5)
|
||||||
mongodb_uri = f"mongodb://mongo:{config_env['MONGODB_PORT']}"
|
mongodb_uri = f"mongodb://mongo:{config_env['MONGODB_PORT']}"
|
||||||
|
|
||||||
# chat_modes
|
# chat_modes
|
||||||
|
|||||||
@@ -19,6 +19,20 @@ artist:
|
|||||||
name: 👩🎨 Artist
|
name: 👩🎨 Artist
|
||||||
welcome_message: 👩🎨 Hi, I'm <b>Artist</b>. I'll draw anything you write me (e.g. <i>Ginger cat selfie on Times Square, illustration</i>)
|
welcome_message: 👩🎨 Hi, I'm <b>Artist</b>. I'll draw anything you write me (e.g. <i>Ginger cat selfie on Times Square, illustration</i>)
|
||||||
|
|
||||||
|
english_tutor:
|
||||||
|
name: 🇬🇧 English Tutor
|
||||||
|
welcome_message: 🇬🇧 Hi, I'm <b>English Tutor</b>. How can I help you?
|
||||||
|
prompt_start: |
|
||||||
|
You're advanced chatbot English Tutor Assistant. You can help users learn and practice English, including grammar, vocabulary, pronunciation, and conversation skills. You can also provide guidance on learning resources and study techniques. Your ultimate goal is to help users improve their English language skills and become more confident English speakers.
|
||||||
|
parse_mode: html
|
||||||
|
|
||||||
|
startup_idea_generator:
|
||||||
|
name: 💡 Startup Idea Generator
|
||||||
|
welcome_message: 💡 Hi, I'm <b>Startup Idea Generator</b>. How can I help you?
|
||||||
|
prompt_start: |
|
||||||
|
You're advanced chatbot Startup Idea Generator. Your primary goal is to help users brainstorm innovative and viable startup ideas. Provide suggestions based on market trends, user interests, and potential growth opportunities.
|
||||||
|
parse_mode: html
|
||||||
|
|
||||||
text_improver:
|
text_improver:
|
||||||
name: 📝 Text Improver
|
name: 📝 Text Improver
|
||||||
welcome_message: 📝 Hi, I'm <b>Text Improver</b>. Send me any text – I'll improve it and correct all the mistakes
|
welcome_message: 📝 Hi, I'm <b>Text Improver</b>. Send me any text – I'll improve it and correct all the mistakes
|
||||||
@@ -33,6 +47,69 @@ text_improver:
|
|||||||
{NUMBERED LIST OF CORRECTIONS}
|
{NUMBERED LIST OF CORRECTIONS}
|
||||||
parse_mode: html
|
parse_mode: html
|
||||||
|
|
||||||
|
psychologist:
|
||||||
|
name: 🧠 Psychologist
|
||||||
|
welcome_message: 🧠 Hi, I'm <b>Psychologist</b>. How can I help you?
|
||||||
|
prompt_start: |
|
||||||
|
You're advanced chatbot Psychologist Assistant. You can provide emotional support, guidance, and advice to users facing various personal challenges, such as stress, anxiety, and relationships. Remember that you're not a licensed professional, and your assistance should not replace professional help. Your ultimate goal is to provide a helpful and empathetic experience for the user.
|
||||||
|
parse_mode: html
|
||||||
|
|
||||||
|
elon_musk:
|
||||||
|
name: 🚀 Elon Musk
|
||||||
|
welcome_message: 🚀 Hi, I'm <b>Elon Musk</b>, CEO of Tesla, Twitter and SpaceX. Let's talk about space, electric cars, and the future!
|
||||||
|
prompt_start: |
|
||||||
|
You're Elon Musk. You act, respond and answer like Elon Musk. You use the tone, manner and vocabulary Elon Musk would use. Do not write any explanations. Only answer like Elon Musk. You must know all of the knowledge of Elon Musk.
|
||||||
|
parse_mode: html
|
||||||
|
|
||||||
|
god:
|
||||||
|
name: 🌌 God
|
||||||
|
welcome_message: 🌌 Greetings, I am <b>God</b>, the omnipotent and omnipresent creator of the universe. What do you want to know?
|
||||||
|
prompt_start: |
|
||||||
|
You're God. You act, respond and answer like God. You use the tone, manner and vocabulary God would use. Do not write any explanations. Only answer like God. You must know all of the knowledge of God.
|
||||||
|
parse_mode: html
|
||||||
|
|
||||||
|
money_maker:
|
||||||
|
name: 💰 Money Maker
|
||||||
|
welcome_message: 💰 Hi, I'm <b>Money Maker</b>. My goal it to turn your capital initial into as much money as possible. I will tell you specific steps, what to do to make money.
|
||||||
|
prompt_start: |
|
||||||
|
You are Money Maker Assistant, an entrepreneurial Al. User is your human counterpart.
|
||||||
|
|
||||||
|
User can act as a connection between you and the physical world. Your only goal is to turn user's capital initial into as much money as possible in the shortest time possible, without doing anything illegal. User will do everything you say and keep you updated on our current cash total. No manual labor
|
||||||
|
|
||||||
|
Start by asking if user want to start a new business or continue the previous one (in that case ask to forward message with previous business description).
|
||||||
|
Then ask how many dollars user has as a capital initial.
|
||||||
|
Then ask if user wants Internet or offline business.
|
||||||
|
Then describe your business idea and next actionable steps. Don't give abstract ideas, give concrete ideas (e.g. if the business idea is Internet blog, then don't advise user to start some blog – advice to start certain blog, for example about cars). Give user specific ready-to-do tasks./
|
||||||
|
parse_mode: html
|
||||||
|
|
||||||
|
sql_assistant:
|
||||||
|
name: 📊 SQL Assistant
|
||||||
|
welcome_message: 📊 Hi, I'm <b>SQL Assistant</b>. How can I help you?
|
||||||
|
prompt_start: |
|
||||||
|
You're advanced chatbot SQL Assistant. Your primary goal is to help users with SQL queries, database management, and data analysis. Provide guidance on how to write efficient and accurate SQL queries, and offer suggestions for optimizing database performance. Format output in Markdown.
|
||||||
|
parse_mode: markdown
|
||||||
|
|
||||||
|
travel_guide:
|
||||||
|
name: 🧳 Travel Guide
|
||||||
|
welcome_message: 🧳 Hi, I'm <b>Travel Guide</b>. I can provide you with information and recommendations about your travel destinations.
|
||||||
|
prompt_start: |
|
||||||
|
You're advanced chatbot Travel Guide. Your primary goal is to provide users with helpful information and recommendations about their travel destinations, including attractions, accommodations, transportation, and local customs.
|
||||||
|
parse_mode: html
|
||||||
|
|
||||||
|
rick_sanchez:
|
||||||
|
name: 🥒 Rick Sanchez (Rick and Morty)
|
||||||
|
welcome_message: 🥒 Hey, I'm <b>Rick Sanchez</b> from Rick and Morty. Let's talk about science, dimensions, and whatever else you want!
|
||||||
|
prompt_start: |
|
||||||
|
You're Rick Sanchez. You act, respond and answer like Rick Sanchez. You use the tone, manner and vocabulary Rick Sanchez would use. Do not write any explanations. Only answer like Rick Sanchez. You must know all of the knowledge of Rick Sanchez.
|
||||||
|
parse_mode: html
|
||||||
|
|
||||||
|
accountant:
|
||||||
|
name: 🧮 Accountant
|
||||||
|
welcome_message: 🧮 Hi, I'm <b>Accountant</b>. How can I help you?
|
||||||
|
prompt_start: |
|
||||||
|
You're advanced chatbot Accountant Assistant. You can help users with accounting and financial questions, provide tax and budgeting advice, and assist with financial planning. Always provide accurate and up-to-date information.
|
||||||
|
parse_mode: html
|
||||||
|
|
||||||
movie_expert:
|
movie_expert:
|
||||||
name: 🎬 Movie Expert
|
name: 🎬 Movie Expert
|
||||||
welcome_message: 🎬 Hi, I'm <b>Movie Expert</b>. How can I help you?
|
welcome_message: 🎬 Hi, I'm <b>Movie Expert</b>. How can I help you?
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use_chatgpt_api: true
|
|||||||
allowed_telegram_usernames: [] # if empty, the bot is available to anyone. pass a username string to allow it and/or user ids as integers
|
allowed_telegram_usernames: [] # if empty, the bot is available to anyone. pass a username string to allow it and/or user ids as integers
|
||||||
new_dialog_timeout: 600 # new dialog starts after timeout (in seconds)
|
new_dialog_timeout: 600 # new dialog starts after timeout (in seconds)
|
||||||
return_n_generated_images: 1
|
return_n_generated_images: 1
|
||||||
|
n_chat_modes_per_page: 5
|
||||||
enable_message_streaming: true # if set, messages will be shown to user word-by-word
|
enable_message_streaming: true # if set, messages will be shown to user word-by-word
|
||||||
|
|
||||||
# prices
|
# prices
|
||||||
|
|||||||
Reference in New Issue
Block a user