更新日期 / Updated: 2026-03-07 状态 / Status: 已测试通过 / Tested and Passed
- 环境准备 / Environment Preparation
- 快速部署 / Quick Deployment
- 详细步骤 / Detailed Steps
- 验证测试 / Verification Tests
- 常见问题 / Common Issues
- 启动命令汇总 / Startup Commands Summary
| 要求 / Requirement | 版本 / Version | 说明 / Description |
|---|---|---|
| Node.js | >= 18.0.0 | 运行前端和后端 / Run frontend and backend |
| npm | >= 9.0.0 | 包管理器 / Package manager |
| Git | 任意版本 / Any version | 代码版本控制 / Version control |
# 检查 Node.js 版本 / Check Node.js version
node --version
# 输出示例 / Example output: v22.22.0
# 检查 npm 版本 / Check npm version
npm --version
# 输出示例 / Example output: 10.9.4# 1. 克隆项目 / Clone project
git clone https://github.com/linuxhsj/askonce.git
cd askonce
# 2. 创建配置文件 / Create config file
cp .env.example .env
# 然后编辑 .env 填入你的 API Key / Then edit .env to add your API Key
# 3. 安装依赖并启动 / Install dependencies and start
cd frontend && npm install && cd ..
cd backend/node && npm install
# 4. 启动服务 / Start services
# 终端1: 后端 / Terminal 1: Backend
cd backend/node && npm run dev
# 终端2: 前端 / Terminal 2: Frontend
cd frontend && npm run dev
# 5. 访问 / Access
# 前端 / Frontend: http://localhost:3000
# 后端 / Backend: http://localhost:8000git clone https://github.com/linuxhsj/askonce.git
cd askonce# 1. 复制环境变量模板 / Copy environment template
cp .env.example .env
# 2. 编辑配置文件 / Edit config file
nano .env
# 或 / or
vim .env填入以下内容(至少选择一种 API)/ Fill in the following (at least one API required):
# DeepSeek (推荐,性价比高 / Recommended, cost-effective)
DEEPSEEK_API_KEY=sk-xxxxxxxxxxxxxxxx
# OpenAI (GPT 系列 / GPT series)
OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxx
# Anthropic (Claude 系列 / Claude series)
ANTHROPIC_API_KEY=sk-ant-xxxxxxxxxxxxxxxx
# OpenRouter (可访问多种模型 / Access multiple models)
OPENROUTER_API_KEY=sk-or-xxxxxxxxxxxxxxxx
# 服务配置 / Service Configuration
PORT=8000
MAX_CONCURRENT=10
DEFAULT_TIMEOUT=60000cd frontend
npm installcd ../backend/node
npm install# 在终端1中执行 / Execute in Terminal 1
cd backend/node
npm run dev成功启动后输出 / Output after successful startup:
╔═══════════════════════════════════════════════════════════╗
║ AskOnce API Server ║
║ Server running at: http://localhost:8000 ║
║ WebSocket at: ws://localhost:8000/ws ║
╚═══════════════════════════════════════════════════════════╝
# 在终端2中执行 / Execute in Terminal 2
cd frontend
npm run dev成功启动后输出 / Output after successful startup:
VITE v5.x.x ready in xxx ms
➜ Local: http://localhost:3000/
➜ Network: use --host to expose
curl http://localhost:8000/api/health预期输出 / Expected output:
{"status":"healthy","timestamp":"2026-03-07T12:00:00.000Z"}curl http://localhost:8000/api/models预期输出 / Expected output: 返回支持的模型列表 / Returns list of supported models
curl -X POST http://localhost:8000/api/query \
-H "Content-Type: application/json" \
-d '{"prompt": "你好", "model_ids": ["deepseek-v3"]}'预期输出 / Expected output:
{
"request_id": "req_xxxx",
"status": "completed",
"results": [{
"model_id": "deepseek-v3",
"status": "completed",
"content": "你好,我是DeepSeek...",
"tokens_used": 20,
"duration": 1500
}]
}curl -X POST http://localhost:8000/api/query \
-H "Content-Type: application/json" \
-d '{"prompt": "什么是AI?", "model_ids": ["deepseek-v3", "deepseek-r1"]}'打开浏览器访问 / Open browser and visit: http://localhost:3000
问题 / Issue: 启动时提示端口被占用 / Port is occupied on startup
解决 / Solution:
# 查找占用端口的进程 / Find process using port
lsof -i :3000
lsof -i :8000
# 杀掉占用进程 / Kill the process
kill -9 <PID>
# 或者使用其他端口启动 / Or use another port
cd frontend && npm run dev -- --port 3001问题 / Issue: 返回 401 Authentication Fails 错误 / Returns 401 error
解决 / Solution:
- 检查 .env 文件中的 API Key 是否正确 / Check if API Key in .env is correct
- 确保 API Key 没有过期 / Ensure API Key hasn't expired
- 重新启动后端服务让配置生效 / Restart backend to apply configuration
# 重启后端 / Restart backend
pkill -f "tsx"
cd backend/node && npm run dev问题 / Issue: 前端页面加载但无法发送请求 / Frontend loads but cannot send requests
解决 / Solution:
- 检查后端是否正常运行 / Check if backend is running:
curl http://localhost:8000/api/health - 检查 vite.config.ts 中的代理配置是否正确 / Check proxy configuration in vite.config.ts
- 清除浏览器缓存 / Clear browser cache
问题 / Issue: npm install 报错找不到模块 / npm install reports module not found
解决 / Solution:
# 清除缓存重新安装 / Clear cache and reinstall
rm -rf node_modules package-lock.json
npm install# ==========================================
# 终端1: 启动后端 / Terminal 1: Start Backend
# ==========================================
cd askonce/backend/node
npm run dev
# 后端地址 / Backend URL: http://localhost:8000
# ==========================================
# 终端2: 启动前端 / Terminal 2: Start Frontend
# ==========================================
cd askonce/frontend
npm run dev
# 前端地址 / Frontend URL: http://localhost:3000# 1. 配置环境变量 / Configure environment variables
cp .env.example .env
nano .env # 填入 API Key / Add API Key
# 2. 启动所有服务 / Start all services
docker-compose up -d
# 3. 访问 / Access
# 前端 / Frontend: http://localhost:3000
# 后端 / Backend: http://localhost:8000
# SearXNG: http://localhost:8888 (可选 / Optional)# 停止所有服务 / Stop all services
pkill -f "tsx"
pkill -f "vite"
# 或在 Docker 中 / Or in Docker
docker-compose down| 模型 ID / Model ID | 名称 / Name | API Key |
|---|---|---|
| deepseek-v3 | DeepSeek V3 | DEEPSEEK_API_KEY |
| deepseek-r1 | DeepSeek R1 | DEEPSEEK_API_KEY |
| 模型 ID / Model ID | 名称 / Name | API Key |
|---|---|---|
| gpt-4o | GPT-4o | OPENAI_API_KEY |
| o1 | o1 | OPENAI_API_KEY |
| 模型 ID / Model ID | 名称 / Name | API Key |
|---|---|---|
| claude-sonnet-4 | Claude Sonnet 4 | ANTHROPIC_API_KEY |
| claude-opus-4 | Claude Opus 4 | ANTHROPIC_API_KEY |
| 模型 ID / Model ID | 名称 / Name | API Key |
|---|---|---|
| google/gemini-1.5-pro | Gemini 1.5 Pro | OPENROUTER_API_KEY |
| x-ai/grok-2 | Grok 2 | OPENROUTER_API_KEY |
| meta-llama/llama-3.1-70b-instruct | Llama 3.1 70B | OPENROUTER_API_KEY |
- 测试报告 / Test Report - 详细测试记录 / Detailed test records
- 快速开始 / Getting Started - 官方快速开始指南 / Official quick start guide
- 项目状态 / Project Status - 项目完成情况 / Project completion status
文档版本 / Document Version: v1.1 创建日期 / Created: 2026-03-07 作者 / Author: SeekSage