1.7 KiB
1.7 KiB
GAME GENERATOR
🚀 TỐI ƯU API CALLS
| Trước | Sau |
|---|---|
| Analyzer: 1 call | Analyzer: 1 call |
| Generate: N calls (1 per game) | Generate: 1 call (tất cả games) |
| Validator: N calls | Validator: 0 call (Python) |
| Tổng: N+1 calls | Tổng: 1-2 calls |
📁 Cấu trúc
gen_using_graph/
├── api.py # FastAPI server
├── requirements.txt
│
└── src/
├── core.py # Core engine (tối ưu API calls)
├── game_registry.py # Auto-load games
├── validator.py # Hallucination check (không dùng API)
│
└── games/ # Game definitions
├── _template.py # Template
├── quiz.py # Quiz game
└── fill_blank.py # Fill-blank game
🔌 API ENDPOINTS
Generate games
POST /generate
{
"text": "Văn bản...",
"enabled_games": ["quiz", "fill_blank"],
"run_analyzer": true,
"run_validator": true,
"max_items": 3
}
# Response includes:
# "api_calls": 2 <-- Số lần gọi LLM
Xem games
GET /games
Bật/Tắt game
POST /games/quiz/activate
POST /games/quiz/deactivate
Reload
POST /reload
🎮 THÊM GAME MỚI
- Copy
src/games/_template.py→src/games/new_game.py - Sửa nội dung
- Gọi
POST /reload
✅ BẬT/TẮT GAME
# Trong file game
GAME_CONFIG = {
"active": True, # Bật
"active": False, # Tắt
}
Hoặc qua API:
curl -X POST http://localhost:8000/games/quiz/deactivate
🚀 Chạy
pip install -r requirements.txt
export GOOGLE_API_KEY=your_key
uvicorn api:app --port 8000