Spaces:
Runtime error
Runtime error
Commit ·
ead0f7d
1
Parent(s): dbecd18
Fix fastapi-users register router and confirm flash-attn dependency
Browse files- api/models.py +16 -2
- main.py +3 -3
- requirements.txt +1 -0
api/models.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
-
# api/models.py
|
| 2 |
from fastapi_users.db import SQLAlchemyBaseUserTable, SQLAlchemyBaseOAuthAccountTable
|
| 3 |
from sqlalchemy import Column, Integer, String, Boolean
|
| 4 |
from sqlalchemy.orm import relationship
|
| 5 |
from sqlalchemy.ext.declarative import declarative_base
|
| 6 |
from pydantic import BaseModel, Field
|
| 7 |
from typing import List, Optional
|
|
|
|
| 8 |
|
| 9 |
Base = declarative_base()
|
| 10 |
|
|
@@ -13,6 +13,7 @@ class OAuthAccount(SQLAlchemyBaseOAuthAccountTable, Base):
|
|
| 13 |
__tablename__ = "oauth_accounts"
|
| 14 |
id = Column(Integer, primary_key=True)
|
| 15 |
user = relationship("User", back_populates="oauth_accounts")
|
|
|
|
| 16 |
# نموذج المستخدم
|
| 17 |
class User(SQLAlchemyBaseUserTable, Base):
|
| 18 |
__tablename__ = "users"
|
|
@@ -23,7 +24,20 @@ class User(SQLAlchemyBaseUserTable, Base):
|
|
| 23 |
is_superuser = Column(Boolean, default=False)
|
| 24 |
oauth_accounts = relationship("OAuthAccount", back_populates="user")
|
| 25 |
|
| 26 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
class QueryRequest(BaseModel):
|
| 28 |
message: str
|
| 29 |
system_prompt: Optional[str] = "You are an expert assistant providing detailed, comprehensive, and well-structured responses."
|
|
|
|
|
|
|
| 1 |
from fastapi_users.db import SQLAlchemyBaseUserTable, SQLAlchemyBaseOAuthAccountTable
|
| 2 |
from sqlalchemy import Column, Integer, String, Boolean
|
| 3 |
from sqlalchemy.orm import relationship
|
| 4 |
from sqlalchemy.ext.declarative import declarative_base
|
| 5 |
from pydantic import BaseModel, Field
|
| 6 |
from typing import List, Optional
|
| 7 |
+
from fastapi_users import schemas
|
| 8 |
|
| 9 |
Base = declarative_base()
|
| 10 |
|
|
|
|
| 13 |
__tablename__ = "oauth_accounts"
|
| 14 |
id = Column(Integer, primary_key=True)
|
| 15 |
user = relationship("User", back_populates="oauth_accounts")
|
| 16 |
+
|
| 17 |
# نموذج المستخدم
|
| 18 |
class User(SQLAlchemyBaseUserTable, Base):
|
| 19 |
__tablename__ = "users"
|
|
|
|
| 24 |
is_superuser = Column(Boolean, default=False)
|
| 25 |
oauth_accounts = relationship("OAuthAccount", back_populates="user")
|
| 26 |
|
| 27 |
+
# Pydantic schemas for fastapi-users
|
| 28 |
+
class UserRead(schemas.BaseUser[int]):
|
| 29 |
+
id: int
|
| 30 |
+
email: str
|
| 31 |
+
is_active: bool = True
|
| 32 |
+
is_superuser: bool = False
|
| 33 |
+
|
| 34 |
+
class UserCreate(schemas.BaseUserCreate):
|
| 35 |
+
email: str
|
| 36 |
+
password: str
|
| 37 |
+
is_active: Optional[bool] = True
|
| 38 |
+
is_superuser: Optional[bool] = False
|
| 39 |
+
|
| 40 |
+
# نموذج طلب الاستعلام
|
| 41 |
class QueryRequest(BaseModel):
|
| 42 |
message: str
|
| 43 |
system_prompt: Optional[str] = "You are an expert assistant providing detailed, comprehensive, and well-structured responses."
|
main.py
CHANGED
|
@@ -11,7 +11,7 @@ from fastapi.middleware.cors import CORSMiddleware
|
|
| 11 |
from api.endpoints import router as api_router
|
| 12 |
from api.auth import fastapi_users, auth_backend, current_active_user, google_oauth_client, github_oauth_client
|
| 13 |
from api.database import get_db, engine, Base
|
| 14 |
-
from api.models import User
|
| 15 |
from motor.motor_asyncio import AsyncIOMotorClient
|
| 16 |
from pydantic import BaseModel
|
| 17 |
from typing import List
|
|
@@ -85,12 +85,12 @@ app.include_router(
|
|
| 85 |
tags=["auth"],
|
| 86 |
)
|
| 87 |
app.include_router(
|
| 88 |
-
fastapi_users.get_register_router(),
|
| 89 |
prefix="/auth",
|
| 90 |
tags=["auth"],
|
| 91 |
)
|
| 92 |
app.include_router(
|
| 93 |
-
fastapi_users.get_users_router(),
|
| 94 |
prefix="/users",
|
| 95 |
tags=["users"],
|
| 96 |
)
|
|
|
|
| 11 |
from api.endpoints import router as api_router
|
| 12 |
from api.auth import fastapi_users, auth_backend, current_active_user, google_oauth_client, github_oauth_client
|
| 13 |
from api.database import get_db, engine, Base
|
| 14 |
+
from api.models import User, UserRead, UserCreate
|
| 15 |
from motor.motor_asyncio import AsyncIOMotorClient
|
| 16 |
from pydantic import BaseModel
|
| 17 |
from typing import List
|
|
|
|
| 85 |
tags=["auth"],
|
| 86 |
)
|
| 87 |
app.include_router(
|
| 88 |
+
fastapi_users.get_register_router(UserRead, UserCreate),
|
| 89 |
prefix="/auth",
|
| 90 |
tags=["auth"],
|
| 91 |
)
|
| 92 |
app.include_router(
|
| 93 |
+
fastapi_users.get_users_router(UserRead, UserCreate),
|
| 94 |
prefix="/users",
|
| 95 |
tags=["users"],
|
| 96 |
)
|
requirements.txt
CHANGED
|
@@ -34,3 +34,4 @@ aiofiles
|
|
| 34 |
motor
|
| 35 |
redis
|
| 36 |
markdown2
|
|
|
|
|
|
| 34 |
motor
|
| 35 |
redis
|
| 36 |
markdown2
|
| 37 |
+
flash-attn==2.6.3
|