|
5 | 5 | from fastapi import APIRouter, Depends, status
|
6 | 6 | from fastapi.responses import JSONResponse
|
7 | 7 | from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
|
8 |
| -from pydantic import BaseModel, Field |
9 | 8 | from app.dependencies import get_pipeline
|
10 | 9 | from app.pipelines.base import Pipeline
|
11 | 10 | from app.routes.utils import HTTPError, http_error
|
| 11 | +from app.routes.utils import EmbeddingRequest, EmbeddingResponse |
12 | 12 |
|
13 | 13 | router = APIRouter()
|
14 | 14 | logger = logging.getLogger(__name__)
|
15 | 15 |
|
16 |
| - |
17 |
| -class EmbeddingRequest(BaseModel): |
18 |
| - input: Union[str, List[str]] = Field(..., description="Text to embed") |
19 |
| - model: str = Field("", description="Model to use") |
20 |
| - instruction: Optional[str] = Field( |
21 |
| - None, description="Instruction for instructor models") |
22 |
| - normalize: bool = Field(True, description="Whether to normalize embeddings") |
23 |
| - |
24 |
| - |
25 |
| -class EmbeddingResponse(BaseModel): |
26 |
| - object: str |
27 |
| - data: List[Dict[str, Union[List[float], int]]] |
28 |
| - model: str |
29 |
| - usage: Dict[str, int] |
30 |
| - |
31 |
| - |
32 | 16 | RESPONSES = {
|
33 | 17 | status.HTTP_200_OK: {"model": EmbeddingResponse},
|
34 | 18 | status.HTTP_400_BAD_REQUEST: {"model": HTTPError},
|
|
0 commit comments