OrbStack 라이선스 만료로 Mac mini Docker 서비스를 GPU 서버로 통합. nginx → Caddy 전환, 12개 서브도메인 자동 HTTPS, fail2ban Caddy JSON 연동. 주요 변경: - home-caddy: Caddy 리버스 프록시 (Let's Encrypt 자동 HTTPS) - home-fail2ban: Caddy JSON 로그 기반 보안 모니터링 - home-ddns: Cloudflare DDNS (API 키 .env 분리) - gpu-hub-api/web: AI 백엔드 라우터 + 웹 UI (gpu-services에서 이전) - AI 런타임(Ollama) 내부망 전용, 외부는 gpu-hub 인증 게이트웨이 경유 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
68 lines
1.9 KiB
Python
68 lines
1.9 KiB
Python
from typing import List, Union
|
|
|
|
from fastapi import APIRouter, HTTPException, Request
|
|
from pydantic import BaseModel
|
|
|
|
from services import proxy_ollama
|
|
from services.registry import registry
|
|
|
|
router = APIRouter(prefix="/v1", tags=["embeddings"])
|
|
|
|
|
|
class EmbeddingRequest(BaseModel):
|
|
model: str
|
|
input: Union[str, List[str]]
|
|
|
|
|
|
@router.post("/embeddings")
|
|
async def create_embedding(body: EmbeddingRequest, request: Request):
|
|
role = getattr(request.state, "role", "anonymous")
|
|
if role == "anonymous":
|
|
raise HTTPException(
|
|
status_code=401,
|
|
detail={"error": {"message": "Authentication required", "type": "auth_error", "code": "unauthorized"}},
|
|
)
|
|
|
|
result = registry.resolve_model(body.model, role)
|
|
if not result:
|
|
raise HTTPException(
|
|
status_code=404,
|
|
detail={
|
|
"error": {
|
|
"message": f"Model '{body.model}' not found or not available",
|
|
"type": "invalid_request_error",
|
|
"code": "model_not_found",
|
|
}
|
|
},
|
|
)
|
|
|
|
backend, model_info = result
|
|
|
|
if "embed" not in model_info.capabilities:
|
|
raise HTTPException(
|
|
status_code=400,
|
|
detail={
|
|
"error": {
|
|
"message": f"Model '{body.model}' does not support embeddings",
|
|
"type": "invalid_request_error",
|
|
"code": "capability_mismatch",
|
|
}
|
|
},
|
|
)
|
|
|
|
if backend.type == "ollama":
|
|
return await proxy_ollama.generate_embedding(
|
|
backend.url, body.model, body.input
|
|
)
|
|
|
|
raise HTTPException(
|
|
status_code=501,
|
|
detail={
|
|
"error": {
|
|
"message": f"Embedding not supported for backend type '{backend.type}'",
|
|
"type": "api_error",
|
|
"code": "not_implemented",
|
|
}
|
|
},
|
|
)
|