Skip to content

Commit

Permalink
Merge pull request #154 from F33RNI/next
Browse files Browse the repository at this point in the history
MS Copilot (LMAO API)
  • Loading branch information
F33RNI authored Apr 2, 2024
2 parents bb07a54 + 34779e9 commit 4ace386
Show file tree
Hide file tree
Showing 26 changed files with 329 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ conversations/
user_images
EdgeGPT_cookies.json
MSCopilot_cookies.json
MS_Copilot_cookies.json
Bard_cookies.json
ChatGPT_cookies.json
data/
Expand Down
31 changes: 23 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@

> 😔 Currently, GPT-Telegramus doesn't have paid ChatGPT and DALL-E support
>
> 📈 GPT-Telegramus v5 is an updated and highly refactored version of the old GPT-Telegramus. Updates coming soon....
> 📈 GPT-Telegramus v5 is an updated and highly refactored version of the old GPT-Telegramus
>
> 📄 Documentation is also under development! Consider reading docstring for now
>
> 🐛 If you find a **bug** in GPT-Telegramus, please create an Issue
>
> p.s. Due to my studies, I don't have much time to work on the project 😔
----------

Expand Down Expand Up @@ -62,6 +64,15 @@

----------

## 📨 Project channel and demo

- You can join official project's Telegram channel <https://t.me/vestnik_labasera>
- Also you can test GPT-Telegramus using official bot <https://t.me/labasyor3000_bot>

⚠️ Please do not overload the bot and use it only as a demo version

----------

## 🏗️ Requirements

- Python **3.10** / **3.11** *(not tested on other versions)*
Expand Down Expand Up @@ -103,9 +114,13 @@ See **🐧 Running as service on linux**, **🍓 Running on Raspberry Pi (ARM)**
- Supports conversation style `/style`
- Stream response support
- Chat history support
- Web-browsing (probably) and sources support
- Unfortunately, it can't accept images as input yet, nor can it generate them. Please use **Microsoft Copilot Designer** to generate images
- **Microsoft Copilot Designer**
- Web-browsing (probably) and sources (attributions) support
- Accepts image requests (for **lmao_ms_copilot** only)
- Send generated images (for **lmao_ms_copilot** only)
- Suggestions (for **lmao_ms_copilot** only)
- See <https://github.com/F33RNI/LlM-Api-Open> for more info
- **NOTE:** Non-LMAO API (the old one `ms_copilot`) is deprecated! Please use `lmao_ms_copilot` instead
- *Microsoft Copilot Designer* (**DEPRECATED**)
- Bing Image Generator. Used as a separate module due to issues with the EdgeGPT module
- Free and unlimited
- **Gemini**
Expand Down Expand Up @@ -232,6 +247,7 @@ See **🐧 Running as service on linux**, **🍓 Running on Raspberry Pi (ARM)**
- 🇺🇦 Українська
- فارسی 🇮🇷
- 🇪🇸 Español
- 🇻🇳 Vietnamese

You can add **a new language**. For that:

