add GitHub callback (#38)

* add gpt-3.5-turbo-stream-GptChatly provider

* add GitHub callback
This commit is contained in:
Dmitry Afanasyev
2023-10-13 15:00:34 +03:00
committed by GitHub
parent b322e3c1da
commit 4c3c6039e3
11 changed files with 144 additions and 21 deletions

View File

@@ -16,8 +16,8 @@ UTC_TZ = timezone.utc
class BotStagesEnum(StrEnum):
about_me = "about_me"
website = "website"
help = "help"
about_bot = "about_bot"
github = "github"
class BotEntryPoints(StrEnum):
@@ -55,6 +55,7 @@ class ChatGptModelsEnum(StrEnum):
gpt_4_stream_Chatgpt4Online = "gpt-4-stream-Chatgpt4Online"
gpt_3_5_turbo_stream_gptalk = "gpt-3.5-turbo-stream-gptalk"
llama2 = "llama2"
gpt_3_5_turbo_stream_GptChatly = "gpt-3.5-turbo-stream-GptChatly"
gpt_3_5_turbo_stream_ChatgptDemo = "gpt-3.5-turbo-stream-ChatgptDemo"
gpt_3_5_turbo_stream_gptforlove = "gpt-3.5-turbo-stream-gptforlove"

View File

@@ -18,6 +18,7 @@ async def main_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> st
return BotEntryPoints.end
reply_markup = InlineKeyboardMarkup(main_keyboard)
await update.message.reply_text("Выберете команду:", reply_markup=reply_markup)
await update.message.reply_text("Список этих команд всегда можно получить набрав /help")
return BotEntryPoints.start_routes
@@ -35,9 +36,9 @@ async def about_bot(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
chatgpt_service = ChatGptService.build()
model = await chatgpt_service.get_current_chatgpt_model()
await update.effective_message.reply_text(
f"Бот использует бесплатную модель {model} для ответов на вопросы. "
f"\nПринимает запросы на разных языках.\n\nБот так же умеет переводить русские голосовые сообщения в текст. "
f"Просто пришлите голосовуху и получите поток сознания в виде текста, но без знаков препинания",
f"Бот использует бесплатную модель *{model}* для ответов на вопросы.\nПринимает запросы на разных языках."
f"\n\nБот так же умеет переводить русские голосовые сообщения в текст. Просто пришлите или перешлите "
f"голосовуху боту и получите поток сознания в виде текста, но без знаков препинания.",
parse_mode="Markdown",
)
@@ -63,6 +64,17 @@ async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
)
async def github(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Send a message when the command /help is issued."""
if not update.effective_message:
return
await update.effective_message.reply_text(
"Проект на [GitHub](https://github.com/Balshgit/gpt_chat_bot)",
parse_mode="Markdown",
)
async def ask_question(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
if not update.message:
return

View File

@@ -14,6 +14,7 @@ from core.bot.commands import (
about_bot,
about_me,
ask_question,
github,
help_command,
main_command,
voice_recognize,
@@ -41,7 +42,7 @@ bot_event_handlers.add_handler(
BotEntryPoints.start_routes: [
CallbackQueryHandler(about_me, pattern="^" + BotStagesEnum.about_me + "$"),
CallbackQueryHandler(website, pattern="^" + BotStagesEnum.website + "$"),
CallbackQueryHandler(help_command, pattern="^" + BotStagesEnum.help + "$"),
CallbackQueryHandler(github, pattern="^" + BotStagesEnum.github + "$"),
CallbackQueryHandler(about_bot, pattern="^" + BotStagesEnum.about_bot + "$"),
],
},
@@ -50,5 +51,5 @@ bot_event_handlers.add_handler(
)
bot_event_handlers.add_handler(CallbackQueryHandler(about_me, pattern="^" + BotStagesEnum.about_me + "$"))
bot_event_handlers.add_handler(CallbackQueryHandler(website, pattern="^" + BotStagesEnum.website + "$"))
bot_event_handlers.add_handler(CallbackQueryHandler(help_command, pattern="^" + BotStagesEnum.help + "$"))
bot_event_handlers.add_handler(CallbackQueryHandler(github, pattern="^" + BotStagesEnum.github + "$"))
bot_event_handlers.add_handler(CallbackQueryHandler(about_bot, pattern="^" + BotStagesEnum.about_bot + "$"))

View File

@@ -8,7 +8,7 @@ main_keyboard = (
InlineKeyboardButton("Веб версия", callback_data=str(BotStagesEnum.website)),
),
(
InlineKeyboardButton("Помощь", callback_data=str(BotStagesEnum.help)),
InlineKeyboardButton("GitHub", callback_data=str(BotStagesEnum.github)),
InlineKeyboardButton("О боте", callback_data=str(BotStagesEnum.about_bot)),
),
)

View File

@@ -105,7 +105,7 @@ async def test_help_command(
InlineKeyboardButton(callback_data="website", text="Веб версия"),
),
(
InlineKeyboardButton(callback_data="help", text="Помощь"),
InlineKeyboardButton(callback_data="github", text="GitHub"),
InlineKeyboardButton(callback_data="about_bot", text="О боте"),
),
)
@@ -128,7 +128,7 @@ async def test_start_entry(
update=Update.de_json(data=bot_update, bot=main_application.bot_app.bot)
)
assert_that(mocked_send_message.call_args.kwargs).is_equal_to(
assert_that(mocked_send_message.call_args_list[0].kwargs).is_equal_to(
{
"text": "Выберете команду:",
"chat_id": bot_update["message"]["chat"]["id"],
@@ -139,7 +139,7 @@ async def test_start_entry(
InlineKeyboardButton(callback_data="website", text="Веб версия"),
),
(
InlineKeyboardButton(callback_data="help", text="Помощь"),
InlineKeyboardButton(callback_data="github", text="GitHub"),
InlineKeyboardButton(callback_data="about_bot", text="О боте"),
),
)
@@ -147,6 +147,14 @@ async def test_start_entry(
},
include=["text", "chat_id", "reply_markup"],
)
assert_that(mocked_send_message.call_args_list[1].kwargs).is_equal_to(
{
"text": "Список этих команд всегда можно получить набрав /help",
"chat_id": bot_update["message"]["chat"]["id"],
"reply_markup": None,
},
include=["text", "chat_id", "reply_markup"],
)
async def test_about_me_callback_action(
@@ -167,6 +175,24 @@ async def test_about_me_callback_action(
assert mocked_reply_text.call_args.kwargs == {"parse_mode": "MarkdownV2"}
async def test_github_callback_action(
main_application: Application,
test_settings: AppSettings,
) -> None:
with mock.patch.object(telegram._message.Message, "reply_text") as mocked_reply_text:
bot_update = BotCallBackQueryFactory(
message=BotMessageFactory.create_instance(text="Список основных команд:"),
callback_query=CallBackFactory(data=BotStagesEnum.github),
)
await main_application.bot_app.application.process_update(
update=Update.de_json(data=bot_update, bot=main_application.bot_app.bot)
)
assert mocked_reply_text.call_args.args == ("Проект на [GitHub](https://github.com/Balshgit/gpt_chat_bot)",)
assert mocked_reply_text.call_args.kwargs == {"parse_mode": "Markdown"}
async def test_about_bot_callback_action(
dbsession: Session,
main_application: Application,
@@ -185,9 +211,10 @@ async def test_about_bot_callback_action(
)
assert mocked_reply_text.call_args.args == (
f"Бот использует бесплатную модель {model_with_highest_priority.model} для ответов на вопросы. "
f"\nПринимает запросы на разных языках.\n\nБот так же умеет переводить русские голосовые сообщения "
f"в текст. Просто пришлите голосовуху и получите поток сознания в виде текста, но без знаков препинания",
f"Бот использует бесплатную модель *{model_with_highest_priority.model}* для ответов на вопросы.\n"
f"Принимает запросы на разных языках.\n\nБот так же умеет переводить русские голосовые сообщения в текст. "
f"Просто пришлите или перешлите голосовуху боту и получите поток сознания в виде текста, "
f"но без знаков препинания.",
)
assert mocked_reply_text.call_args.kwargs == {"parse_mode": "Markdown"}