Spaces:
Runtime error
Runtime error
Commit
·
709b775
1
Parent(s):
02ca405
deploy
Browse files- __pycache__/main.cpython-313.pyc +0 -0
- main.py +4 -0
- routes/__pycache__/sms_router.cpython-313.pyc +0 -0
- routes/sms_router.py +24 -6
- schemas/__pycache__/schema.cpython-313.pyc +0 -0
- schemas/schema.py +2 -2
__pycache__/main.cpython-313.pyc
CHANGED
|
Binary files a/__pycache__/main.cpython-313.pyc and b/__pycache__/main.cpython-313.pyc differ
|
|
|
main.py
CHANGED
|
@@ -6,3 +6,7 @@ app = FastAPI()
|
|
| 6 |
|
| 7 |
# Include the router for SMS endpoints
|
| 8 |
app.include_router(sms_router)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# Include the router for SMS endpoints
|
| 8 |
app.include_router(sms_router)
|
| 9 |
+
@app.get("/")
|
| 10 |
+
def home():
|
| 11 |
+
|
| 12 |
+
return {"message": "Welcome to embedding sms API, use /docs to post SMS text and get demenstions"}
|
routes/__pycache__/sms_router.cpython-313.pyc
CHANGED
|
Binary files a/routes/__pycache__/sms_router.cpython-313.pyc and b/routes/__pycache__/sms_router.cpython-313.pyc differ
|
|
|
routes/sms_router.py
CHANGED
|
@@ -15,10 +15,28 @@ async def get_embeddings(sms_request: SMSRequest):
|
|
| 15 |
# Generate embeddings
|
| 16 |
embeddings = generate_embeddings(sms_request.messages)
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
| 23 |
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
# Generate embeddings
|
| 16 |
embeddings = generate_embeddings(sms_request.messages)
|
| 17 |
|
| 18 |
+
from fastapi import APIRouter, HTTPException
|
| 19 |
+
from schemas.schema import SMSRequest, EmbeddingResponse
|
| 20 |
+
from service.embedded_service import generate_embeddings
|
| 21 |
+
|
| 22 |
+
# Initialize Router
|
| 23 |
+
router = APIRouter()
|
| 24 |
|
| 25 |
+
@router.post("/get_embeddings/", response_model=EmbeddingResponse)
|
| 26 |
+
async def get_embeddings(sms_request: SMSRequest):
|
| 27 |
+
# Check if the input list is not empty
|
| 28 |
+
if not sms_request.messages:
|
| 29 |
+
raise HTTPException(status_code=400, detail="No messages provided.")
|
| 30 |
+
|
| 31 |
+
# Generate embeddings
|
| 32 |
+
embeddings = generate_embeddings(sms_request.messages)
|
| 33 |
+
|
| 34 |
+
# Check if embeddings are generated and are in the correct format
|
| 35 |
+
if not embeddings or not all(isinstance(emb, list) for emb in embeddings):
|
| 36 |
+
raise HTTPException(status_code=500, detail="Failed to generate embeddings.")
|
| 37 |
+
|
| 38 |
+
# Get the dimensions from the first embedding (assuming all are the same)
|
| 39 |
+
dimensions = len(embeddings[0]) if embeddings else 0
|
| 40 |
+
|
| 41 |
+
# Return the response as per the EmbeddingResponse model
|
| 42 |
+
return EmbeddingResponse(dimensions=dimensions, embeddings=embeddings)
|
schemas/__pycache__/schema.cpython-313.pyc
CHANGED
|
Binary files a/schemas/__pycache__/schema.cpython-313.pyc and b/schemas/__pycache__/schema.cpython-313.pyc differ
|
|
|
schemas/schema.py
CHANGED
|
@@ -13,8 +13,8 @@ class EmbeddingResponse(BaseModel):
|
|
| 13 |
"example": {
|
| 14 |
"dimensions": 768,
|
| 15 |
"embeddings": [
|
| 16 |
-
[0.1, 0.2, 0.3, 0.4, 0.5, 0.6
|
| 17 |
-
[0.7, 0.8, 0.9, 1.0, 1.1, 1.2
|
| 18 |
]
|
| 19 |
}
|
| 20 |
}
|
|
|
|
| 13 |
"example": {
|
| 14 |
"dimensions": 768,
|
| 15 |
"embeddings": [
|
| 16 |
+
[0.1, 0.2, 0.3, 0.4, 0.5, 0.6], # Example values for first message
|
| 17 |
+
[0.7, 0.8, 0.9, 1.0, 1.1, 1.2] # Example values for second message
|
| 18 |
]
|
| 19 |
}
|
| 20 |
}
|