Files
ai-shiliu/backend_main.py
figmar 81115dc23d 初始提交:识流 AI 助手项目
微信自动回复机器人,基于截图+OCR识别消息,支持关键词规则和 AI(OpenAI/DeepSeek/Dify)自动回复。
技术栈:PySide6 + Flask + Vue3 + RapidOCR + SQLite

注:OCR大模型文件(.onnx / .pdiparams)不纳入版本控制,需单独下载。

🤖 Generated with [Qoder][https://qoder.com]
2026-05-30 15:09:40 +08:00

47 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os
import sys
from pathlib import Path
from app.application.services import AppConfig
from app.infrastructure.backend import start_backend
PROJECT_ROOT = Path(__file__).resolve().parent
VENV_ROOT = PROJECT_ROOT / ".venv"
VENV_DIR = VENV_ROOT / "Scripts"
VENV_PYTHON = VENV_DIR / "python.exe"
def _resolve(path):
try:
return Path(path).resolve()
except Exception:
return None
def _running_in_project_venv():
current_prefix = _resolve(sys.prefix)
if current_prefix == _resolve(VENV_ROOT):
return True
current_executable = _resolve(sys.executable)
return current_executable == _resolve(VENV_PYTHON)
def ensure_project_venv():
if _running_in_project_venv():
return
if os.environ.get("OPENCLAW_PROJECT_VENV_REEXEC") == "1":
raise RuntimeError("重启后仍未进入项目 .venv请检查 .venv 是否损坏")
if not VENV_PYTHON.exists():
raise RuntimeError(f"未找到项目 .venv 解释器: {VENV_PYTHON}")
os.environ["OPENCLAW_PROJECT_VENV_REEXEC"] = "1"
os.chdir(str(PROJECT_ROOT))
os.execv(str(VENV_PYTHON), [str(VENV_PYTHON), str(PROJECT_ROOT / "backend_main.py")])
ensure_project_venv()
if __name__ == "__main__":
config = AppConfig()
start_backend(host=config.host, port=config.port)