Spaces:
Running
Running
Download app/routers/embeddings.py from free-apis-collection/markitdown: direct link, hf CLI and curl.
- Browser
- Download file 1.09 kB
-
https://huggingface.co/spaces/free-apis-collection/markitdown/resolve/main/app/routers/embeddings.py
- Command line
-
hf download hf://spaces/free-apis-collection/markitdown/app/routers/embeddings.py
-
curl -L -o embeddings.py https://huggingface.co/spaces/free-apis-collection/markitdown/resolve/main/app/routers/embeddings.py
1.09 kB
| """Embeddings router — integrated native embedding service.""" | |
| from __future__ import annotations | |
| from fastapi import APIRouter, Depends | |
| from app.core.deps import ServiceAuth | |
| from app.models.schemas import EmbedRequest | |
| from app.services import embeddings | |
| router = APIRouter() | |
| async def embed(payload: EmbedRequest) -> dict: | |
| if not embeddings.embedding_enabled(): | |
| return {"embeddings": [], "dimension": payload.dimension, "count": 0, "error": "currently embedding service is unavailable"} | |
| result = await embeddings.generate_embeddings(payload.data, payload.dimension) | |
| if isinstance(payload.data, str): | |
| return {"embeddings": result, "dimension": len(result), "count": 1} | |
| return {"embeddings": result, "dimension": len(result[0]) if result else 0, "count": len(result)} | |
| async def health() -> dict: | |
| return { | |
| "status": "healthy" if embeddings.embedding_enabled() else "embedding_service_disabled", | |
| "loaded_dimensions": embeddings.supported_dimensions(), | |
| } | |