From a47eb1eaef978c3aa52f0bd00e1b7b11bb0e8755 Mon Sep 17 00:00:00 2001 From: 666ghj <670939375@qq.com> Date: Fri, 19 Dec 2025 13:58:35 +0800 Subject: [PATCH] Refactor project structure by removing Docker support and updating environment configuration - Deleted docker-compose.yml, backend Dockerfile, frontend Dockerfile, and nginx configuration to streamline project setup. - Updated .env.example to reorganize LLM and ZEP API configurations for clarity and ease of use. - Enhanced README.md to reflect changes in project structure and provide clearer setup instructions. --- .env.example | 10 ++- README.md | 190 ++++++++++---------------------------------- backend/Dockerfile | 59 -------------- docker-compose.yml | 44 ---------- frontend/Dockerfile | 34 -------- frontend/nginx.conf | 45 ----------- 6 files changed, 46 insertions(+), 336 deletions(-) delete mode 100644 backend/Dockerfile delete mode 100644 docker-compose.yml delete mode 100644 frontend/Dockerfile delete mode 100644 frontend/nginx.conf diff --git a/.env.example b/.env.example index 2f53d76..913e07c 100644 --- a/.env.example +++ b/.env.example @@ -1,11 +1,13 @@ -# ===== ZEP记忆图谱配置 ===== -ZEP_API_KEY=your_zep_api_key_here - -# ===== 通用 LLM 配置 ===== +# LLM API配置(支持 OpenAI SDK 格式的任意 LLM) +# 推荐使用阿里百炼平台Qwen-plus模型:https://bailian.console.aliyun.com/ LLM_API_KEY=your_api_key_here LLM_BASE_URL=https://dashscope.aliyuncs.com/compatible-mode/v1 LLM_MODEL_NAME=qwen-plus +# ===== ZEP记忆图谱配置 ===== +# 每月免费额度即可支撑使用:https://app.getzep.com/ +ZEP_API_KEY=your_zep_api_key_here + # ===== 加速 LLM 配置(可选)===== LLM_BOOST_API_KEY=your_boost_api_key_here LLM_BOOST_BASE_URL=https://another-api-provider.com/v1 diff --git a/README.md b/README.md index 3740166..8381957 100644 --- a/README.md +++ b/README.md @@ -1,58 +1,46 @@ -# MiroFish 🐟 +

+ MiroFish Logo +

-**简洁通用的群体智能引擎,预测万物** +

+ 简洁通用的群体智能引擎,预测万物 +
+ A Simple and Universal Swarm Intelligence Engine, Predicting Anything +

