diff --git a/ModelMerge b/ModelMerge index 9bb6ce33..46815c80 160000 --- a/ModelMerge +++ b/ModelMerge @@ -1 +1 @@ -Subproject commit 9bb6ce33c8052e0868a0f1a33c7b7f0187d33349 +Subproject commit 46815c806b66852fa30fb016d882c1340a3946e9 diff --git a/README.md b/README.md index 1704c49d..6fb5016b 100644 --- a/README.md +++ b/README.md @@ -16,11 +16,11 @@

-The ChatGPT Telegram Bot is a powerful Telegram bot that utilizes the latest GPT models, including GPT-3.5/4/4 Turbo/4o, DALL·E 3, Groq Mixtral-8x7b/LLaMA2-70b, Gemini 1.5 Pro/Flash and the official Claude2.1/3/3.5 API. It enables users to engage in efficient conversations and information searches on Telegram. +The ChatGPT Telegram Bot is a powerful Telegram bot that utilizes the latest GPT models, including GPT-3.5/4/4 Turbo/4o, DALL·E 3, Groq Mixtral-8x7b/LLaMA2-70b, Gemini 1.5 Pro/Flash, the official Claude2.1/3/3.5 API and DuckDuckGo(gpt-4o-mini, claude-3-haiku, Meta-Llama-3.1-70B, Mixtral-8x7B). It enables users to engage in efficient conversations and information searches on Telegram. ## ✨ Features -- **Multiple AI Models**: Supports GPT-3.5/4/4 Turbo/4o, DALL·E 3, Groq Mixtral-8x7b/LLaMA2-70b, Gemini 1.5 Pro/Flash and the official Claude2.1/3/3.5 API. Also supports one-api/new-api. Utilizes a self-developed API request backend [SDK](https://github.com/yym68686/ModelMerge), independent of the OpenAI SDK. +- **Multiple AI Models**: Supports GPT-3.5/4/4 Turbo/4o, DALL·E 3, Groq Mixtral-8x7b/LLaMA2-70b, Gemini 1.5 Pro/Flash, the official Claude2.1/3/3.5 API and DuckDuckGo(gpt-4o-mini, claude-3-haiku, Meta-Llama-3.1-70B, Mixtral-8x7B). Also supports one-api/new-api. Utilizes a self-developed API request backend [SDK](https://github.com/yym68686/ModelMerge), independent of the OpenAI SDK. - **Multi-modal Q&A**: Supports Q&A for voice, audio, images and PDF/TXT/MD/python documents. Users can upload files directly in the chat box for use. - **Group Chat Topic Mode**: Supports enabling topic mode in group chats, isolating APIs, dialogue history, plugin configurations, and preferences between topics. - **Rich Plugin System**: Supports web search(DuckDuckGo and Google), URL summarization, arXiv paper summarization, and code interpreter. diff --git a/bot.py b/bot.py index 74e5b268..7bcc1208 100644 --- a/bot.py +++ b/bot.py @@ -135,7 +135,8 @@ async def command_bot(update, context, language=None, prompt=translator_prompt, time_stamps[convo_id][i] - time_stamps[convo_id][i - 1] for i in range(1, len(time_stamps[convo_id])) ] - print(f"Chat ID {convo_id} 时间间隔: {intervals},总时间:{sum(intervals)}") + if intervals: + print(f"Chat ID {convo_id} 时间间隔: {intervals},总时间:{sum(intervals)}") message = "\n".join(message_cache[convo_id]) message_cache[convo_id] = [] diff --git a/config.py b/config.py index 2a29374f..13314b14 100644 --- a/config.py +++ b/config.py @@ -6,7 +6,7 @@ from utils.i18n import strings from datetime import datetime from ModelMerge.src.ModelMerge.utils import prompt -from ModelMerge.src.ModelMerge.models import chatgpt, claude, groq, claude3, gemini, PLUGINS, whisper +from ModelMerge.src.ModelMerge.models import chatgpt, claude, groq, claude3, gemini, PLUGINS, whisper, DuckChat from ModelMerge.src.ModelMerge.models.base import BaseAPI from telegram import InlineKeyboardButton @@ -157,9 +157,9 @@ def get_ENGINE(user_id = None): temperature = float(os.environ.get('temperature', '0.5')) CLAUDE_API = os.environ.get('claude_api_key', None) -ChatGPTbot, SummaryBot, claudeBot, claude3Bot, groqBot, gemini_Bot, whisperBot = None, None, None, None, None, None, None +ChatGPTbot, SummaryBot, claudeBot, claude3Bot, groqBot, gemini_Bot, whisperBot, duckBot = None, None, None, None, None, None, None, None def update_ENGINE(data = None, chat_id=None): - global Users, ChatGPTbot, SummaryBot, claudeBot, claude3Bot, groqBot, gemini_Bot, whisperBot + global Users, ChatGPTbot, SummaryBot, claudeBot, claude3Bot, groqBot, gemini_Bot, whisperBot, duckBot if data: Users.set_config(chat_id, "engine", data) engine = Users.get_config(chat_id, "engine") @@ -183,8 +183,10 @@ def update_ENGINE(data = None, chat_id=None): if GOOGLE_AI_API_KEY and "gemini" in engine: gemini_Bot = gemini(api_key=f"{GOOGLE_AI_API_KEY}", engine=engine, system_prompt=systemprompt, temperature=temperature, convo_id=chat_id) + duckBot = DuckChat(model=engine) + def update_language_status(language, chat_id=None): - global Users, ChatGPTbot, SummaryBot, claudeBot, claude3Bot, groqBot, gemini_Bot, whisperBot + global Users, ChatGPTbot, SummaryBot, claudeBot, claude3Bot, groqBot, gemini_Bot, whisperBot, duckBot systemprompt = Users.get_config(chat_id, "systemprompt") claude_systemprompt = Users.get_config(chat_id, "claude_systemprompt") LAST_LANGUAGE = Users.get_config(chat_id, "language") @@ -198,7 +200,7 @@ def update_language_status(language, chat_id=None): claude_systemprompt = claude_systemprompt.replace(LAST_LANGUAGE, Users.get_config(chat_id, "language")) Users.set_config(chat_id, "systemprompt", systemprompt) Users.set_config(chat_id, "claude_systemprompt", claude_systemprompt) - if ChatGPTbot == None: + if duckBot == None: update_ENGINE(chat_id=chat_id) if ChatGPTbot: ChatGPTbot.system_prompt[chat_id] = systemprompt @@ -213,6 +215,9 @@ def update_language_status(language, chat_id=None): pass update_language_status(LANGUAGE) +if ChatGPTbot == None and duckBot: + Users.engine = "gpt-4o-mini" + def get_local_version_info(): current_directory = os.path.dirname(os.path.abspath(__file__)) @@ -255,7 +260,7 @@ def update_info_message(user_id = None): ]) def reset_ENGINE(chat_id, message=None): - global ChatGPTbot, claudeBot, claude3Bot, groqBot, gemini_Bot + global ChatGPTbot, claudeBot, claude3Bot, groqBot, gemini_Bot, duckBot api_key = Users.get_config(chat_id, "api_key") api_url = Users.get_config(chat_id, "api_url") engine = Users.get_config(chat_id, "engine") @@ -279,9 +284,11 @@ def reset_ENGINE(chat_id, message=None): groqBot.reset(convo_id=str(chat_id), system_prompt=systemprompt) if GOOGLE_AI_API_KEY and gemini_Bot: gemini_Bot.reset(convo_id=str(chat_id), system_prompt=systemprompt) + if duckBot: + duckBot.reset(convo_id=str(chat_id)) def get_robot(chat_id = None): - global ChatGPTbot, claudeBot, claude3Bot, groqBot, gemini_Bot + global ChatGPTbot, claudeBot, claude3Bot, groqBot, gemini_Bot, duckBot engine = Users.get_config(chat_id, "engine") if CLAUDE_API and "claude-2.1" in engine: robot = claudeBot @@ -303,12 +310,17 @@ def get_robot(chat_id = None): role = "user" api_key = GOOGLE_AI_API_KEY api_url = "https://generativelanguage.googleapis.com/v1beta/models/{model}:{stream}?key={api_key}" - else: + elif ChatGPTbot: robot = ChatGPTbot role = "user" api_key = Users.get_config(chat_id, "api_key") api_url = Users.get_config(chat_id, "api_url") api_url = BaseAPI(api_url=api_url).chat_url + else: + robot = duckBot + role = "user" + api_key = "duckduckgo" + api_url = None return robot, role, api_key, api_url @@ -407,6 +419,13 @@ def create_buttons(strings, plugins_status=False, lang="English", button_text=No "gemini-1.5-flash", ]) +if duckBot: + initial_model.extend([ + "claude-3-haiku", + "Meta-Llama-3.1-70B", + "Mixtral-8x7B", + ]) + if GET_MODELS: try: endpoint = BaseAPI(api_url=API_URL) diff --git a/requirements.txt b/requirements.txt index 786c1385..de368dec 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,9 +4,11 @@ python-telegram-bot[webhooks,rate-limiter]==21.0.1 lxml pytz +msgspec PyExecJS requests pdfminer.six +fake-useragent beautifulsoup4 tiktoken==0.6.0 duckduckgo-search==5.3.1 diff --git a/utils/decorators.py b/utils/decorators.py index 20cbaeea..2ebd6591 100644 --- a/utils/decorators.py +++ b/utils/decorators.py @@ -82,7 +82,7 @@ async def wrapper(*args, **kwargs): parse_mode='MarkdownV2', ) return - if (api_key and api_key.endswith("your_api_key")) or api_url.endswith("your_api_url"): + if (api_key and api_key.endswith("your_api_key")) or (api_url and api_url.endswith("your_api_url")): await context.bot.send_message(chat_id=chatid, message_thread_id=message_thread_id, text=escape(strings['message_api_error'][get_current_lang()]), parse_mode='MarkdownV2') return return await func(*args, **kwargs)