Skip to content

Commit

Permalink
🐛 Bug: Fixed the bug that prevented use after opening the plugin.
Browse files Browse the repository at this point in the history
💻 Code: Upgrade ModelMerge version to 0.6.8
  • Loading branch information
yym68686 committed Jun 11, 2024
1 parent 14fed81 commit 6db0a40
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
__pycache__/
.DS_Store
.vscode
.env
.env
pyrightconfig.json
29 changes: 17 additions & 12 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ async def GetMesage(update_message, context):
file_url = None
reply_to_message_text = None

chatid = update_message.chat_id
chatid = str(update_message.chat_id)
message_thread_id = update_message.message_thread_id
if message_thread_id:
convo_id = str(chatid) + "_" + str(message_thread_id)
else:
convo_id = chatid
convo_id = str(chatid)

messageid = update_message.message_id

Expand Down Expand Up @@ -237,7 +237,6 @@ async def reset_chat(update, context):
global target_convo_id
_, _, _, chatid, _, _, _, message_thread_id, convo_id, file_url = await GetMesageInfo(update, context)
target_convo_id = convo_id
print("target_chatid", convo_id)
stop_event.set()
message = None
if (len(context.args) > 0):
Expand Down Expand Up @@ -276,7 +275,7 @@ async def getChatGPT(update, context, title, robot, message, chatid, messageid,
image_has_send = 0

try:
for data in robot.ask_stream(text, convo_id=str(convo_id), pass_history=pass_history, model=model_name):
for data in robot.ask_stream(text, convo_id=convo_id, pass_history=pass_history, model=model_name):
if stop_event.is_set() and convo_id == target_convo_id:
return
if "🌐" not in data:
Expand All @@ -291,7 +290,7 @@ async def getChatGPT(update, context, title, robot, message, chatid, messageid,
tmpresult = claude_replace(tmpresult)
if "🌐" in data:
tmpresult = data
history = robot.conversation[str(convo_id)]
history = robot.conversation[convo_id]
if history[-1].get('name') == "generate_image" and not image_has_send:
await context.bot.send_photo(chat_id=chatid, photo=history[-1]['content'], reply_to_message_id=answer_messageid)
image_has_send = 1
Expand All @@ -305,7 +304,7 @@ async def getChatGPT(update, context, title, robot, message, chatid, messageid,
print(tmpresult)
print('\033[0m')
if config.API:
robot.reset(convo_id=str(convo_id), system_prompt=config.systemprompt)
robot.reset(convo_id=convo_id, system_prompt=config.systemprompt)
tmpresult = f"{tmpresult}\n\n`{e}`"
print(tmpresult)
if lastresult != tmpresult and answer_messageid:
Expand All @@ -323,7 +322,7 @@ async def getChatGPT(update, context, title, robot, message, chatid, messageid,
"{}"
"</infomation>"
).format("\n\n".join(tmpresult.split("\n\n")[1:]))
result = config.SummaryBot.ask(prompt, convo_id=str(convo_id), pass_history=False).split('\n')
result = config.SummaryBot.ask(prompt, convo_id=convo_id, pass_history=False).split('\n')
keyboard = []
result = [i for i in result if i.strip() and len(i) > 5]
print(result)
Expand All @@ -340,11 +339,11 @@ async def button_press(update, context):
"""Function to handle the button press"""
message, rawtext, image_url, chatid, messageid, reply_to_message_text, update_message, message_thread_id, convo_id, file_url = await GetMesageInfo(update, context)
callback_query = update.callback_query
print("callback_query chatid", chatid)
info_message = update_info_message(convo_id)
await callback_query.answer()
data = callback_query.data
banner = strings['message_banner'][get_current_lang()]

if data.endswith("_MODELS"):
data = data[:-7]
update_ENGINE(data, convo_id)
Expand All @@ -365,6 +364,7 @@ async def button_press(update, context):
reply_markup=InlineKeyboardMarkup(update_models_buttons(convo_id)),
parse_mode='MarkdownV2'
)

elif data.endswith("_LANGUAGES"):
data = data[:-10]
update_language_status(data, chat_id=convo_id)
Expand All @@ -385,6 +385,7 @@ async def button_press(update, context):
reply_markup=InlineKeyboardMarkup(update_menu_buttons(LANGUAGES, "_LANGUAGES", convo_id)),
parse_mode='MarkdownV2'
)

if data.endswith("_PREFERENCES"):
data = data[:-12]
try:
Expand All @@ -409,11 +410,15 @@ async def button_press(update, context):
reply_markup=InlineKeyboardMarkup(update_menu_buttons(PREFERENCES, "_PREFERENCES", convo_id)),
parse_mode='MarkdownV2'
)

if data.endswith("_PLUGINS"):
data = data[:-8]
try:
current_data = Users.get_config(convo_id, data)
Users.set_config(convo_id, data, not current_data)
plugins_config = Users.extract_plugins_config(convo_id)
robot, role = get_robot(convo_id)
robot.plugins[convo_id] = plugins_config
except Exception as e:
logger.info(e)
try:
Expand Down Expand Up @@ -453,13 +458,13 @@ async def info(update, context):
@decorators.GroupAuthorization
@decorators.Authorization
async def handle_file(update, context):
robot, role = get_robot()
_, _, image_url, chatid, _, messageid, update_message, message_thread_id, convo_id, file_url = await GetMesageInfo(update, context)
robot, role = get_robot(convo_id)
engine = get_ENGINE(chatid)

message = Document_extract(file_url, None, engine)

robot.add_to_conversation(message, role, str(convo_id))
robot.add_to_conversation(message, role, convo_id)
message = (
f"上传成功!\n\n"
)
Expand Down Expand Up @@ -490,11 +495,11 @@ async def inlinequery(update: Update, context) -> None:
# 调用 getChatGPT 函数获取结果
if (query.endswith(';') or query.endswith(';')) and query.strip():
prompt = "Answer the following questions as concisely as possible:\n\n"
result = config.ChatGPTbot.ask(prompt + query, convo_id=str(chatid), pass_history=False)
result = config.ChatGPTbot.ask(prompt + query, convo_id=chatid, pass_history=False)

results = [
InlineQueryResultArticle(
id=str(chatid),
id=chatid,
title=f"{engine}",
thumbnail_url="https://pb.yym68686.top/TTGk",
description=f"{result}",
Expand Down
6 changes: 6 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ def set_config(self, user_id = None, parameter_name = None, value = None):
self.user_init(user_id)
self.users[self.user_id][parameter_name] = value

def extract_plugins_config(self, user_id = None):
self.user_init(user_id)
user_data = self.users[self.user_id]
plugins_config = {key: value for key, value in user_data.items() if key in self.plugins}
return plugins_config

CHAT_MODE = os.environ.get('CHAT_MODE', "global")
Users = UserConfig(mode=CHAT_MODE, engine=GPT_ENGINE, preferences=PREFERENCES, plugins=PLUGINS, language=LANGUAGE, languages=LANGUAGES, systemprompt=systemprompt, claude_systemprompt=claude_systemprompt)

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--index-url https://pypi.python.org/simple/
python-dotenv
md2tgmd==0.2.2
ModelMerge==0.6.6
ModelMerge==0.6.7
python-telegram-bot[webhooks,rate-limiter]==21.0.1

0 comments on commit 6db0a40

Please sign in to comment.