-MiroFish 是一个基于多智能体(Multi-Agent)技术的社交媒体舆情模拟平台,能够模拟 Twitter/Reddit 等社交媒体上的用户行为,预测舆情发展趋势。 +## ⚡ 项目概述 -## 📁 项目结构 +**MiroFish** 是一款基于多智能体技术的新一代 AI 预测引擎。通过提取现实世界的种子信息(如突发新闻、政策草案、金融信号),自动构建出高保真的平行数字世界。在此空间内,成千上万个具备独立人格、长期记忆与行为逻辑的智能体进行自由交互与社会演化。你可透过「上帝视角」动态注入变量,精准推演未来走向——**让未来在数字沙盘中预演,助决策在百战模拟后胜出**。 -``` -MiroFish/ -├── backend/ # Flask 后端服务 -│ ├── app/ # 应用核心代码 -│ ├── scripts/ # OASIS 模拟脚本 -│ ├── requirements.txt -│ └── run.py # 后端启动入口 -├── frontend/ # Vue 3 前端 -│ ├── src/ -│ ├── package.json -│ └── vite.config.js -├── .env.example # 环境变量示例 -├── docker-compose.yml # Docker 部署配置 -├── package.json # 根目录启动脚本 -└── README.md -``` +> 你只需:上传一份或多份「种子材料」(舆情分析报告、量化分析报告,甚至有趣的小说故事),并用自然语言描述你的模拟/预测需求 +> MiroFish 将返回:一份详尽的模拟/预测报告,以及一个可深度交互、可按你意愿持续推演的高保真数字世界 ---- +#### 我们的愿景 + +MiroFish 致力于打造映射现实的群体智能镜像,通过捕捉个体互动引发的「群体涌现」,突破传统预测的局限: + +- **于宏观**:我们是决策者的预演实验室,让政策与公关在零风险中试错 +- **于微观**:我们是个人用户的创意沙盘,无论是推演小说结局还是探索脑洞,皆可有趣、好玩、触手可及 + +从严肃预测到趣味仿真,我们让每一个「如果」都能看见结果,让**预测万物**成为可能。 + +## 🎬 演示视频-待上传 + +1. 针对微舆BettaFish生成的武大舆情报告进行预测的完整演示视频 +2. 红楼梦结局预测完整演示视频 +3. 金融方向的预测完整演示视频 ## 🚀 快速开始 ### 前置要求 -在开始之前,请确保已安装以下工具: - | 工具 | 版本要求 | 说明 | 安装检查 | |------|---------|------|---------| | **Node.js** | 18+ | 前端运行环境,包含 npm | `node -v` | | **Python** | 3.11+ | 后端运行环境 | `python --version` | | **uv** | 最新版 | Python 包管理器(替代 pip) | `uv --version` | -#### 安装 uv - -```bash -# macOS/Linux -curl -LsSf https://astral.sh/uv/install.sh | sh - -# Windows (PowerShell) -powershell -c "irm https://astral.sh/uv/install.ps1 | iex" - -# 或使用 Homebrew (macOS) -brew install uv -``` - -> ⚠️ 安装 uv 后需要**重新打开终端**或执行 `source ~/.zshrc` (macOS/Linux) 使其生效。 - -### 配置环境变量 +### 1. 配置环境变量 ```bash # 复制示例配置文件 @@ -61,25 +49,21 @@ cp .env.example .env # 编辑 .env 文件,填入必要的 API 密钥 ``` -必需的环境变量: +**必需的环境变量:** ```env -# LLM 配置(支持 OpenAI 格式的任意 LLM) +# LLM API配置(支持 OpenAI SDK 格式的任意 LLM) +# 推荐使用阿里百炼平台Qwen-plus模型:https://bailian.console.aliyun.com/ LLM_API_KEY=your_api_key -LLM_BASE_URL=https://api.openai.com/v1 -LLM_MODEL_NAME=gpt-4o-mini +LLM_BASE_URL=https://dashscope.aliyuncs.com/compatible-mode/v1 +LLM_MODEL_NAME=qwen-plus # Zep Cloud 配置 +# 每月免费额度即可支撑使用:https://app.getzep.com/ ZEP_API_KEY=your_zep_api_key ``` ---- - -## 📦 部署方式一:源码部署(开发推荐) - -使用 `concurrently` 同时启动前后端,**跨平台兼容**(Windows/macOS/Linux)。 - -### 1. 安装依赖 +### 2. 安装依赖 ```bash # 一键安装所有依赖(根目录 + 前端 + 后端) @@ -96,114 +80,20 @@ npm run setup npm run setup:backend ``` -### 2. 启动服务 +### 3. 启动服务 ```bash # 同时启动前后端(在项目根目录执行) npm run dev ``` -服务地址: +**服务地址:** - 前端:`http://localhost:3000` - 后端 API:`http://localhost:5001` -### 单独启动 +**单独启动:** ```bash -# 仅启动后端 -npm run backend - -# 仅启动前端 -npm run frontend -``` - ---- - -## 🐳 部署方式二:Docker 部署(生产推荐) - -### 前置要求 - -- Docker 20.10+ -- Docker Compose v2+ - -### 启动服务 - -```bash -# 构建并启动所有服务 -docker compose up -d - -# 查看日志 -docker compose logs -f - -# 停止服务 -docker compose down -``` - -服务地址: -- 前端:`http://localhost:3000` -- 后端 API:`http://localhost:5001` - -### 仅构建镜像 - -```bash -# 构建后端镜像 -docker build -t mirofish-backend ./backend - -# 构建前端镜像 -docker build -t mirofish-frontend ./frontend -``` - ---- - -## 🛠 技术栈 - -### 后端 -- **框架**: Flask 3.x -- **LLM 调用**: OpenAI SDK -- **图谱存储**: Zep Cloud -- **模拟引擎**: OASIS (camel-oasis) - -### 前端 -- **框架**: Vue 3 + Composition API -- **构建工具**: Vite -- **可视化**: D3.js -- **HTTP 客户端**: Axios - ---- - -## ⚙️ 环境变量说明 - -| 变量名 | 必需 | 说明 | 默认值 | -|--------|------|------|--------| -| `LLM_API_KEY` | ✅ | LLM API 密钥 | - | -| `LLM_BASE_URL` | ❌ | LLM API 地址 | `https://api.openai.com/v1` | -| `LLM_MODEL_NAME` | ❌ | 模型名称 | `gpt-4o-mini` | -| `ZEP_API_KEY` | ✅ | Zep Cloud API 密钥 | - | -| `FLASK_DEBUG` | ❌ | 调试模式 | `true` | -| `FLASK_HOST` | ❌ | 后端监听地址 | `0.0.0.0` | -| `FLASK_PORT` | ❌ | 后端端口 | `5001` | - ---- - -## 🐛 常见问题 - -### Q: 后端启动报错 "LLM_API_KEY 未配置" -A: 确保 `.env` 文件在项目根目录,且配置了正确的 API 密钥。 - -### Q: 前端无法连接后端 -A: 检查后端是否正常运行在 5001 端口,前端开发服务器会自动代理 `/api/*` 请求。 - -### Q: OASIS 模拟启动失败 -A: 确保已安装 `camel-oasis` 和 `camel-ai` 依赖,且 LLM API 配置正确。 - -### Q: 运行 `npm run setup:backend` 报错 "uv: command not found" -A: uv 未安装或未加入 PATH。请先安装 uv(参考前置要求),安装后**重新打开终端**再执行。 - -### Q: Windows 上 Python 虚拟环境激活失败 -A: 使用 `.venv\Scripts\activate` 而不是 `source .venv/bin/activate`。 - ---- - -## 📄 License - -Apache License 2.0 +npm run backend # 仅启动后端 +npm run frontend # 仅启动前端 +``` \ No newline at end of file diff --git a/backend/Dockerfile b/backend/Dockerfile deleted file mode 100644 index 64d24e0..0000000 --- a/backend/Dockerfile +++ /dev/null @@ -1,59 +0,0 @@ -# MiroFish Backend Dockerfile -# Multi-stage build for smaller image size - -# ============= Build Stage ============= -FROM python:3.11-slim AS builder - -WORKDIR /app - -# 安装构建依赖 -RUN apt-get update && apt-get install -y --no-install-recommends \ - build-essential \ - && rm -rf /var/lib/apt/lists/* - -# 复制依赖文件 -COPY requirements.txt . - -# 创建虚拟环境并安装依赖 -RUN python -m venv /opt/venv -ENV PATH="/opt/venv/bin:$PATH" - -RUN pip install --no-cache-dir --upgrade pip && \ - pip install --no-cache-dir -r requirements.txt - -# ============= Production Stage ============= -FROM python:3.11-slim - -WORKDIR /app - -# 安装运行时依赖 -RUN apt-get update && apt-get install -y --no-install-recommends \ - curl \ - && rm -rf /var/lib/apt/lists/* - -# 从 builder 复制虚拟环境 -COPY --from=builder /opt/venv /opt/venv -ENV PATH="/opt/venv/bin:$PATH" - -# 复制应用代码 -COPY app/ ./app/ -COPY scripts/ ./scripts/ -COPY run.py . - -# 创建上传目录 -RUN mkdir -p uploads/simulations uploads/reports - -# 设置环境变量 -ENV PYTHONUNBUFFERED=1 -ENV FLASK_HOST=0.0.0.0 -ENV FLASK_PORT=5001 - -# 暴露端口 -EXPOSE 5001 - -# 健康检查 -HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ - CMD curl -f http://localhost:5001/health || exit 1 - -# 启动命令 -CMD ["python", "run.py"] diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 2d5f88e..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,44 +0,0 @@ -version: '3.8' - -services: - # 后端服务 - backend: - build: - context: ./backend - dockerfile: Dockerfile - container_name: mirofish-backend - ports: - - "5001:5001" - environment: - - FLASK_HOST=0.0.0.0 - - FLASK_PORT=5001 - - FLASK_DEBUG=false - env_file: - - .env - volumes: - # 持久化上传文件和模拟数据 - - ./data/uploads:/app/uploads - restart: unless-stopped - healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:5001/health"] - interval: 30s - timeout: 10s - retries: 3 - - # 前端服务 - frontend: - build: - context: ./frontend - dockerfile: Dockerfile - args: - - VITE_API_BASE_URL=http://backend:5001 - container_name: mirofish-frontend - ports: - - "3000:80" - depends_on: - - backend - restart: unless-stopped - -networks: - default: - name: mirofish-network diff --git a/frontend/Dockerfile b/frontend/Dockerfile deleted file mode 100644 index 7472607..0000000 --- a/frontend/Dockerfile +++ /dev/null @@ -1,34 +0,0 @@ -# MiroFish Frontend Dockerfile -# Multi-stage build: Node.js build + Nginx serve - -# ============= Build Stage ============= -FROM node:20-alpine as builder - -WORKDIR /app - -# 复制 package 文件 -COPY package*.json ./ - -# 安装依赖 -RUN npm ci - -# 复制源代码 -COPY . . - -# 构建生产版本 -RUN npm run build - -# ============= Production Stage ============= -FROM nginx:alpine - -# 复制 Nginx 配置 -COPY nginx.conf /etc/nginx/conf.d/default.conf - -# 复制构建产物 -COPY --from=builder /app/dist /usr/share/nginx/html - -# 暴露端口 -EXPOSE 80 - -# 启动 Nginx -CMD ["nginx", "-g", "daemon off;"] diff --git a/frontend/nginx.conf b/frontend/nginx.conf deleted file mode 100644 index 856075e..0000000 --- a/frontend/nginx.conf +++ /dev/null @@ -1,45 +0,0 @@ -server { - listen 80; - server_name localhost; - root /usr/share/nginx/html; - index index.html; - - # Gzip 压缩 - gzip on; - gzip_types text/plain text/css application/json application/javascript text/xml application/xml; - gzip_min_length 1000; - - # Vue Router history 模式支持 - location / { - try_files $uri $uri/ /index.html; - } - - # API 代理到后端 - location /api/ { - proxy_pass http://backend:5001; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_cache_bypass $http_upgrade; - - # 超时设置(模拟可能耗时较长) - proxy_connect_timeout 60s; - proxy_send_timeout 300s; - proxy_read_timeout 300s; - } - - # 健康检查代理 - location /health { - proxy_pass http://backend:5001/health; - } - - # 静态文件缓存 - location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ { - expires 1y; - add_header Cache-Control "public, immutable"; - } -}