Support .env for server-local Ollama config to avoid git pull conflicts.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,20 +1,55 @@
|
||||
"""
|
||||
Trading Studio 全局配置模块
|
||||
统一存放局域网节点、模型名称、固定 Prompt 及本地路径。
|
||||
|
||||
服务器本地覆盖:复制 .env.example 为 .env 并修改(不入 Git),无需改 config.py。
|
||||
"""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def _load_dotenv() -> None:
|
||||
"""加载项目根目录 .env(简单 KEY=VALUE 格式,无第三方依赖)。"""
|
||||
env_path = Path(__file__).resolve().parent / ".env"
|
||||
if not env_path.is_file():
|
||||
return
|
||||
for raw in env_path.read_text(encoding="utf-8").splitlines():
|
||||
line = raw.strip()
|
||||
if not line or line.startswith("#") or "=" not in line:
|
||||
continue
|
||||
key, val = line.split("=", 1)
|
||||
key = key.strip()
|
||||
val = val.strip().strip('"').strip("'")
|
||||
if key and key not in os.environ:
|
||||
os.environ[key] = val
|
||||
|
||||
|
||||
_load_dotenv()
|
||||
|
||||
|
||||
def _env_str(key: str, default: str) -> str:
|
||||
return os.environ.get(key, default).strip()
|
||||
|
||||
|
||||
def _env_int(key: str, default: int) -> int:
|
||||
try:
|
||||
return int(os.environ.get(key, str(default)).strip())
|
||||
except ValueError:
|
||||
return default
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 网络与服务
|
||||
# ---------------------------------------------------------------------------
|
||||
# 远程 Ollama 节点(局域网大模型审查润色)
|
||||
OLLAMA_HOST = "192.168.8.64"
|
||||
OLLAMA_PORT = 11434
|
||||
# 生产环境请在 .env 中设置 OLLAMA_HOST,避免 git pull 冲突
|
||||
OLLAMA_HOST = _env_str("OLLAMA_HOST", "192.168.8.64")
|
||||
OLLAMA_PORT = _env_int("OLLAMA_PORT", 11434)
|
||||
OLLAMA_URL = f"http://{OLLAMA_HOST}:{OLLAMA_PORT}/api/chat"
|
||||
|
||||
# 指定无限制版 Gemma4 模型
|
||||
MODEL_NAME = "huihui_ai/gemma-4-abliterated:e4b"
|
||||
MODEL_NAME = _env_str("MODEL_NAME", "huihui_ai/gemma-4-abliterated:e4b")
|
||||
|
||||
# Gradio 中控固定端口(硬性死规则)
|
||||
HOST = "0.0.0.0"
|
||||
|
||||
Reference in New Issue
Block a user