feat: add CLIP embedding service sidecar for GPU machine
FastAPI service that loads ViT-L-14 model and exposes /embed, /similarity, and /batch-similarity endpoints. Runs on RTX 3090 with NVIDIA GPU reservation. Includes 9 cosine similarity tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
"""Test configuration: mock heavy dependencies that aren't needed for unit tests."""
|
||||
|
||||
import sys
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
# Mock modules that are not installed in the test environment.
|
||||
# The tests only exercise pure numpy math, not model inference.
|
||||
for mod_name in [
|
||||
"torch",
|
||||
"open_clip",
|
||||
"fastapi",
|
||||
"fastapi.responses",
|
||||
"pydantic",
|
||||
"PIL",
|
||||
"PIL.Image",
|
||||
"uvicorn",
|
||||
]:
|
||||
if mod_name not in sys.modules:
|
||||
sys.modules[mod_name] = MagicMock()
|
||||
|
||||
# Provide a real BaseModel stand-in so Pydantic models can be defined
|
||||
# (they are referenced at import time in main.py).
|
||||
import types
|
||||
|
||||
pydantic_mock = sys.modules["pydantic"]
|
||||
|
||||
|
||||
class _FakeBaseModel:
|
||||
def __init_subclass__(cls, **kwargs):
|
||||
pass
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
for k, v in kwargs.items():
|
||||
setattr(self, k, v)
|
||||
|
||||
|
||||
pydantic_mock.BaseModel = _FakeBaseModel
|
||||
|
||||
# Provide a fake FastAPI and HTTPException so the module loads
|
||||
fastapi_mock = sys.modules["fastapi"]
|
||||
|
||||
|
||||
class _FakeFastAPI:
|
||||
def __init__(self, **kwargs):
|
||||
pass
|
||||
|
||||
def get(self, *a, **kw):
|
||||
def decorator(fn):
|
||||
return fn
|
||||
return decorator
|
||||
|
||||
def post(self, *a, **kw):
|
||||
def decorator(fn):
|
||||
return fn
|
||||
return decorator
|
||||
|
||||
|
||||
class _FakeHTTPException(Exception):
|
||||
def __init__(self, status_code=500, detail=""):
|
||||
self.status_code = status_code
|
||||
self.detail = detail
|
||||
|
||||
|
||||
fastapi_mock.FastAPI = _FakeFastAPI
|
||||
fastapi_mock.HTTPException = _FakeHTTPException
|
||||
Reference in New Issue
Block a user