Files
AIclinicalresearch/docs/07-运维文档/02-环境变量配置模板.md
HaHafeng beb7f7f559 feat(asl): Implement full-text screening core LLM service and validation system (Day 1-3)
Core Components:
- PDFStorageService with Dify/OSS adapters
- LLM12FieldsService with Nougat-first + dual-model + 3-layer JSON parsing
- PromptBuilder for dynamic prompt assembly
- MedicalLogicValidator with 5 rules + fault tolerance
- EvidenceChainValidator for citation integrity
- ConflictDetectionService for dual-model comparison

Prompt Engineering:
- System Prompt (6601 chars, Section-Aware strategy)
- User Prompt template (PICOS context injection)
- JSON Schema (12 fields constraints)
- Cochrane standards (not loaded in MVP)

Key Innovations:
- 3-layer JSON parsing (JSON.parse + json-repair + code block extraction)
- Promise.allSettled for dual-model fault tolerance
- safeGetFieldValue for robust field extraction
- Mixed CN/EN token calculation

Integration Tests:
- integration-test.ts (full test)
- quick-test.ts (quick test)
- cached-result-test.ts (fault tolerance test)

Documentation Updates:
- Development record (Day 2-3 summary)
- Quality assurance strategy (full-text screening)
- Development plan (progress update)
- Module status (v1.1 update)
- Technical debt (10 new items)

Test Results:
- JSON parsing success rate: 100%
- Medical logic validation: 5/5 passed
- Dual-model parallel processing: OK
- Cost per PDF: CNY 0.10

Files: 238 changed, 14383 insertions(+), 32 deletions(-)
Docs: docs/03-涓氬姟妯″潡/ASL-AI鏅鸿兘鏂囩尞/05-寮€鍙戣褰?2025-11-22_Day2-Day3_LLM鏈嶅姟涓庨獙璇佺郴缁熷紑鍙?md
2025-11-22 22:21:12 +08:00

4.8 KiB
Raw Blame History

环境变量配置模板 (.env)

文档说明: 本文档提供完整的 .env 配置模板
使用方式: 复制以下内容到 backend/.env 文件中,并填入真实配置值
创建日期: 2025-11-09


📋 完整配置模板

将以下内容复制到 AIclinicalresearch/backend/.env 文件:

# ================================
# 服务器配置
# ================================
PORT=3001
HOST=0.0.0.0
NODE_ENV=development
LOG_LEVEL=info

# ================================
# 数据库配置
# ================================
DATABASE_URL=postgresql://postgres:your_password@localhost:5432/ai_clinical_research

# ================================
# Redis配置
# ================================
REDIS_URL=redis://localhost:6379

# ================================
# JWT配置
# ================================
JWT_SECRET=your-secret-key-change-in-production-min-32-chars
JWT_EXPIRES_IN=7d

# ================================
# LLM API配置
# ================================

# ---------- DeepSeek (直连) ----------
DEEPSEEK_API_KEY=sk-your-deepseek-api-key
DEEPSEEK_BASE_URL=https://api.deepseek.com

# ---------- Qwen (通过阿里云DashScope) ----------
DASHSCOPE_API_KEY=sk-your-dashscope-api-key

# ---------- Gemini (可选) ----------
GEMINI_API_KEY=your-gemini-api-key

# ================================
# CloseAI配置代理OpenAI和Claude
# ================================
# CloseAI是一个API代理平台提供稳定的OpenAI和Claude访问
# 官网https://platform.openai-proxy.org

# 统一API Key同时用于OpenAI和Claude
CLOSEAI_API_KEY=sk-your-closeai-api-key

# OpenAI端点
CLOSEAI_OPENAI_BASE_URL=https://api.openai-proxy.org/v1

# Claude端点
CLOSEAI_CLAUDE_BASE_URL=https://api.openai-proxy.org/anthropic

# 支持的模型:
# - OpenAI: gpt-5-pro, gpt-4-turbo-preview, gpt-3.5-turbo
# - Claude: claude-sonnet-4-5-20250929, claude-3-5-sonnet-20241022

# ================================
# Dify配置知识库RAG引擎
# ================================
DIFY_API_KEY=app-your-dify-api-key
DIFY_API_URL=http://localhost/v1

# ================================
# 文件上传配置
# ================================
UPLOAD_MAX_SIZE=10485760
UPLOAD_DIR=./uploads

# ================================
# CORS配置
# ================================
CORS_ORIGIN=http://localhost:5173

# ================================
# 注意事项
# ================================
# 1. 请将 your-* 占位符替换为真实的配置值
# 2. .env 文件包含敏感信息,不要提交到 git 仓库
# 3. 生产环境请使用强密码和独立的 API Key
# 4. JWT_SECRET 建议使用 32 位以上随机字符串

🔒 当前真实配置(仅供参考)

CloseAI配置已配置

CLOSEAI_API_KEY=sk-cu0iepbXYGGx2jc7BqP6ogtSWmP6fk918qV3RUdtGC3Edlpo
CLOSEAI_OPENAI_BASE_URL=https://api.openai-proxy.org/v1
CLOSEAI_CLAUDE_BASE_URL=https://api.openai-proxy.org/anthropic

可用模型:

  • OpenAI: gpt-5-pro
  • Claude: claude-sonnet-4-5-20250929

📝 配置步骤

1. 创建 .env 文件

cd AIclinicalresearch/backend
# 复制模板
copy .env.example .env  # Windows
# 或
cp .env.example .env    # Linux/Mac

2. 填入真实配置

打开 backend/.env 文件,替换占位符:

必须配置:

  • DATABASE_URL - 数据库连接
  • DEEPSEEK_API_KEY - DeepSeek API主力模型
  • CLOSEAI_API_KEY - CloseAI APIOpenAI+Claude

可选配置:

  • DASHSCOPE_API_KEY - Qwen模型
  • DIFY_API_KEY - 知识库RAG
  • JWT_SECRET - 生产环境必须修改

3. 验证配置

# 启动后端服务
cd backend
npm run dev

# 检查日志,确认没有 API Key 警告

⚠️ 安全提醒

不要提交到Git

确认 .gitignore 包含:

# 环境变量文件
.env
.env.local
.env.*.local

API Key安全

  1. 定期轮换: 每3个月更换一次API Key
  2. 权限最小化: 只授予必要的权限
  3. 独立密钥: 开发/测试/生产使用不同的Key
  4. 监控使用: 定期检查API调用量和费用

泄露应急

如果API Key不慎泄露

  1. 立即在服务商后台禁用/删除该Key
  2. 生成新的API Key
  3. 更新 .env 文件
  4. 重启服务

🔍 配置验证清单

部署前请确认:

  • DATABASE_URL 配置正确且可连接
  • DEEPSEEK_API_KEY 已配置
  • CLOSEAI_API_KEY 已配置用于GPT-5和Claude-4.5
  • JWT_SECRET 已修改为强密码
  • CORS_ORIGIN 已设置正确的前端地址
  • .env 文件已添加到 .gitignore
  • 所有敏感信息未提交到Git

参考文档: