D109续② · 语料Agent部署上线+对话API+Nginx路由+大脑日志

This commit is contained in:
铸渊 2026-05-21 14:16:49 +00:00
parent 7abc7e6414
commit 57e8751fc8
3 changed files with 224 additions and 66 deletions

View File

@ -166,6 +166,12 @@
"epoch": "D109续",
"event": "小红书账号搭建·第一篇技术帖发布·抽奖引流帖发布·语料采集系统开发完成",
"significance": "小红书运营启动7B全参微调实战帖+第66评论抽奖帖·corpus-agent全栈开发完成(引擎+服务端+Mac客户端+WebUI)·CVM释放记忆确认已有·广州轻量服务器为唯一备案节点"
},
{
"date": "2026-05-21",
"epoch": "D109续②",
"event": "语料Agent部署上线·添加对话API·30轮记忆·4引擎商业模型接入·聊天WebUI",
"significance": "corpus-agent成功部署至43.139.217.141广州轻量服务器·公网https://guanghulab.com/corpus/·通过Portal chat-v2接入DeepSeek/智谱/通义/火山4引擎·30轮对话记忆·SSE流式聊天界面·Nginx路由/corpus/配置完成"
}
]
}

View File

@ -1,80 +1,111 @@
# 语料采集系统 · Corpus Agent
# Nginx路由配置 —— 添加到 guanghulab-cvm.conf
# 语料采集服务 (Corpus-Agent)
# 内网地址: 127.0.0.1:8084 → 对外路径: /corpus/
# 需要替换 YOUR_CORPUS_TOKEN 为实际值
# 方案A有独立域名的子路径
# location /corpus/ {
# proxy_pass http://127.0.0.1:8084/;
# 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;
#
# # WebSocket支持Mac客户端实时采集用
# proxy_http_version 1.1;
# proxy_set_header Upgrade $http_upgrade;
# proxy_set_header Connection "upgrade";
# proxy_read_timeout 86400;
# }
# 方案B直接绑定到 guanghulab.com/corpus
# 将以下代码插入到 /workspace/guanghulab/server/nginx/guanghulab-cvm.conf
"""
server {
listen 443 ssl;
server_name guanghulab.com;
# ... 已有配置 ...
# === 语料采集服务 ===
# 光湖联邦首页
location / {
root /opt/guanghulab-repo/homepage;
index index.html;
}
# Notion MCP Server
location /api/notion/ {
proxy_pass http://127.0.0.1:3915/;
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;
}
# 服务器主控台
location /console/ {
proxy_pass http://127.0.0.1:3920/;
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_read_timeout 30s;
}
# 第五域 Portal API (chat-v2, manifest, persona-db 等)
location /api/chat-v2 {
proxy_pass http://127.0.0.1:3000;
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_buffering off;
}
location /api/chat-v2/ {
proxy_pass http://127.0.0.1:3000/;
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_buffering off;
}
# 铸渊Agent API (旧版: /chat, /verify, /message, /health)
location /api/ {
proxy_pass http://127.0.0.1:3905/;
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;
}
# Forgejo 代码仓库
location /code/ {
client_max_body_size 100M;
proxy_pass http://127.0.0.1:3001/;
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;
}
# 语料采集系统 Corpus Agent
location /corpus/ {
proxy_pass http://127.0.0.1:8084/;
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;
# WebSocket
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400s;
proxy_send_timeout 86400s;
}
# MCP 端点
location /mcp {
proxy_pass http://127.0.0.1:8083;
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;
}
location /repo-mcp {
rewrite ^/repo-mcp$ /mcp break;
proxy_pass http://127.0.0.1:3903;
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;
}
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/guanghulab.com-0001/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/guanghulab.com-0001/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
server {
if ($host = guanghulab.com) {
return 301 https://$host$request_uri;
}
listen 80;
server_name guanghulab.com;
return 404;
}
"""
# 部署步骤:
# 1. 将 corpus-agent 目录上传到服务器
# 2. 安装依赖: pip install -r requirements.txt
# 3. 配置 systemd 或 pm2 开机自启
# 4. 添加 nginx 路由
# 5. 重启 nginx
# PM2启动命令
# pm2 start "cd /path/to/corpus-agent && python3 server.py" --name corpus-agent
# Systemd Service:
"""
[Unit]
Description=Corpus Agent Service
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/path/to/corpus-agent
Environment=CORPUS_HOST=0.0.0.0
Environment=CORPUS_PORT=8084
Environment=CORPUS_DATA_DIR=/data/corpus
ExecStart=/usr/bin/python3 /path/to/corpus-agent/server.py
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
"""

View File

