# Clone 项目
git clone https://github.com/yourusername/openspace-openhands-evolution.git
cd openspace-openhands-evolution
# 安装依赖
pip install -e .
# 运行设置脚本
python setup_production.py选项 A: 环境变量(推荐)
# OpenAI
export OPENAI_API_KEY=sk-your-openai-key
# Anthropic
export ANTHROPIC_API_KEY=sk-ant-your-key选项 B: 配置文件
编辑 config.yaml:
llm:
provider: openai
model: gpt-4
api_key: "sk-your-key"# 交互式模式
openspace-evolution
# 或直接运行任务
openspace-evolution run "Create a Flask REST API with user authentication"openspace-evolution run "
Create a Flask REST API for a todo list application with:
- CRUD operations (Create, Read, Update, Delete)
- SQLite database
- Input validation
- Error handling
- API documentation
"输出:
workspace/app.py- Flask 应用workspace/models.py- 数据模型workspace/requirements.txt- 依赖列表
openspace-evolution run "
Write a Python script to:
1. Read a CSV file from 'data/sales.csv'
2. Calculate monthly revenue
3. Generate a summary report
4. Save results to 'output/report.txt'
"openspace-evolution run "
Create a React component for a user profile card that shows:
- User avatar
- Name and bio
- Social media links
- Follow/unfollow button
Use TypeScript and styled-components.
" --language javascript --framework react# 从 project-a 迁移技能到 project-b
openspace-evolution transfer \
--from project-a \
--to project-b \
--min-similarity 0.8openspace-evolution status输出示例:
OpenSpace Engine: ✅ Running (15 skills)
OpenHands Engine: ✅ Running (GPT-4)
Monitor System: ✅ Running (threshold: 0.8)
Governance: ✅ Active (V-02, V-06 enabled)
所有代码在隔离环境中执行:
- ✅ 无法访问系统文件
- ✅ 超时保护(默认 30 秒)
- ✅ 输出限制(1MB)
- ✅ 危险命令阻止
在 config.yaml 中配置:
openhands:
enable_file_operations: true
allowed_directories:
- ./workspace
- ./output
sandbox_timeout: 30# 实时日志
tail -f logs/evolution.log
# 查看错误
grep ERROR logs/evolution.log每次执行都会记录:
- 执行时间
- 成功率
- Token 使用量
- 质量评分
❌ 不好: "Create an API"
✅ 好: "Create a Flask REST API for user management with JWT authentication, including registration, login, and profile update endpoints"
openspace-evolution run "Build a web scraper" \
--language python \
--framework beautifulsoup将大任务分解:
# Step 1: 设计数据库
openspace-evolution run "Design SQLite schema for blog"
# Step 2: 实现后端
openspace-evolution run "Implement Flask backend for blog"
# Step 3: 创建前端
openspace-evolution run "Create React frontend for blog"# 生成的文件保存在 workspace/
ls workspace/
# 查看生成的代码
cat workspace/app.pyError: OpenAI API key not configured
解决:
export OPENAI_API_KEY=sk-your-key
# 或编辑 config.yamlError: Execution timed out after 30 seconds
解决: 增加超时时间
openhands:
sandbox_timeout: 60 # 增加到 60 秒检查 workspace/ 中的错误日志:
cat logs/evolution.log | grep ERROR优点: 最强大的代码生成能力 成本: $0.03/1K tokens
llm:
provider: openai
model: gpt-4优点: 更好的长上下文理解 成本: $0.015/1K tokens
llm:
provider: anthropic
model: claude-3-opus-20240229优点: 免费、隐私保护 缺点: 需要本地 GPU
# 安装 Ollama
curl -fsSL https://ollama.ai/install.sh | sh
# 拉取模型
ollama pull llama2
# 配置llm:
provider: ollama
model: llama2
base_url: http://localhost:11434技能会自动缓存,重复任务更快。
import asyncio
from openspace_openhands_evolution import EvolutionOrchestrator, TaskRequest
async def run_parallel_tasks():
orchestrator = EvolutionOrchestrator(config)
tasks = [
TaskRequest(id="task-1", description="Create API endpoint 1", ...),
TaskRequest(id="task-2", description="Create API endpoint 2", ...),
]
results = await asyncio.gather(
*[orchestrator.execute_task(t) for t in tasks]
)
return resultsmonitor:
quality_threshold: 0.7 # 降低以加快速度(默认 0.8)- Issues: GitHub Issues
- Discussions: GitHub Discussions
Happy Coding! 🚀