mirror of
https://github.com/cdryzun/tg_bot_collections.git
synced 2025-04-29 00:27:09 +08:00
fix: wrong answer
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
This commit is contained in:
parent
23ad429cd2
commit
1909e95cd6
@ -26,7 +26,7 @@ DEFAULT_LOAD_PRIORITY = 10
|
|||||||
|
|
||||||
BOT_MESSAGE_LENGTH = 4000
|
BOT_MESSAGE_LENGTH = 4000
|
||||||
|
|
||||||
REPLY_MESSAGE_CACHE = ExpiringDict(max_len=1000, max_age_seconds=300)
|
REPLY_MESSAGE_CACHE = ExpiringDict(max_len=1000, max_age_seconds=600)
|
||||||
|
|
||||||
|
|
||||||
def bot_reply_first(message: Message, who: str, bot: TeleBot) -> Message:
|
def bot_reply_first(message: Message, who: str, bot: TeleBot) -> Message:
|
||||||
|
@ -24,8 +24,8 @@ client = OpenAI(api_key=CHATGPT_API_KEY, base_url=CHATGPT_BASE_URL, timeout=20)
|
|||||||
|
|
||||||
|
|
||||||
# Global history cache
|
# Global history cache
|
||||||
chatgpt_player_dict = ExpiringDict(max_len=1000, max_age_seconds=300)
|
chatgpt_player_dict = ExpiringDict(max_len=1000, max_age_seconds=600)
|
||||||
chatgpt_pro_player_dict = ExpiringDict(max_len=1000, max_age_seconds=300)
|
chatgpt_pro_player_dict = ExpiringDict(max_len=1000, max_age_seconds=600)
|
||||||
|
|
||||||
|
|
||||||
def chatgpt_handler(message: Message, bot: TeleBot) -> None:
|
def chatgpt_handler(message: Message, bot: TeleBot) -> None:
|
||||||
@ -81,7 +81,7 @@ def chatgpt_handler(message: Message, bot: TeleBot) -> None:
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
bot_reply_markdown(reply_id, who, "answer wrong", bot)
|
bot.reply_to(message, "answer wrong maybe up to the max token")
|
||||||
# pop my user
|
# pop my user
|
||||||
player_message.pop()
|
player_message.pop()
|
||||||
return
|
return
|
||||||
@ -138,7 +138,7 @@ def chatgpt_pro_handler(message: Message, bot: TeleBot) -> None:
|
|||||||
s += chunk.choices[0].delta.content
|
s += chunk.choices[0].delta.content
|
||||||
if time.time() - start > 1.2:
|
if time.time() - start > 1.2:
|
||||||
start = time.time()
|
start = time.time()
|
||||||
bot_reply_markdown(reply_id, who, s, bot, split_text=True)
|
bot_reply_markdown(reply_id, who, s, bot, split_text=False)
|
||||||
# maybe not complete
|
# maybe not complete
|
||||||
try:
|
try:
|
||||||
bot_reply_markdown(reply_id, who, s, bot, split_text=True)
|
bot_reply_markdown(reply_id, who, s, bot, split_text=True)
|
||||||
@ -154,7 +154,7 @@ def chatgpt_pro_handler(message: Message, bot: TeleBot) -> None:
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
bot_reply_markdown(reply_id, who, "answer wrong", bot)
|
# bot.reply_to(message, "answer wrong maybe up to the max token")
|
||||||
player_message.clear()
|
player_message.clear()
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -199,11 +199,15 @@ def chatgpt_photo_handler(message: Message, bot: TeleBot) -> None:
|
|||||||
if time.time() - start > 2.0:
|
if time.time() - start > 2.0:
|
||||||
start = time.time()
|
start = time.time()
|
||||||
bot_reply_markdown(reply_id, who, s, bot, split_text=False)
|
bot_reply_markdown(reply_id, who, s, bot, split_text=False)
|
||||||
|
# maybe not complete
|
||||||
|
try:
|
||||||
bot_reply_markdown(reply_id, who, s, bot)
|
bot_reply_markdown(reply_id, who, s, bot)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
bot_reply_markdown(reply_id, who, "answer wrong", bot)
|
bot.reply_to(message, "answer wrong maybe up to the max token")
|
||||||
|
|
||||||
|
|
||||||
if CHATGPT_API_KEY:
|
if CHATGPT_API_KEY:
|
||||||
|
@ -25,7 +25,7 @@ TELEGRA_PH_TOKEN = environ.get("TELEGRA_PH_TOKEN")
|
|||||||
ph = TelegraphAPI(TELEGRA_PH_TOKEN)
|
ph = TelegraphAPI(TELEGRA_PH_TOKEN)
|
||||||
|
|
||||||
# Global history cache
|
# Global history cache
|
||||||
cohere_player_dict = ExpiringDict(max_len=1000, max_age_seconds=300)
|
cohere_player_dict = ExpiringDict(max_len=1000, max_age_seconds=600)
|
||||||
|
|
||||||
|
|
||||||
def clean_text(text):
|
def clean_text(text):
|
||||||
@ -159,7 +159,7 @@ def cohere_handler(message: Message, bot: TeleBot) -> None:
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
bot_reply_markdown(reply_id, who, "Answer wrong", bot)
|
bot.reply_to(message, "answer wrong maybe up to the max token")
|
||||||
player_message.clear()
|
player_message.clear()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -22,9 +22,9 @@ if DIFY_API_KEY:
|
|||||||
client = ChatClient(api_key=DIFY_API_KEY)
|
client = ChatClient(api_key=DIFY_API_KEY)
|
||||||
|
|
||||||
# Global history cache
|
# Global history cache
|
||||||
dify_player_dict = ExpiringDict(max_len=1000, max_age_seconds=300)
|
dify_player_dict = ExpiringDict(max_len=1000, max_age_seconds=600)
|
||||||
dify_player_c = ExpiringDict(
|
dify_player_c = ExpiringDict(
|
||||||
max_len=1000, max_age_seconds=300
|
max_len=1000, max_age_seconds=600
|
||||||
) # History cache is supported by dify cloud conversation_id.
|
) # History cache is supported by dify cloud conversation_id.
|
||||||
|
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ def dify_handler(message: Message, bot: TeleBot) -> None:
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
bot_reply_markdown(reply_id, who, "answer wrong", bot)
|
bot.reply_to(message, "answer wrong maybe up to the max token")
|
||||||
# pop my user
|
# pop my user
|
||||||
player_message.pop()
|
player_message.pop()
|
||||||
return
|
return
|
||||||
|
@ -34,9 +34,9 @@ safety_settings = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
# Global history cache
|
# Global history cache
|
||||||
gemini_player_dict = ExpiringDict(max_len=1000, max_age_seconds=300)
|
gemini_player_dict = ExpiringDict(max_len=1000, max_age_seconds=600)
|
||||||
gemini_pro_player_dict = ExpiringDict(max_len=1000, max_age_seconds=300)
|
gemini_pro_player_dict = ExpiringDict(max_len=1000, max_age_seconds=600)
|
||||||
gemini_file_player_dict = ExpiringDict(max_len=100, max_age_seconds=300)
|
gemini_file_player_dict = ExpiringDict(max_len=100, max_age_seconds=600)
|
||||||
|
|
||||||
|
|
||||||
def make_new_gemini_convo(is_pro=False) -> ChatSession:
|
def make_new_gemini_convo(is_pro=False) -> ChatSession:
|
||||||
@ -116,7 +116,7 @@ def gemini_handler(message: Message, bot: TeleBot) -> None:
|
|||||||
gemini_reply_text = re.sub(r"\\n", "\n", gemini_reply_text)
|
gemini_reply_text = re.sub(r"\\n", "\n", gemini_reply_text)
|
||||||
else:
|
else:
|
||||||
print("No meaningful text was extracted from the exception.")
|
print("No meaningful text was extracted from the exception.")
|
||||||
bot_reply_markdown(reply_id, who, "answer wrong", bot)
|
bot.reply_to(message, "answer wrong maybe up to the max token")
|
||||||
return
|
return
|
||||||
|
|
||||||
# By default markdown
|
# By default markdown
|
||||||
@ -167,7 +167,7 @@ def gemini_pro_handler(message: Message, bot: TeleBot) -> None:
|
|||||||
return
|
return
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
bot_reply_markdown(reply_id, who, "answer wrong", bot)
|
bot.reply_to(message, "answer wrong maybe up to the max token")
|
||||||
try:
|
try:
|
||||||
player.history.clear()
|
player.history.clear()
|
||||||
except:
|
except:
|
||||||
@ -204,10 +204,14 @@ def gemini_photo_handler(message: Message, bot: TeleBot) -> None:
|
|||||||
start = time.time()
|
start = time.time()
|
||||||
bot_reply_markdown(reply_id, who, s, bot, split_text=False)
|
bot_reply_markdown(reply_id, who, s, bot, split_text=False)
|
||||||
|
|
||||||
|
# maybe not complete
|
||||||
|
try:
|
||||||
bot_reply_markdown(reply_id, who, s, bot)
|
bot_reply_markdown(reply_id, who, s, bot)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
bot_reply_markdown(reply_id, who, "answer wrong", bot)
|
bot.reply_to(message, "answer wrong maybe up to the max token")
|
||||||
|
|
||||||
|
|
||||||
def gemini_audio_handler(message: Message, bot: TeleBot) -> None:
|
def gemini_audio_handler(message: Message, bot: TeleBot) -> None:
|
||||||
@ -245,7 +249,7 @@ def gemini_audio_handler(message: Message, bot: TeleBot) -> None:
|
|||||||
return
|
return
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
bot_reply_markdown(reply_id, who, "answer wrong", bot)
|
bot.reply_to(message, "answer wrong maybe up to the max token")
|
||||||
try:
|
try:
|
||||||
player.history.clear()
|
player.history.clear()
|
||||||
except:
|
except:
|
||||||
|
@ -22,8 +22,8 @@ if LLAMA_API_KEY:
|
|||||||
client = Groq(api_key=LLAMA_API_KEY)
|
client = Groq(api_key=LLAMA_API_KEY)
|
||||||
|
|
||||||
# Global history cache
|
# Global history cache
|
||||||
llama_player_dict = ExpiringDict(max_len=1000, max_age_seconds=300)
|
llama_player_dict = ExpiringDict(max_len=1000, max_age_seconds=600)
|
||||||
llama_pro_player_dict = ExpiringDict(max_len=1000, max_age_seconds=300)
|
llama_pro_player_dict = ExpiringDict(max_len=1000, max_age_seconds=600)
|
||||||
|
|
||||||
|
|
||||||
def llama_handler(message: Message, bot: TeleBot) -> None:
|
def llama_handler(message: Message, bot: TeleBot) -> None:
|
||||||
@ -79,7 +79,7 @@ def llama_handler(message: Message, bot: TeleBot) -> None:
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
bot_reply_markdown(reply_id, who, "answer wrong", bot)
|
bot.reply_to(message, "answer wrong maybe up to the max token")
|
||||||
# pop my user
|
# pop my user
|
||||||
player_message.pop()
|
player_message.pop()
|
||||||
return
|
return
|
||||||
@ -153,7 +153,7 @@ def llama_pro_handler(message: Message, bot: TeleBot) -> None:
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
bot_reply_markdown(reply_id, who, "answer wrong", bot)
|
bot.reply_to(message, "answer wrong maybe up to the max token")
|
||||||
player_message.clear()
|
player_message.clear()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -22,8 +22,8 @@ if QWEN_API_KEY:
|
|||||||
client = Together(api_key=QWEN_API_KEY)
|
client = Together(api_key=QWEN_API_KEY)
|
||||||
|
|
||||||
# Global history cache
|
# Global history cache
|
||||||
qwen_player_dict = ExpiringDict(max_len=1000, max_age_seconds=300)
|
qwen_player_dict = ExpiringDict(max_len=1000, max_age_seconds=600)
|
||||||
qwen_pro_player_dict = ExpiringDict(max_len=1000, max_age_seconds=300)
|
qwen_pro_player_dict = ExpiringDict(max_len=1000, max_age_seconds=600)
|
||||||
|
|
||||||
|
|
||||||
def qwen_handler(message: Message, bot: TeleBot) -> None:
|
def qwen_handler(message: Message, bot: TeleBot) -> None:
|
||||||
@ -79,7 +79,7 @@ def qwen_handler(message: Message, bot: TeleBot) -> None:
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
bot_reply_markdown(reply_id, who, "answer wrong", bot)
|
bot.reply_to(message, "answer wrong maybe up to the max token")
|
||||||
# pop my user
|
# pop my user
|
||||||
player_message.pop()
|
player_message.pop()
|
||||||
return
|
return
|
||||||
@ -152,7 +152,7 @@ def qwen_pro_handler(message: Message, bot: TeleBot) -> None:
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
bot_reply_markdown(reply_id, who, "answer wrong", bot)
|
bot.reply_to(message, "answer wrong maybe up to the max token")
|
||||||
player_message.clear()
|
player_message.clear()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -46,8 +46,8 @@ Hint = (
|
|||||||
)
|
)
|
||||||
#### LLMs ####
|
#### LLMs ####
|
||||||
GEMINI_USE = True
|
GEMINI_USE = True
|
||||||
CHATGPT_USE = False
|
CHATGPT_USE = True
|
||||||
CLADUE_USE = False
|
CLADUE_USE = True
|
||||||
QWEN_USE = True
|
QWEN_USE = True
|
||||||
COHERE_USE = False # Slow, but web search
|
COHERE_USE = False # Slow, but web search
|
||||||
LLAMA_USE = False # prompted for Language
|
LLAMA_USE = False # prompted for Language
|
||||||
@ -467,7 +467,6 @@ def chatgpt_answer(latest_message: Message, bot: TeleBot, m):
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"\n------\n{who} function inner Error:\n{e}\n------\n")
|
print(f"\n------\n{who} function inner Error:\n{e}\n------\n")
|
||||||
bot_reply_markdown(reply_id, who, "answer wrong", bot)
|
|
||||||
return f"\n---\n{who}:\nAnswer wrong", reply_id.message_id
|
return f"\n---\n{who}:\nAnswer wrong", reply_id.message_id
|
||||||
|
|
||||||
return llm_answer(who, s), reply_id.message_id
|
return llm_answer(who, s), reply_id.message_id
|
||||||
@ -506,7 +505,6 @@ def claude_answer(latest_message: Message, bot: TeleBot, m):
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"\n------\n{who} function inner Error:\n{e}\n------\n")
|
print(f"\n------\n{who} function inner Error:\n{e}\n------\n")
|
||||||
bot_reply_markdown(reply_id, who, "answer wrong", bot)
|
|
||||||
return f"\n---\n{who}:\nAnswer wrong", reply_id.message_id
|
return f"\n---\n{who}:\nAnswer wrong", reply_id.message_id
|
||||||
|
|
||||||
answer = f"\n---\n{who}:\n{s}"
|
answer = f"\n---\n{who}:\n{s}"
|
||||||
@ -581,7 +579,6 @@ def cohere_answer(latest_message: Message, bot: TeleBot, m):
|
|||||||
pass
|
pass
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"\n------\n{who} function inner Error:\n{e}\n------\n")
|
print(f"\n------\n{who} function inner Error:\n{e}\n------\n")
|
||||||
bot_reply_markdown(reply_id, who, "Answer wrong", bot)
|
|
||||||
return f"\n---\n{who}:\nAnswer wrong", reply_id.message_id
|
return f"\n---\n{who}:\nAnswer wrong", reply_id.message_id
|
||||||
|
|
||||||
return llm_answer(who, content), reply_id.message_id
|
return llm_answer(who, content), reply_id.message_id
|
||||||
@ -619,7 +616,6 @@ def qwen_answer(latest_message: Message, bot: TeleBot, m):
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"\n------\n{who} function inner Error:\n{e}\n------\n")
|
print(f"\n------\n{who} function inner Error:\n{e}\n------\n")
|
||||||
bot_reply_markdown(reply_id, who, "answer wrong", bot)
|
|
||||||
return f"\n---\n{who}:\nAnswer wrong", reply_id.message_id
|
return f"\n---\n{who}:\nAnswer wrong", reply_id.message_id
|
||||||
|
|
||||||
return llm_answer(who, s), reply_id.message_id
|
return llm_answer(who, s), reply_id.message_id
|
||||||
@ -662,7 +658,6 @@ def llama_answer(latest_message: Message, bot: TeleBot, m):
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"\n------\n{who} function inner Error:\n{e}\n------\n")
|
print(f"\n------\n{who} function inner Error:\n{e}\n------\n")
|
||||||
bot_reply_markdown(reply_id, who, "answer wrong", bot)
|
|
||||||
return f"\n---\n{who}:\nAnswer wrong", reply_id.message_id
|
return f"\n---\n{who}:\nAnswer wrong", reply_id.message_id
|
||||||
|
|
||||||
return llm_answer(who, s), reply_id.message_id
|
return llm_answer(who, s), reply_id.message_id
|
||||||
|
@ -22,8 +22,8 @@ client = OpenAI(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Global history cache
|
# Global history cache
|
||||||
yi_player_dict = ExpiringDict(max_len=1000, max_age_seconds=300)
|
yi_player_dict = ExpiringDict(max_len=1000, max_age_seconds=600)
|
||||||
yi_pro_player_dict = ExpiringDict(max_len=1000, max_age_seconds=300)
|
yi_pro_player_dict = ExpiringDict(max_len=1000, max_age_seconds=600)
|
||||||
|
|
||||||
|
|
||||||
def yi_handler(message: Message, bot: TeleBot) -> None:
|
def yi_handler(message: Message, bot: TeleBot) -> None:
|
||||||
@ -82,7 +82,7 @@ def yi_handler(message: Message, bot: TeleBot) -> None:
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
bot_reply_markdown(reply_id, who, "answer wrong", bot)
|
bot.reply_to(message, "answer wrong maybe up to the max token")
|
||||||
# pop my user
|
# pop my user
|
||||||
player_message.pop()
|
player_message.pop()
|
||||||
return
|
return
|
||||||
@ -156,7 +156,7 @@ def yi_pro_handler(message: Message, bot: TeleBot) -> None:
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
bot_reply_markdown(reply_id, who, "answer wrong", bot)
|
bot.reply_to(message, "answer wrong maybe up to the max token")
|
||||||
player_message.clear()
|
player_message.clear()
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -206,7 +206,7 @@ def yi_photo_handler(message: Message, bot: TeleBot) -> None:
|
|||||||
bot_reply_markdown(reply_id, who, text, bot)
|
bot_reply_markdown(reply_id, who, text, bot)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
bot_reply_markdown(reply_id, who, "answer wrong", bot)
|
bot.reply_to(message, "answer wrong maybe up to the max token")
|
||||||
|
|
||||||
|
|
||||||
if YI_API_KEY and YI_BASE_URL:
|
if YI_API_KEY and YI_BASE_URL:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user