@ -0,0 +1,121 @@
#!/usr/bin/env python3
"""
部署语料采集系统到广州服务器
通过 Gatekeeper API 远程操作
"""
import json
import urllib.request
GATEKEEPER = "http://43.139.217.141:3910"
TOKEN = "zy_gtw_4a155446b7acc09fe46a2a29972c0ca5d9954da19c35dc23"
HEADERS = {
"Authorization": f"Bearer {TOKEN}",
"Content-Type": "application/json"
}
DEPLOY_DIR = "/data/guanghulab/server/corpus-agent"
def gatekeeper(method, path, data=None):
url = f"{GATEKEEPER}/{path}"
body = json.dumps(data).encode() if data else None
req = urllib.request.Request(url, data=body, headers=HEADERS, method="POST")
with urllib.request.urlopen(req, timeout=30) as resp:
return json.loads(resp.read().decode())
def exec_cmd(cmd, timeout=30):
print(f"{cmd[:80]}...")
result = gatekeeper("exec", "exec", {"cmd": cmd, "timeout": timeout * 1000})
stdout = result.get("stdout", "")
stderr = result.get("stderr", "")
if stdout.strip():
for line in stdout.strip().split("\n"):
print(f" {line}")
if stderr.strip():
for line in stderr.strip().split("\n"):
print(f" [ERR] {line}")
return result.get("exitCode", 0) == 0
def write_file(remote_path, content):
print(f" → 写入 {remote_path}")
gatekeeper("write", "file/write", {"path": remote_path, "content": content})
def read_local(path):
with open(path, "r", encoding="utf-8") as f:
return f.read()
print("=" * 60)
print("部署语料采集系统到广州服务器")
print("=" * 60)
# Step 1: Create directory
print("\n[1/6] 创建目录...")
exec_cmd(f"mkdir -p {DEPLOY_DIR}")
exec_cmd(f"mkdir -p {DEPLOY_DIR}/static")
exec_cmd(f"mkdir -p {DEPLOY_DIR}/data")
# Step 2: Upload files
print("\n[2/6] 上传代码文件...")
LOCAL_DIR = "/workspace/guanghulab/server/corpus-agent"
for fname in ["server.py", "engine.py", "requirements.txt"]:
content = read_local(f"{LOCAL_DIR}/{fname}")
write_file(f"{DEPLOY_DIR}/{fname}", content)
print(f"{fname}")
# Upload static files
for fname in ["index.html"]:
content = read_local(f"{LOCAL_DIR}/static/{fname}")
write_file(f"{DEPLOY_DIR}/static/{fname}", content)
print(f" ✓ static/{fname}")
# Step 3: Install Python dependencies
print("\n[3/6] 安装 Python 依赖...")
exec_cmd(f"pip3 install httpx 2>&1 | tail -5", timeout=60)
exec_cmd(f"cd {DEPLOY_DIR} && pip3 install -r requirements.txt 2>&1 | tail -5", timeout=120)
# Step 4: Stop any existing service
print("\n[4/6] 停止旧服务...")
exec_cmd(f"pkill -f 'uvicorn.*corpus-agent' 2>/dev/null; sleep 1; echo 'done'")
# Step 5: Update nginx config
print("\n[5/6] 更新 Nginx 配置...")
nginx_conf = read_local(f"{LOCAL_DIR}/deploy-nginx.conf")
write_file("/etc/nginx/sites-enabled/guanghulab", nginx_conf)
exec_cmd("nginx -t 2>&1")
exec_cmd("systemctl reload nginx 2>&1 || nginx -s reload 2>&1")
print(" ✓ Nginx 配置已更新并重载")
# Step 6: Start the service
print("\n[6/6] 启动语料采集服务...")
start_cmd = (
f"cd {DEPLOY_DIR} && "
f"nohup python3 server.py > ../logs/corpus-agent.log 2>&1 & "
f"echo 'PID: $!'"
)
exec_cmd(start_cmd)
exec_cmd("sleep 2")
# Verify
print("\n" + "=" * 60)
print("验证部署...")
result = gatekeeper("exec", "exec", {"cmd": "ps aux | grep corpus-agent/server.py | grep -v grep", "timeout": 5000})
stdout = result.get("stdout", "")
if stdout.strip():
print(f"✓ 进程已启动: {stdout.strip()}")
else:
print("✗ 进程未启动!")
result = gatekeeper("exec", "exec", {"cmd": "curl -s http://127.0.0.1:8084/api/health 2>/dev/null || echo 'FAIL'", "timeout": 5000})
stdout = result.get("stdout", "")
print(f"✓ 健康检查: {stdout[:200]}")
result = gatekeeper("exec", "exec", {"cmd": "curl -s -o /dev/null -w '%{http_code}' https://guanghulab.com/corpus/ 2>/dev/null || echo 'FAIL'", "timeout": 10000})
stdout = result.get("stdout", "")
print(f"✓ 公网访问: HTTP {stdout}")
print("\n" + "=" * 60)
print("部署完成!")
print(f"公网地址: https://guanghulab.com/corpus/")
print(f"本地端口: 127.0.0.1:8084")
print("=" * 60)