mirror of
https://github.com/Balshgit/gpt_chat_bot.git
synced 2025-09-11 22:30:41 +03:00
parent
7c51a775c6
commit
a18c94882a
@ -70,11 +70,11 @@ def check_user_is_banned(func: Any) -> Any:
|
|||||||
@wraps(func)
|
@wraps(func)
|
||||||
async def wrapper(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
async def wrapper(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||||
if not update.effective_message:
|
if not update.effective_message:
|
||||||
logger.error('no effective message', update=update, context=context)
|
logger.error("no effective message", update=update, context=context)
|
||||||
return
|
return
|
||||||
|
|
||||||
if not update.effective_user:
|
if not update.effective_user:
|
||||||
logger.error('no effective user', update=update, context=context)
|
logger.error("no effective user", update=update, context=context)
|
||||||
await update.effective_message.reply_text(
|
await update.effective_message.reply_text(
|
||||||
"Бот не смог определить пользователя. :(\nОб ошибке уже сообщено."
|
"Бот не смог определить пользователя. :(\nОб ошибке уже сообщено."
|
||||||
)
|
)
|
||||||
|
@ -5,6 +5,7 @@ Revises:
|
|||||||
Create Date: 2023-10-05 18:28:30.915361
|
Create Date: 2023-10-05 18:28:30.915361
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
from alembic import op
|
from alembic import op
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ Revises: 0001_create_chatgpt_table
|
|||||||
Create Date: 2023-11-28 00:58:01.984654
|
Create Date: 2023-11-28 00:58:01.984654
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
@ -5,6 +5,7 @@ Revises: 0002_create_auth_tables
|
|||||||
Create Date: 2023-12-28 13:24:42.667724
|
Create Date: 2023-12-28 13:24:42.667724
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
from alembic import op
|
from alembic import op
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ Revises: 0003_create_user_question_count_table
|
|||||||
Create Date: 2024-01-08 20:56:34.815976
|
Create Date: 2024-01-08 20:56:34.815976
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
from alembic import op
|
from alembic import op
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ class AppSettings(SentrySettings, LoggingSettings, BaseSettings):
|
|||||||
# ==== gpt settings ====
|
# ==== gpt settings ====
|
||||||
GPT_BASE_HOST: str = "http://chathpt_chat_service:8858"
|
GPT_BASE_HOST: str = "http://chathpt_chat_service:8858"
|
||||||
|
|
||||||
@model_validator(mode="before") # type: ignore[arg-type]
|
@model_validator(mode="before")
|
||||||
def validate_boolean_fields(self) -> Any:
|
def validate_boolean_fields(self) -> Any:
|
||||||
values_dict: dict[str, Any] = self # type: ignore[assignment]
|
values_dict: dict[str, Any] = self # type: ignore[assignment]
|
||||||
for value in (
|
for value in (
|
||||||
|
@ -381,11 +381,14 @@ async def test_ask_question_action_bot_user_not_exists(
|
|||||||
message = BotMessageFactory.create_instance(text="Привет!")
|
message = BotMessageFactory.create_instance(text="Привет!")
|
||||||
user = message["from"]
|
user = message["from"]
|
||||||
|
|
||||||
with mock.patch.object(
|
with (
|
||||||
telegram._bot.Bot, "send_message", return_value=lambda *args, **kwargs: (args, kwargs)
|
mock.patch.object(
|
||||||
) as mocked_send_message, mocked_ask_question_api(
|
telegram._bot.Bot, "send_message", return_value=lambda *args, **kwargs: (args, kwargs)
|
||||||
host=test_settings.GPT_BASE_HOST,
|
) as mocked_send_message,
|
||||||
return_value=Response(status_code=httpx.codes.OK, text="Привет! Как я могу помочь вам сегодня?"),
|
mocked_ask_question_api(
|
||||||
|
host=test_settings.GPT_BASE_HOST,
|
||||||
|
return_value=Response(status_code=httpx.codes.OK, text="Привет! Как я могу помочь вам сегодня?"),
|
||||||
|
),
|
||||||
):
|
):
|
||||||
bot_update = BotUpdateFactory(message=message)
|
bot_update = BotUpdateFactory(message=message)
|
||||||
bot_update["message"].pop("entities")
|
bot_update["message"].pop("entities")
|
||||||
@ -436,11 +439,14 @@ async def test_ask_question_action_bot_user_already_exists(
|
|||||||
users = dbsession.query(User).all()
|
users = dbsession.query(User).all()
|
||||||
assert len(users) == 1
|
assert len(users) == 1
|
||||||
|
|
||||||
with mock.patch.object(
|
with (
|
||||||
telegram._bot.Bot, "send_message", return_value=lambda *args, **kwargs: (args, kwargs)
|
mock.patch.object(
|
||||||
) as mocked_send_message, mocked_ask_question_api(
|
telegram._bot.Bot, "send_message", return_value=lambda *args, **kwargs: (args, kwargs)
|
||||||
host=test_settings.GPT_BASE_HOST,
|
) as mocked_send_message,
|
||||||
return_value=Response(status_code=httpx.codes.OK, text="Привет! Как я могу помочь вам сегодня?"),
|
mocked_ask_question_api(
|
||||||
|
host=test_settings.GPT_BASE_HOST,
|
||||||
|
return_value=Response(status_code=httpx.codes.OK, text="Привет! Как я могу помочь вам сегодня?"),
|
||||||
|
),
|
||||||
):
|
):
|
||||||
bot_update = BotUpdateFactory(message=message)
|
bot_update = BotUpdateFactory(message=message)
|
||||||
bot_update["message"].pop("entities")
|
bot_update["message"].pop("entities")
|
||||||
@ -496,12 +502,15 @@ async def test_ask_question_action_user_is_banned(
|
|||||||
ban_reason="test reason",
|
ban_reason="test reason",
|
||||||
)
|
)
|
||||||
|
|
||||||
with mock.patch.object(
|
with (
|
||||||
telegram._bot.Bot, "send_message", return_value=lambda *args, **kwargs: (args, kwargs)
|
mock.patch.object(
|
||||||
) as mocked_send_message, mocked_ask_question_api(
|
telegram._bot.Bot, "send_message", return_value=lambda *args, **kwargs: (args, kwargs)
|
||||||
host=test_settings.GPT_BASE_HOST,
|
) as mocked_send_message,
|
||||||
return_value=Response(status_code=httpx.codes.OK, text="Привет! Как я могу помочь вам сегодня?"),
|
mocked_ask_question_api(
|
||||||
assert_all_called=False,
|
host=test_settings.GPT_BASE_HOST,
|
||||||
|
return_value=Response(status_code=httpx.codes.OK, text="Привет! Как я могу помочь вам сегодня?"),
|
||||||
|
assert_all_called=False,
|
||||||
|
),
|
||||||
):
|
):
|
||||||
bot_update = BotUpdateFactory(message=message)
|
bot_update = BotUpdateFactory(message=message)
|
||||||
bot_update["message"].pop("entities")
|
bot_update["message"].pop("entities")
|
||||||
@ -531,10 +540,13 @@ async def test_ask_question_action_not_success(
|
|||||||
test_settings: AppSettings,
|
test_settings: AppSettings,
|
||||||
) -> None:
|
) -> None:
|
||||||
ChatGptModelFactory.create_batch(size=3)
|
ChatGptModelFactory.create_batch(size=3)
|
||||||
with mock.patch.object(
|
with (
|
||||||
telegram._bot.Bot, "send_message", return_value=lambda *args, **kwargs: (args, kwargs)
|
mock.patch.object(
|
||||||
) as mocked_send_message, mocked_ask_question_api(
|
telegram._bot.Bot, "send_message", return_value=lambda *args, **kwargs: (args, kwargs)
|
||||||
host=test_settings.GPT_BASE_HOST, return_value=Response(status_code=httpx.codes.INTERNAL_SERVER_ERROR)
|
) as mocked_send_message,
|
||||||
|
mocked_ask_question_api(
|
||||||
|
host=test_settings.GPT_BASE_HOST, return_value=Response(status_code=httpx.codes.INTERNAL_SERVER_ERROR)
|
||||||
|
),
|
||||||
):
|
):
|
||||||
bot_update = BotUpdateFactory(message=BotMessageFactory.create_instance(text="Привет!"))
|
bot_update = BotUpdateFactory(message=BotMessageFactory.create_instance(text="Привет!"))
|
||||||
bot_update["message"].pop("entities")
|
bot_update["message"].pop("entities")
|
||||||
@ -557,11 +569,14 @@ async def test_ask_question_action_critical_error(
|
|||||||
test_settings: AppSettings,
|
test_settings: AppSettings,
|
||||||
) -> None:
|
) -> None:
|
||||||
ChatGptModelFactory.create_batch(size=3)
|
ChatGptModelFactory.create_batch(size=3)
|
||||||
with mock.patch.object(
|
with (
|
||||||
telegram._bot.Bot, "send_message", return_value=lambda *args, **kwargs: (args, kwargs)
|
mock.patch.object(
|
||||||
) as mocked_send_message, mocked_ask_question_api(
|
telegram._bot.Bot, "send_message", return_value=lambda *args, **kwargs: (args, kwargs)
|
||||||
host=test_settings.GPT_BASE_HOST,
|
) as mocked_send_message,
|
||||||
side_effect=Exception(),
|
mocked_ask_question_api(
|
||||||
|
host=test_settings.GPT_BASE_HOST,
|
||||||
|
side_effect=Exception(),
|
||||||
|
),
|
||||||
):
|
):
|
||||||
bot_update = BotUpdateFactory(message=BotMessageFactory.create_instance(text="Привет!"))
|
bot_update = BotUpdateFactory(message=BotMessageFactory.create_instance(text="Привет!"))
|
||||||
bot_update["message"].pop("entities")
|
bot_update["message"].pop("entities")
|
||||||
|
943
poetry.lock
generated
943
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@ -5,7 +5,7 @@ description = "Bot to integrated with Chat gpt"
|
|||||||
authors = ["Dmitry Afanasyev <Balshbox@gmail.com>"]
|
authors = ["Dmitry Afanasyev <Balshbox@gmail.com>"]
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["poetry-core>=1.7.1"]
|
requires = ["poetry-core>=1.7.2"]
|
||||||
build-backend = "poetry.core.masonry.api"
|
build-backend = "poetry.core.masonry.api"
|
||||||
|
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
@ -18,13 +18,13 @@ python-dateutil = "*"
|
|||||||
httpx = "^0.25"
|
httpx = "^0.25"
|
||||||
aiohttp = "^3.9"
|
aiohttp = "^3.9"
|
||||||
loguru = "^0.7"
|
loguru = "^0.7"
|
||||||
pydantic = "^2.5"
|
pydantic = "^2.6"
|
||||||
pydantic-settings = "^2.1"
|
pydantic-settings = "^2.1"
|
||||||
gunicorn = "^21.2"
|
gunicorn = "^21.2"
|
||||||
uvicorn = "^0.25"
|
uvicorn = "^0.27.0.post1"
|
||||||
wheel = "^0.42"
|
wheel = "^0.42"
|
||||||
orjson = "^3.9"
|
orjson = "^3.9"
|
||||||
sentry-sdk = "^1.39"
|
sentry-sdk = "^1.40"
|
||||||
SpeechRecognition = "^3.8"
|
SpeechRecognition = "^3.8"
|
||||||
greenlet = "^3.0"
|
greenlet = "^3.0"
|
||||||
graypy = "^2.1.0"
|
graypy = "^2.1.0"
|
||||||
@ -34,7 +34,7 @@ sqlalchemy = {version = "^2.0", extras=["mypy"]}
|
|||||||
alembic = "^1.13"
|
alembic = "^1.13"
|
||||||
sqladmin = {version = "^0.16", extras=["full"]}
|
sqladmin = {version = "^0.16", extras=["full"]}
|
||||||
pydub = {git = "https://github.com/jiaaro/pydub.git"}
|
pydub = {git = "https://github.com/jiaaro/pydub.git"}
|
||||||
types-pytz = "^2023.3.1.1"
|
types-pytz = "^2023.4.0.20240130"
|
||||||
|
|
||||||
|
|
||||||
[tool.poetry.dev-dependencies]
|
[tool.poetry.dev-dependencies]
|
||||||
@ -51,7 +51,7 @@ bandit = "^1.7"
|
|||||||
|
|
||||||
pyupgrade = "^3.10"
|
pyupgrade = "^3.10"
|
||||||
isort = "^5.12"
|
isort = "^5.12"
|
||||||
black = "^23.12"
|
black = "^24.1"
|
||||||
|
|
||||||
mypy = "^1.8"
|
mypy = "^1.8"
|
||||||
types-PyMySQL = "^1.0"
|
types-PyMySQL = "^1.0"
|
||||||
@ -69,12 +69,12 @@ pytest-timeouts = "^1.2"
|
|||||||
pytest-sugar = "^0.9"
|
pytest-sugar = "^0.9"
|
||||||
pytest-clarity = "^1.0"
|
pytest-clarity = "^1.0"
|
||||||
pytest-env = "^1.1"
|
pytest-env = "^1.1"
|
||||||
nest-asyncio = "^1.5"
|
nest-asyncio = "^1.6"
|
||||||
pytest-html = "^4.1"
|
pytest-html = "^4.1"
|
||||||
pytest-randomly = "^3.15"
|
pytest-randomly = "^3.15"
|
||||||
pytest-split = "^0.8"
|
pytest-split = "^0.8"
|
||||||
pytest-freezegun = "^0.4"
|
pytest-freezegun = "^0.4"
|
||||||
pytest-socket = "^0.6"
|
pytest-socket = "^0.7"
|
||||||
assertpy = "^1.1"
|
assertpy = "^1.1"
|
||||||
respx = "^0.20"
|
respx = "^0.20"
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ flake8-logging-format = "^0.9"
|
|||||||
flake8-comprehensions = "^3.14"
|
flake8-comprehensions = "^3.14"
|
||||||
flake8-eradicate = "^1.5"
|
flake8-eradicate = "^1.5"
|
||||||
flake8-pytest-style = "^1.7"
|
flake8-pytest-style = "^1.7"
|
||||||
flake8-bugbear = "^23.12"
|
flake8-bugbear = "^24.1"
|
||||||
flake8-warnings = "^0.4"
|
flake8-warnings = "^0.4"
|
||||||
flake8-debugger = "^4.1"
|
flake8-debugger = "^4.1"
|
||||||
flake8-fixme = "^1.1"
|
flake8-fixme = "^1.1"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user