Spaces:
Build error
Build error
Ajit Panday commited on
Commit ·
9cc5dcd
1
Parent(s): 0e10f98
Add Pydantic models and update endpoints to use them
Browse files- app/schemas.py +41 -0
- main.py +7 -6
app/schemas.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pydantic import BaseModel
|
| 2 |
+
from typing import Optional
|
| 3 |
+
from datetime import datetime
|
| 4 |
+
|
| 5 |
+
class CustomerBase(BaseModel):
|
| 6 |
+
name: str
|
| 7 |
+
company_name: str
|
| 8 |
+
email: str
|
| 9 |
+
|
| 10 |
+
class CustomerCreate(CustomerBase):
|
| 11 |
+
pass
|
| 12 |
+
|
| 13 |
+
class Customer(CustomerBase):
|
| 14 |
+
id: int
|
| 15 |
+
api_key: str
|
| 16 |
+
is_active: bool
|
| 17 |
+
created_at: datetime
|
| 18 |
+
updated_at: datetime
|
| 19 |
+
|
| 20 |
+
class Config:
|
| 21 |
+
from_attributes = True
|
| 22 |
+
|
| 23 |
+
class CallRecordBase(BaseModel):
|
| 24 |
+
caller_number: str
|
| 25 |
+
called_number: str
|
| 26 |
+
file_path: str
|
| 27 |
+
transcription: str
|
| 28 |
+
summary: str
|
| 29 |
+
sentiment: str
|
| 30 |
+
|
| 31 |
+
class CallRecordCreate(CallRecordBase):
|
| 32 |
+
pass
|
| 33 |
+
|
| 34 |
+
class CallRecord(CallRecordBase):
|
| 35 |
+
id: str
|
| 36 |
+
customer_id: int
|
| 37 |
+
created_at: datetime
|
| 38 |
+
updated_at: datetime
|
| 39 |
+
|
| 40 |
+
class Config:
|
| 41 |
+
from_attributes = True
|
main.py
CHANGED
|
@@ -14,7 +14,8 @@ from app.settings import (
|
|
| 14 |
ADMIN_USERNAME, ADMIN_PASSWORD, WHISPER_MODEL,
|
| 15 |
SUMMARIZER_MODEL, SENTIMENT_MODEL
|
| 16 |
)
|
| 17 |
-
from app.models import Customer, CallRecord
|
|
|
|
| 18 |
from app.auth import verify_api_key, get_current_admin, create_access_token, router as auth_router
|
| 19 |
from app.database import get_db
|
| 20 |
from sqlalchemy.orm import sessionmaker
|
|
@@ -49,9 +50,9 @@ app.include_router(auth_router, prefix="/api/v1", tags=["auth"])
|
|
| 49 |
|
| 50 |
async def get_customer_by_api_key(api_key: str = Header(...), db: Session = Depends(get_db)):
|
| 51 |
"""Get customer by API key"""
|
| 52 |
-
customer = db.query(
|
| 53 |
-
|
| 54 |
-
|
| 55 |
).first()
|
| 56 |
if not customer:
|
| 57 |
raise HTTPException(
|
|
@@ -65,7 +66,7 @@ async def process_call(
|
|
| 65 |
file: UploadFile = File(...),
|
| 66 |
caller_number: str = Form(...),
|
| 67 |
called_number: str = Form(...),
|
| 68 |
-
customer:
|
| 69 |
db: Session = Depends(get_db)
|
| 70 |
):
|
| 71 |
"""
|
|
@@ -104,7 +105,7 @@ async def process_call(
|
|
| 104 |
|
| 105 |
try:
|
| 106 |
# Create call record
|
| 107 |
-
call_record =
|
| 108 |
id=process_id,
|
| 109 |
customer_id=customer.id,
|
| 110 |
caller_number=caller_number,
|
|
|
|
| 14 |
ADMIN_USERNAME, ADMIN_PASSWORD, WHISPER_MODEL,
|
| 15 |
SUMMARIZER_MODEL, SENTIMENT_MODEL
|
| 16 |
)
|
| 17 |
+
from app.models import Customer as CustomerModel, CallRecord as CallRecordModel
|
| 18 |
+
from app.schemas import Customer, CustomerCreate, CallRecord
|
| 19 |
from app.auth import verify_api_key, get_current_admin, create_access_token, router as auth_router
|
| 20 |
from app.database import get_db
|
| 21 |
from sqlalchemy.orm import sessionmaker
|
|
|
|
| 50 |
|
| 51 |
async def get_customer_by_api_key(api_key: str = Header(...), db: Session = Depends(get_db)):
|
| 52 |
"""Get customer by API key"""
|
| 53 |
+
customer = db.query(CustomerModel).filter(
|
| 54 |
+
CustomerModel.api_key == api_key,
|
| 55 |
+
CustomerModel.is_active == True
|
| 56 |
).first()
|
| 57 |
if not customer:
|
| 58 |
raise HTTPException(
|
|
|
|
| 66 |
file: UploadFile = File(...),
|
| 67 |
caller_number: str = Form(...),
|
| 68 |
called_number: str = Form(...),
|
| 69 |
+
customer: CustomerModel = Depends(verify_api_key),
|
| 70 |
db: Session = Depends(get_db)
|
| 71 |
):
|
| 72 |
"""
|
|
|
|
| 105 |
|
| 106 |
try:
|
| 107 |
# Create call record
|
| 108 |
+
call_record = CallRecordModel(
|
| 109 |
id=process_id,
|
| 110 |
customer_id=customer.id,
|
| 111 |
caller_number=caller_number,
|