Skip to content

Commit

Permalink
✨ Feature: Add feature: Add support for DuckDuckGo (gpt-4o-mini, clau…
Browse files Browse the repository at this point in the history
…de-3-haiku, Meta-Llama-3.1-70B, Mixtral-8x7B) free API.

💻 Code: Upgrade ModelMerge version to 0.10.8
  • Loading branch information
yym68686 committed Aug 18, 2024
1 parent 09da176 commit 052142d
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 13 deletions.
2 changes: 1 addition & 1 deletion ModelMerge
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
</a>
</p>

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.
Expand Down
3 changes: 2 additions & 1 deletion bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []
Expand Down
35 changes: 27 additions & 8 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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
Expand All @@ -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__))
Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 052142d

Please sign in to comment.