Skip to content

Commit

Permalink
🐛 Bug: 1. Fix the bug causing Ratelimit error 202 on DuckDuckGo
Browse files Browse the repository at this point in the history
💻 Code: 1. Upgrade ModelMerge version to 0.3.11

2. Refactor the code, streamline the bot.py code.
  • Loading branch information
yym68686 committed May 14, 2024
1 parent a8f8aaf commit 6e0b4a8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 41 deletions.
47 changes: 8 additions & 39 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
get_current_lang,
update_info_message,
update_ENGINE,
update_language
reset_ENGINE,
update_language,
get_robot
)

from utils.i18n import strings
Expand Down Expand Up @@ -124,12 +126,7 @@ async def command_bot(update, context, language=None, prompt=translator_prompt,
elif reply_to_message_text and not update_message.reply_to_message.from_user.is_bot:
message = reply_to_message_text + "\n" + message

if "claude-3" in config.GPT_ENGINE and config.CLAUDE_API:
robot = config.claude3Bot
if ("mixtral" in config.GPT_ENGINE or "llama" in config.GPT_ENGINE) and config.GROQ_API_KEY:
robot = config.groqBot
if "gemini" in config.GPT_ENGINE and config.GOOGLE_AI_API_KEY:
robot = config.gemini_Bot
robot, role = get_robot()
if "gpt" in config.GPT_ENGINE or (config.CLAUDE_API and "claude-3" in config.GPT_ENGINE):
message = [{"type": "text", "text": message}]
if image_url and (config.GPT_ENGINE == "gpt-4-turbo-2024-04-09" or "gpt-4o" in config.GPT_ENGINE):
Expand All @@ -156,16 +153,7 @@ async def command_bot(update, context, language=None, prompt=translator_prompt,
@decorators.GroupAuthorization
@decorators.Authorization
async def reset_chat(update, context):
if config.API and config.ChatGPTbot:
config.ChatGPTbot.reset(convo_id=str(update.message.chat_id), system_prompt=config.systemprompt)
if config.CLAUDE_API and config.claudeBot:
config.claudeBot.reset(convo_id=str(update.message.chat_id), system_prompt=config.claude_systemprompt)
if config.CLAUDE_API and config.claude3Bot:
config.claude3Bot.reset(convo_id=str(update.message.chat_id), system_prompt=config.claude_systemprompt)
if config.GROQ_API_KEY and config.groqBot:
config.groqBot.reset(convo_id=str(update.message.chat_id), system_prompt=config.systemprompt)
if config.GOOGLE_AI_API_KEY and config.gemini_Bot:
config.gemini_Bot.reset(convo_id=str(update.message.chat_id), system_prompt=config.systemprompt)
reset_ENGINE(update.message.chat_id)

await context.bot.send_message(
chat_id=update.message.chat_id,
Expand Down Expand Up @@ -386,18 +374,7 @@ async def handle_pdf(update, context):
new_file = await context.bot.get_file(file_id)
file_url = new_file.file_path
extracted_text_with_prompt = Document_extract(file_url)
if config.CLAUDE_API and "claude-2.1" in config.GPT_ENGINE:
robot = config.claudeBot
role = "Human"
elif config.CLAUDE_API and "claude-3" in config.GPT_ENGINE:
robot = config.claude3Bot
role = "user"
elif config.GOOGLE_AI_API_KEY and "gemini" in config.GPT_ENGINE:
robot = config.gemini_Bot
role = "user"
else:
robot = config.ChatGPTbot
role = "user"
robot, role = get_robot()
robot.add_to_conversation(extracted_text_with_prompt, role, str(update.effective_chat.id))
if config.CLAUDE_API and "claude-3" in config.GPT_ENGINE:
robot.add_to_conversation(claude3_doc_assistant_prompt, "assistant", str(update.effective_chat.id))
Expand All @@ -422,18 +399,10 @@ async def handle_photo(update, context):
photo_file = await context.bot.getFile(file_id)
image_url = photo_file.file_path

if config.CLAUDE_API and "claude-2.1" in config.GPT_ENGINE:
robot = config.claudeBot
role = "Human"
elif config.CLAUDE_API and "claude-3" in config.GPT_ENGINE:
robot = config.claude3Bot
role = "user"
else:
robot = config.ChatGPTbot
role = "user"
robot, role = get_robot()

base64_image = get_encode_image(image_url)
if image_url and (config.GPT_ENGINE == "gpt-4-turbo-2024-04-09" or "gpt-4o" in config.GPT_ENGINE or (config.CLAUDE_API is None and "claude-3" in config.GPT_ENGINE)):
if image_url and ("gpt-4" in config.GPT_ENGINE or (config.CLAUDE_API is None and "claude-3" in config.GPT_ENGINE)):
message = [
{
"type": "image_url",
Expand Down
34 changes: 33 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,41 @@ def update_ENGINE(data = None):
groqBot = groq(api_key=f"{GROQ_API_KEY}", engine=GPT_ENGINE, system_prompt=systemprompt, temperature=temperature)
if GOOGLE_AI_API_KEY and "gemini" in GPT_ENGINE:
gemini_Bot = gemini(api_key=f"{GOOGLE_AI_API_KEY}", engine=GPT_ENGINE, system_prompt=systemprompt, temperature=temperature)

update_ENGINE()

def reset_ENGINE(chat_id):
global ChatGPTbot, translate_bot, claudeBot, claude3Bot, groqBot, gemini_Bot
if API and ChatGPTbot:
ChatGPTbot.reset(convo_id=str(chat_id), system_prompt=systemprompt)
if CLAUDE_API and claudeBot:
claudeBot.reset(convo_id=str(chat_id), system_prompt=claude_systemprompt)
if CLAUDE_API and claude3Bot:
claude3Bot.reset(convo_id=str(chat_id), system_prompt=claude_systemprompt)
if GROQ_API_KEY and groqBot:
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)

def get_robot():
global ChatGPTbot, claudeBot, claude3Bot, groqBot, gemini_Bot
if CLAUDE_API and "claude-2.1" in GPT_ENGINE:
robot = claudeBot
role = "Human"
elif CLAUDE_API and "claude-3" in GPT_ENGINE:
robot = claude3Bot
role = "user"
elif ("mixtral" in GPT_ENGINE or "llama" in GPT_ENGINE) and GROQ_API_KEY:
robot = groqBot
elif GOOGLE_AI_API_KEY and "gemini" in GPT_ENGINE:
robot = gemini_Bot
role = "user"
else:
robot = ChatGPTbot
role = "user"

return robot, role


whitelist = os.environ.get('whitelist', None)
if whitelist:
whitelist = [int(id) for id in whitelist.split(",")]
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ pytz
python-dotenv
md2tgmd==0.1.9
fake_useragent
ModelMerge==0.3.8
ModelMerge==0.3.11
oauth2client==3.0.0
python-telegram-bot[webhooks,rate-limiter]==21.0.1

0 comments on commit 6e0b4a8

Please sign in to comment.