add auth context (#62)

* add user table and superuser creation

* add gpt-4-stream-aivvm provider

* rename user migration to auth migration
This commit is contained in:
Dmitry Afanasyev
2023-11-28 23:06:26 +03:00
committed by GitHub
parent c80b001740
commit 2359481fb7
17 changed files with 668 additions and 280 deletions

View File

@@ -1,7 +1,10 @@
from fastapi import Depends
from fastapi_users_db_sqlalchemy import SQLAlchemyUserDatabase
from sqlalchemy.ext.asyncio import AsyncSession
from starlette.requests import Request
from telegram import Update
from core.auth.models.users import User
from core.bot.app import BotApplication, BotQueue
from core.bot.repository import ChatGPTRepository
from core.bot.services import ChatGptService
@@ -21,6 +24,10 @@ def get_bot_queue(request: Request) -> BotQueue:
return request.app.state.queue
def get_db_session(request: Request) -> AsyncSession:
return request.app.state.db_session_factory()
async def get_update_from_request(request: Request, bot_app: BotApplication = Depends(get_bot_app)) -> Update | None:
data = await request.json()
return Update.de_json(data, bot_app.bot)
@@ -44,3 +51,9 @@ def get_chatgpt_service(
chatgpt_repository: ChatGPTRepository = Depends(get_chatgpt_repository),
) -> ChatGptService:
return ChatGptService(repository=chatgpt_repository)
async def get_user_db( # type: ignore[misc]
session: AsyncSession = Depends(get_db_session),
) -> SQLAlchemyUserDatabase: # type: ignore[type-arg]
yield SQLAlchemyUserDatabase(session, User)