feat: ai-service를 ds923에서 맥미니로 이전
- ChromaDB → Qdrant 전환 (맥미니 기존 인스턴스, tk_qc_issues 컬렉션) - Ollama 임베딩/텍스트 생성 URL 분리 (임베딩: 맥미니, 텍스트: GPU서버) - MLX fallback 제거, Ollama 단일 경로로 단순화 - ds923 docker-compose에서 ai-service 제거 - gateway/system3-web nginx: ai-service 프록시를 ai.hyungi.net 경유로 변경 - resolver + 변수 기반 proxy_pass로 런타임 DNS 해석 (컨테이너 시작 실패 방지) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,8 @@ from config import settings
|
||||
|
||||
class OllamaClient:
|
||||
def __init__(self):
|
||||
self.base_url = settings.OLLAMA_BASE_URL
|
||||
self.text_url = settings.OLLAMA_BASE_URL # GPU서버 (텍스트 생성)
|
||||
self.embed_url = settings.OLLAMA_EMBED_URL # 맥미니 (임베딩)
|
||||
self.timeout = httpx.Timeout(float(settings.OLLAMA_TIMEOUT), connect=10.0)
|
||||
self._client: httpx.AsyncClient | None = None
|
||||
|
||||
@@ -22,7 +23,7 @@ class OllamaClient:
|
||||
async def generate_embedding(self, text: str) -> list[float]:
|
||||
client = await self._get_client()
|
||||
response = await client.post(
|
||||
f"{self.base_url}/api/embeddings",
|
||||
f"{self.embed_url}/api/embeddings",
|
||||
json={"model": settings.OLLAMA_EMBED_MODEL, "prompt": text},
|
||||
)
|
||||
response.raise_for_status()
|
||||
@@ -43,49 +44,38 @@ class OllamaClient:
|
||||
messages.append({"role": "system", "content": system})
|
||||
messages.append({"role": "user", "content": prompt})
|
||||
client = await self._get_client()
|
||||
# 조립컴 Ollama 메인, MLX fallback
|
||||
try:
|
||||
response = await client.post(
|
||||
f"{self.base_url}/api/chat",
|
||||
json={
|
||||
"model": settings.OLLAMA_TEXT_MODEL,
|
||||
"messages": messages,
|
||||
"stream": False,
|
||||
"think": False,
|
||||
"options": {"temperature": 0.3, "num_predict": 2048},
|
||||
},
|
||||
)
|
||||
response.raise_for_status()
|
||||
return response.json()["message"]["content"]
|
||||
except Exception:
|
||||
response = await client.post(
|
||||
f"{settings.MLX_BASE_URL}/chat/completions",
|
||||
json={
|
||||
"model": settings.MLX_TEXT_MODEL,
|
||||
"messages": messages,
|
||||
"max_tokens": 2048,
|
||||
"temperature": 0.3,
|
||||
},
|
||||
)
|
||||
response.raise_for_status()
|
||||
return response.json()["choices"][0]["message"]["content"]
|
||||
response = await client.post(
|
||||
f"{self.text_url}/api/chat",
|
||||
json={
|
||||
"model": settings.OLLAMA_TEXT_MODEL,
|
||||
"messages": messages,
|
||||
"stream": False,
|
||||
"think": False,
|
||||
"options": {"temperature": 0.3, "num_predict": 2048},
|
||||
},
|
||||
)
|
||||
response.raise_for_status()
|
||||
return response.json()["message"]["content"]
|
||||
|
||||
async def check_health(self) -> dict:
|
||||
result = {}
|
||||
short_timeout = httpx.Timeout(5.0, connect=3.0)
|
||||
# GPU서버 Ollama (텍스트 생성)
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=short_timeout) as c:
|
||||
response = await c.get(f"{self.base_url}/api/tags")
|
||||
response = await c.get(f"{self.text_url}/api/tags")
|
||||
models = response.json().get("models", [])
|
||||
result["ollama"] = {"status": "connected", "models": [m["name"] for m in models]}
|
||||
result["ollama_text"] = {"status": "connected", "url": self.text_url, "models": [m["name"] for m in models]}
|
||||
except Exception:
|
||||
result["ollama"] = {"status": "disconnected"}
|
||||
result["ollama_text"] = {"status": "disconnected", "url": self.text_url}
|
||||
# 맥미니 Ollama (임베딩)
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=short_timeout) as c:
|
||||
response = await c.get(f"{settings.MLX_BASE_URL}/health")
|
||||
result["mlx"] = {"status": "connected", "model": settings.MLX_TEXT_MODEL}
|
||||
response = await c.get(f"{self.embed_url}/api/tags")
|
||||
models = response.json().get("models", [])
|
||||
result["ollama_embed"] = {"status": "connected", "url": self.embed_url, "models": [m["name"] for m in models]}
|
||||
except Exception:
|
||||
result["mlx"] = {"status": "disconnected"}
|
||||
result["ollama_embed"] = {"status": "disconnected", "url": self.embed_url}
|
||||
return result
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user