light refactoring (#35)

* update poetry lock

* simple refactoring

* move gpt-3.5-turbo-stream-aivvm to deprecated provider
This commit is contained in:
Dmitry Afanasyev
2023-10-12 12:12:05 +03:00
committed by GitHub
parent 7ef8d6e19d
commit 94b50f1b7c
14 changed files with 104 additions and 146 deletions

View File

@@ -46,7 +46,6 @@ class ChatGptModelsEnum(StrEnum):
gpt_3_stream_binjie = "gpt-3-stream-binjie"
gpt_3_5_turbo_stream_CodeLinkAva = "gpt-3.5-turbo-stream-CodeLinkAva"
gpt_4_stream_ChatBase = "gpt-4-stream-ChatBase"
gpt_3_5_turbo_stream_aivvm = "gpt-3.5-turbo-stream-aivvm"
gpt_3_5_turbo_16k_stream_Ylokh = "gpt-3.5-turbo-16k-stream-Ylokh"
gpt_3_5_turbo_stream_Vitalentum = "gpt-3.5-turbo-stream-Vitalentum"
gpt_3_5_turbo_stream_GptGo = "gpt-3.5-turbo-stream-GptGo"
@@ -56,9 +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"
gpt_3_5_turbo_stream_ChatgptDemo = "gpt-3.5-turbo-stream-ChatgptDemo"
gpt_3_5_turbo_stream_H2o = "gpt-3.5-turbo-stream-H2o"
gpt_3_5_turbo_stream_gptforlove = "gpt-3.5-turbo-stream-gptforlove"
gpt_3_5_turbo_ChatgptDuo = "gpt-3.5-turbo-ChatgptDuo"
@classmethod
def values(cls) -> set[str]:
@@ -66,4 +63,7 @@ class ChatGptModelsEnum(StrEnum):
@staticmethod
def _deprecated() -> set[str]:
return {"gpt-3.5-turbo-stream-H2o", "gpt-3.5-turbo-stream-gptforlove", "gpt-3.5-turbo-ChatgptDuo"}
return {
"gpt-3.5-turbo-stream-gptforlove",
"gpt-3.5-turbo-stream-aivvm",
}

View File

@@ -27,11 +27,12 @@ class Application:
openapi_url="/" + "/".join([settings.api_prefix.strip("/"), "openapi.json"]),
default_response_class=UJSONResponse,
)
self.app.state.settings = settings
self.app.state.queue = BotQueue(bot_app=bot_app)
self.app.state.bot_app = bot_app
self.db = Database(settings)
self.bot_app = bot_app
self.db = Database(settings)
self._bot_queue = BotQueue(bot_app=self.bot_app)
self.app.state.settings = settings
self.app.state.queue = self._bot_queue
self.app.state.bot_app = self.bot_app
self.app.on_event("startup")(startup(self.app, settings))
self.app.on_event("shutdown")(shutdown(self.app))
@@ -57,6 +58,10 @@ class Application:
def fastapi_app(self) -> FastAPI:
return self.app
@cached_property
def bot_queue(self) -> BotQueue:
return self._bot_queue
def configure_hooks(self) -> None:
if self.bot_app.start_with_webhook:
self.app.add_event_handler("startup", self._bot_start_up)

View File

@@ -14,8 +14,8 @@ BASE_DIR = Path(__file__).parent.parent
SHARED_DIR = BASE_DIR.resolve().joinpath("shared")
SHARED_DIR.mkdir(exist_ok=True)
SHARED_DIR.joinpath("logs").mkdir(exist_ok=True)
DIR_LOGS = SHARED_DIR.joinpath("logs")
DIR_LOGS.mkdir(exist_ok=True)
env_path = f"{BASE_DIR}/settings/.env"

View File

@@ -41,7 +41,7 @@ async def test_bot_webhook_endpoint(
bot_update = BotUpdateFactory(message=BotMessageFactory.create_instance(text="/help"))
response = await rest_client.post(url="/api/CDDEEFFaabbccdd", json=bot_update)
assert response.status_code == 202
update = await main_application.fastapi_app.state._state["queue"].queue.get()
update = await main_application.bot_queue.queue.get()
update = update.to_dict()
assert update["update_id"] == bot_update["update_id"]
assert_that(update["message"]).is_equal_to(

View File

@@ -204,9 +204,7 @@ async def main_application(
@pytest_asyncio.fixture()
async def rest_client(
main_application: AppApplication,
) -> AsyncGenerator[AsyncClient, None]:
async def rest_client(main_application: AppApplication) -> AsyncGenerator[AsyncClient, None]:
"""
Default http client. Use to test unauthorized requests, public endpoints
or special authorization methods.