Expand Down Expand Up @@ -284,10 +300,9 @@ You can enable and configure data collection in `config.json` in `data_collectin
## 📝 TODO
- Official (and paid) ChatGPT API
- Official DALL-E API
- Microsoft Copilot as part of LMAO API
- Some free GPT-4 model
- Paid version of ChatGPT
- DALL-E (from OpenAI)
- Some other LLMs (and maybe some free GPT-4 model)
----------
Expand Down
2 changes: 1 addition & 1 deletion _version.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from packaging import version

__version__ = "5.0.3"
__version__ = "5.2.5"


def version_major() -> int:
Expand Down
Binary file modified banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions bot_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,42 @@ async def query_callback(self, update: Update, context: ContextTypes.DEFAULT_TYP
context,
)

# Send suggestion
elif action == "suggestion":
# Get last message ID
reply_message_id_last = self.users_handler.get_key(0, "reply_message_id_last", user=user)
if reply_message_id_last is None or reply_message_id_last != reply_message_id:
await _send_safe(user_id, self.messages.get_message("suggestion_error", lang_id=lang_id), context)
return

# Get module name and suggestion id
data_parts_ = data_.split("_")
suggestion_id = data_parts_[-1]
module_name_ = "_".join(data_parts_[:-1])

# Find suggestion
suggestions = self.users_handler.get_key(0, "suggestions", user=user, default_value=[])
suggestion = None
for suggestion_id_, suggestion_ in suggestions:
if suggestion_id_ == suggestion_id:
suggestion = suggestion_
break

# Check
if not suggestion:
logging.warning(f"No suggestion with ID {suggestion_id} saved")
await _send_safe(user_id, self.messages.get_message("suggestion_error", lang_id=lang_id), context)
return

# Ask
await self._bot_module_request_raw(
module_name_,
suggestion,
user_id,
reply_message_id_last,
context,
)

# Stop generating
elif action == "stop":
# Get last message ID
Expand Down Expand Up @@ -1410,18 +1446,24 @@ async def bot_command_users(self, update: Update, context: ContextTypes.DEFAULT_
database, key=lambda user: self.users_handler.get_key(0, "requests_total", 0, user=user), reverse=True
)

# Counters
users_banned_counter = 0
users_admin_counter = 0

# Add them to message
message = ""
module_default = self.config.get("modules").get("default")
for user_ in database:
# Banned?
if self.users_handler.get_key(0, "banned", False, user=user_):
users_banned_counter += 1
message += self.config.get("telegram").get("banned_symbol", "B") + " "
else:
message += self.config.get("telegram").get("non_banned_symbol", " ") + " "

# Admin?
if self.users_handler.get_key(0, "admin", False, user=user_):
users_admin_counter += 1
message += self.config.get("telegram").get("admin_symbol", "A") + " "
else:
message += self.config.get("telegram").get("non_admin_symbol", " ") + " "
Expand Down Expand Up @@ -1465,6 +1507,14 @@ async def bot_command_users(self, update: Update, context: ContextTypes.DEFAULT_
# Format final message
message = self.messages.get_message("users_admin", lang_id=lang_id).format(users_data=message)

# Add total stats
users_total_stats_formatter = self.messages.get_message("users_total_stats", lang_id=lang_id)
message += "\n" + users_total_stats_formatter.format(
users_num=len(database),
banned_num=users_banned_counter,
admins_num=users_admin_counter,
)

# Send as markdown
await bot_sender.send_reply(self.config.get("telegram").get("api_key"), user_id, message, markdown=True)

Expand Down
12 changes: 11 additions & 1 deletion bot_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def build_markup(
buttons.append(button_clear)

# Add change style button for MS Copilot
if request_response.module_name == "ms_copilot":
if request_response.module_name == "ms_copilot" or request_response.module_name == "lmao_ms_copilot":
button_style = InlineKeyboardButton(
messages_.get_message("button_style_change", user_id=user_id),
callback_data=f"style||{request_response.reply_message_id}",
Expand All @@ -233,6 +233,16 @@ def build_markup(
)
buttons.append(button_module)

# Add suggestions (their IDs must be saved into user database)
if request_response.response_suggestions and len(request_response.response_suggestions) != 0:
for suggestion_id, suggestion in request_response.response_suggestions:
data = f"{request_response.module_name}_{suggestion_id}"
button_style = InlineKeyboardButton(
messages_.get_message("suggestion_format", user_id=user_id).format(suggestion=suggestion),
callback_data=f"suggestion|{data}|{request_response.reply_message_id}",
)
buttons.append(button_style)

return InlineKeyboardMarkup(build_menu(buttons, n_cols=2))


Expand Down
14 changes: 7 additions & 7 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"__comment01__": "Version of config file. Please don't change it",
"config_version": 5,
"config_version": 6,

"__comment02__": "General config of enabled modules",
"__comment03__": "Available modules: lmao_chatgpt, ms_copilot, ms_copilot_designer, gemini",
"__comment03__": "Available modules: lmao_chatgpt, lmao_ms_copilot, ms_copilot, ms_copilot_designer, gemini",
"__comment04__": "NOTE: ms_copilot and ms_copilot_designer modules are DEPRECATED and will be removed soon",
"modules": {
"__comment01__": "Enabled modules",
"enabled": [
"lmao_chatgpt",
"ms_copilot",
"ms_copilot_designer",
"lmao_ms_copilot",
"gemini"
],

"__comment02__": "Default (initial) module for handling user messages",
"default": "lmao_chatgpt"
},

"__comment04__": "Paths to files and directories",
"__comment05__": "Paths to files and directories",
"files": {
"module_configs_dir": "module_configs",
"users_database": "users.json",
Expand All @@ -27,7 +27,7 @@
"messages_dir": "langs"
},

"__comment05__": "Telegram bot config",
"__comment06__": "Telegram bot config",
"telegram": {
"__comment01__": "Provide your bot api key from <https://t.me/BotFather>",
"api_key": "",
Expand Down Expand Up @@ -100,7 +100,7 @@
]
},

"__comment06__": "Save all requests and responses to the files",
"__comment07__": "Save all requests and responses to the files",
"data_collecting": {
"__comment01__": "Set true to automatically save all user's requests and responses into data_collecting_dir",
"__comment02__": "NOTE: You should notify users if it's enabled!",
Expand Down
7 changes: 7 additions & 0 deletions langs/bel.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
"stop_error_not_last": "❌ Памылка! Можна спыніць толькі апошні запрос!",
"stop_error": "❌ Памылка! Немагчыма спыніць дэгенерацыю",
"response_link_format": "\n📄 {source_name}: {link}",
"suggestion_format": "💡 {suggestion}",
"suggestion_error": "❌ Магчыма выкарыстоўваць прапанаваны запыт толькі з апошняга паведамлення!",
"users_read_error": "❌ Памылка чытання ці аналізу спісу карыстальнікаў!",
"users_admin": "Забанены? Адмін? Мова Модуль ID Имя - Запросаў\n\n{users_data}",
"users_total_stats": "Карыстальнікі: {users_num}, забаненыя {banned_num}, адміністратары: {admins_num}",
"restarting": "🙏 Выконваецца перазапуск...\nКалі ласка, пачакайце",
"restarting_done": "{reload_logs}\n✅ Перазапуск выкананы",
"chat_cleared": "✅ Гісторыя чата была ачышчана для {module_name}",
Expand Down Expand Up @@ -59,6 +62,10 @@
"icon": "💬",
"name": "ChatGPT (LMAO API)"
},
"lmao_ms_copilot": {
"icon": "🟦",
"name": "MS Copilot (LMAO API)"
},
"chatgpt": {
"icon": "💬",
"name": "ChatGPT"
Expand Down
7 changes: 7 additions & 0 deletions langs/eng.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
"stop_error_not_last": "❌ Error! Can only abort the last request!",
"stop_error": "❌ Error! Can not stop generating!",
"response_link_format": "\n📄 {source_name}: {link}",
"suggestion_format": "💡 {suggestion}",
"suggestion_error": "❌ It is possible to use the suggested request only from the last message!",
"users_read_error": "❌ Error reading or parsing list of users!",
"users_admin": "Banned? Admin? Language Module ID Name - Requests\n\n{users_data}",
"users_total_stats": "Users: {users_num}, banned {banned_num}, admins: {admins_num}",
"restarting": "🙏 Restarting in progress...\nPlease wait",
"restarting_done": "{reload_logs}\n✅ The restart is completed",
"chat_cleared": "✅ Chat history cleared for {module_name}",
Expand Down Expand Up @@ -59,6 +62,10 @@
"icon": "💬",
"name": "ChatGPT (LMAO API)"
},
"lmao_ms_copilot": {
"icon": "🟦",
"name": "MS Copilot (LMAO API)"
},
"chatgpt": {
"icon": "💬",
"name": "ChatGPT"
Expand Down
7 changes: 7 additions & 0 deletions langs/fas.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
"stop_error_not_last": "❌ خطا! فقط می توان آخرین درخواست را لغو کرد!",
"stop_error": "❌ خطا! نمی توان تولید را متوقف کرد!",
"response_link_format": "\n📄 {source_name}: {link}",
"suggestion_format": "💡 {suggestion}",
"suggestion_error": "❌ ممکن است از درخواست ارائه شده فقط از آخرین پیام استفاده شود!",
"users_read_error": "❌ خطا در خواندن یا تجزیه لیست کاربران!",
"users_admin": "ممنوع شد؟ مدیر؟ شناسه کاربری ماژول زبان نام - درخواست ها\n\n{users_data}",
"users_total_stats": "کاربران: {users_num}، مسدود‌شده‌ها: {banned_num}، مدیران: {admins_num}",
"restarting": "🙏 شروع مجدد در حال انجام است...\nلطفا صبور باشید",
"restarting_done": "{reload_logs}\n✅ راه اندازی مجدد کامل شد",
"chat_cleared": "✅ سابقه چت پاک شد برای {module_name}",
Expand Down Expand Up @@ -59,6 +62,10 @@
"icon": "💬",
"name": "ChatGPT (LMAO API)"
},
"lmao_ms_copilot": {
"icon": "🟦",
"name": "MS Copilot (LMAO API)"
},
"chatgpt": {
"icon": "💬",
"name": "ChatGPT"
Expand Down
7 changes: 7 additions & 0 deletions langs/ind.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
"stop_error_not_last": "❌ Kesalahan! Hanya bisa menghentikan permintaan terakhir!",
"stop_error": "❌ Kesalahan! Tidak dapat menghentikan penghasilan!",
"response_link_format": "\n📄 {source_name}: {link}",
"suggestion_format": "💡 {suggestion}",
"suggestion_error": "❌ Mungkin menggunakan permintaan yang diajukan hanya dari pesan terakhir!",
"users_read_error": "❌ Kesalahan membaca atau menguraikan daftar pengguna!",
"users_admin": "Dilarang? Admin? Bahasa Modul ID Nama - Permintaan\n\n{users_data}",
"users_total_stats": "Pengguna: {users_num}, diblokir {banned_num}, admin: {admins_num}",
"restarting": "🙏 Sedang dilakukan proses restart...\nTunggu sebentar",
"restarting_done": "{reload_logs}\n✅ Restart selesai",
"chat_cleared": "✅ Riwayat obrolan dibersihkan untuk {module_name}",
Expand Down Expand Up @@ -59,6 +62,10 @@
"icon": "💬",
"name": "ChatGPT (LMAO API)"
},
"lmao_ms_copilot": {
"icon": "🟦",
"name": "MS Copilot (LMAO API)"
},
"chatgpt": {
"icon": "💬",
"name": "ChatGPT"
Expand Down
7 changes: 7 additions & 0 deletions langs/rus.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
"stop_error_not_last": "❌ Ошибка! Можно прервать только последний запрос!",
"stop_error": "❌ Ошибка! Невозможно прекратить дегенерацию!",
"response_link_format": "\n📄 {source_name}: {link}",
"suggestion_format": "💡 {suggestion}",
"suggestion_error": "❌ Возможно использовать предложенный запрос только из последнего сообщения!",
"users_read_error": "❌ Ошибка чтения или анализа списка пользователей!",
"users_admin": "Забанен? Админ? Язык Модуль ID Имя - Запросов\n\n{users_data}",
"users_total_stats": "Пользователи: {users_num}, заблокированные: {banned_num}, администраторы: {admins_num}",
"restarting": "🙏 Выполняется перезапуск...\nПожалуйста, подождите",
"restarting_done": "{reload_logs}\n✅ Перезапуск завершен",
"chat_cleared": "✅ История чата была очищена для {module_name}",
Expand Down Expand Up @@ -59,6 +62,10 @@
"icon": "💬",
"name": "ChatGPT (LMAO API)"
},
"lmao_ms_copilot": {
"icon": "🟦",
"name": "MS Copilot (LMAO API)"
},
"chatgpt": {
"icon": "💬",
"name": "ChatGPT"
Expand Down
7 changes: 7 additions & 0 deletions langs/spa.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
"stop_error_not_last": "❌ Error! ¡Solo se puede detener la generación de la última solicitud!",
"stop_error": "❌ Error! ¡No se puede detener la generación!",
"response_link_format": "\n📄 {source_name}: {link}",
"suggestion_format": "💡 {suggestion}",
"suggestion_error": "❌ ¡Se puede utilizar la solicitud propuesta solo del último mensaje!",
"users_read_error": "❌ ¡Error al leer o analizar la lista de usuarios!",
"users_admin": "¿Baneado? ¿Admin? Idioma Módulo ID Nombre - Solicitudes\n\n{users_data}",
"users_total_stats": "Usuarios: {users_num}, prohibidos: {banned_num}, administradores: {admins_num}",
"restarting": "🙏 Reinicio en curso...\nEspera por favor",
"restarting_done": "{reload_logs}\n✅ El reinicio se ha completado",
"chat_cleared": "✅ Historial del chat borrado para {module_name}",
Expand Down Expand Up @@ -59,6 +62,10 @@
"icon": "💬",
"name": "ChatGPT (LMAO API)"
},
"lmao_ms_copilot": {
"icon": "🟦",
"name": "MS Copilot (LMAO API)"
},
"chatgpt": {
"icon": "💬",
"name": "ChatGPT"
Expand Down
Loading

0 comments on commit 4ace386

Please sign in to comment.