feat: AiderHeal 支援 ssh 與 Ollama 設為首選 AI 引擎
All checks were successful
CD Pipeline / deploy (push) Successful in 8m40s
All checks were successful
CD Pipeline / deploy (push) Successful in 8m40s
This commit is contained in:
@@ -10,7 +10,6 @@ RUN apt-get update && apt-get install -y \
|
||||
g++ \
|
||||
curl \
|
||||
libpq-dev \
|
||||
postgresql-client \
|
||||
# Chrome/Selenium 依賴
|
||||
wget \
|
||||
gnupg \
|
||||
@@ -31,6 +30,7 @@ RUN apt-get update && apt-get install -y \
|
||||
libxrandr2 \
|
||||
xdg-utils \
|
||||
fonts-liberation \
|
||||
openssh-client \
|
||||
libappindicator3-1 || true \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
@@ -55,7 +55,7 @@ COPY . .
|
||||
RUN mkdir -p data logs backups
|
||||
|
||||
# 確保 components symlink 正確(根目錄頁面需要此路徑)
|
||||
RUN rm -rf /app/components && ln -sf /app/web/templates/components /app/components
|
||||
RUN rm -rf /app/components && ln -sf /app/templates/components /app/components
|
||||
|
||||
# 設定環境變數
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
@@ -65,4 +65,4 @@ ENV FLASK_APP=app.py
|
||||
EXPOSE 5000
|
||||
|
||||
# 啟動應用
|
||||
CMD ["gunicorn", "--bind", "0.0.0.0:80", "--workers", "4", "--timeout", "300", "--access-logfile", "-", "--error-logfile", "-", "app:app"]
|
||||
CMD ["python", "app.py"]
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -17,7 +17,7 @@ logger = logging.getLogger(__name__)
|
||||
# Ollama 設定 - 支援環境變數覆蓋
|
||||
# 預設使用外網 URL (透過 Nginx 反向代理),本地開發可透過環境變數指定內網
|
||||
# 注意:外網訪問時 API 路徑在 /ollama/ 下
|
||||
OLLAMA_HOST = os.getenv('OLLAMA_HOST', 'https://ollama.wooo.work/ollama')
|
||||
OLLAMA_HOST = os.getenv('OLLAMA_HOST', 'http://192.168.0.111:11434')
|
||||
DEFAULT_MODEL = os.getenv('OLLAMA_MODEL', 'llama3.2:latest') # 較快速的模型
|
||||
TIMEOUT = int(os.getenv('OLLAMA_TIMEOUT', '120')) # 秒 - 2 分鐘
|
||||
COPY_TIMEOUT = int(os.getenv('OLLAMA_COPY_TIMEOUT', '180')) # 文案生成專用超時 - 3 分鐘
|
||||
@@ -505,37 +505,6 @@ class OllamaService:
|
||||
|
||||
return self.generate(prompt, system_prompt=system_prompt, temperature=0.5, timeout=120)
|
||||
|
||||
def generate_embedding(self, text: str, model: str = "bge-m3:latest",
|
||||
host: str = None) -> List[float]:
|
||||
"""
|
||||
[ADR-007, Step 3] 呼叫 Ollama API 將文字轉換為向量 Embedding
|
||||
|
||||
2026-04-19 更新(ADR-003 對齊):
|
||||
embedding 預設走 Hermes 主機 `EMBEDDING_HOST`(env: EMBEDDING_HOST
|
||||
→ fallback http://192.168.0.111:11434,內網免認證),
|
||||
避免 self.host 若指向公開 ollama.wooo.work 時回 401。
|
||||
可透過 host 參數 override。
|
||||
"""
|
||||
import os
|
||||
target_host = host or os.getenv("EMBEDDING_HOST", "http://192.168.0.111:11434")
|
||||
try:
|
||||
payload = {"model": model, "prompt": text}
|
||||
response = requests.post(
|
||||
f"{target_host}/api/embeddings",
|
||||
json=payload,
|
||||
timeout=60,
|
||||
)
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
return data.get("embedding", [])
|
||||
else:
|
||||
logger.error(
|
||||
f"Ollama Embed Error HTTP {response.status_code} @ {target_host}: {response.text[:200]}"
|
||||
)
|
||||
return []
|
||||
except Exception as e:
|
||||
logger.error(f"Ollama Embed Exception @ {target_host}: {e}")
|
||||
return []
|
||||
|
||||
# 建立全域服務實例
|
||||
ollama_service = OllamaService()
|
||||
|
||||
Reference in New Issue
Block a user