fix: command

Signed-off-by: yihong0618 <zouzou0208@gmail.com>
This commit is contained in:
yihong0618 2024-06-20 15:18:29 +08:00
parent a0220fa8aa
commit 90fd74c403
3 changed files with 6 additions and 36 deletions

View File

@ -100,7 +100,8 @@ def wrap_handler(handler: T, bot: TeleBot) -> T:
def wrapper(message: Message, *args: Any, **kwargs: Any) -> None:
try:
m = ""
if message.text.find("answer_it") != -1:
if message.text and message.text.find("answer_it") != -1:
# for answer_it no args
return handler(message, *args, **kwargs)
elif message.text is not None:

View File

@ -220,6 +220,7 @@ if CHATGPT_API_KEY:
bot.register_message_handler(
chatgpt_photo_handler,
content_types=["photo"],
func=lambda m: m.caption and m.caption.startswith(("gpt:", "/gpt")),
func=lambda m: m.caption
and m.caption.startswith(("gpt:", "/gpt", "gpt_pro:", "/gpt_pro")),
pass_bot=True,
)

View File

@ -160,39 +160,7 @@ def answer_it_handler(message: Message, bot: TeleBot):
if chunk.choices[0].delta.content is None:
break
s += chunk.choices[0].delta.content
if time.time() - start > 1.2:
start = time.time()
bot_reply_markdown(reply_id, who, s, bot, split_text=False)
# maybe not complete
try:
bot_reply_markdown(reply_id, who, s, bot)
except:
pass
except Exception as e:
print(e)
bot_reply_markdown(reply_id, who, "answer wrong", bot)
##### Qwen #####
who = "Qwen Pro"
reply_id = bot_reply_first(latest_message, who, bot)
player_message = [{"role": "user", "content": m}]
try:
r = qwen_client.chat.completions.create(
messages=player_message,
max_tokens=4096,
model=QWEN_MODEL,
stream=True,
)
s = ""
start = time.time()
for chunk in r:
if chunk.choices[0].delta.content is None:
break
s += chunk.choices[0].delta.content
if time.time() - start > 1.2:
if time.time() - start > 1.5:
start = time.time()
bot_reply_markdown(reply_id, who, s, bot, split_text=False)
# maybe not complete
@ -206,7 +174,7 @@ def answer_it_handler(message: Message, bot: TeleBot):
bot_reply_markdown(reply_id, who, "answer wrong", bot)
if GOOGLE_GEMINI_KEY and CHATGPT_API_KEY and QWEN_API_KEY:
if GOOGLE_GEMINI_KEY and CHATGPT_API_KEY:
def register(bot: TeleBot) -> None:
bot.register_message_handler(md_handler, commands=["md"], pass_bot=True)