Issues #32-33: Quick Wins Complete!
# Install FastAPI and uvicorn (if not already installed)
pip install fastapi uvicorn pydantic
# Start the server
python api_server.pyServer will start on http://localhost:8000
API Documentation: http://localhost:8000/docs (interactive Swagger UI)
- Start the API server first (see above)
- Open
web_ui/index.htmlin your browser
# Option 1: Open directly
open web_ui/index.html
# Option 2: Serve with Python (recommended for CORS)
python -m http.server 8080 --directory web_ui
# Then open http://localhost:8080GET /
- Health check and API info
GET /health
- System health status
GET /concepts
- List all concept IDs
GET /concepts/{concept_id}
- Get concept details
POST /concepts
- Create new concept
POST /query
- Query the knowledge graph
{
"query": "dog to animal",
"use_nlp": false,
"max_depth": 10
}POST /inference
- Get inference chain between concepts
{
"start_concept": "dog",
"target_concept": "animal"
}POST /analogy
- Find analogies using structural similarity
{
"source_concept": "dog",
"target_domain_concepts": ["cat", "bird", "fish"]
}POST /synthesize
- Synthesize new concept from examples (abductive learning)
{
"concept_name": "mammal",
"examples": [
{"properties": {"warm_blooded": true, "gives_birth": true}},
{"properties": {"warm_blooded": true, "gives_birth": true}}
]
}GET /stats
- System statistics (concepts, relations, GPU status, learner stats)
GET /strategy/recommend/{query_type}
- Recommend best inference strategy
- Query types:
classification,analogy,explanation,prediction, etc.
- Natural language or symbolic queries
- Visual inference chain display
- Confidence scores
- Explanations
- Concepts Tab: Browse all concepts
- Statistics Tab: View system metrics
- Total concepts
- Total relations
- Inference rules
- GPU status
Inference Chain
- Find reasoning path between two concepts
- Visual step-by-step display
Analogical Reasoning
- Find structural analogies
- Similarity scores
Concept Synthesis
- Create new concepts from examples
- Abductive learning
- Start API server:
python api_server.py - Open Web UI:
web_ui/index.html - Query: Enter "dog to animal"
- Result: See inference chain: dog → mammal → animal
- Navigate to: Advanced Tools → Analogy tab
- Source: "dog"
- Targets: "cat, bird, fish"
- Result: Shows similarity scores for each analog
- Navigate to: Advanced Tools → Synthesize tab
- Name: "new_mammal"
- Click: Synthesize from Examples
- Result: System creates concept with inferred properties
import requests
# Query endpoint
response = requests.post('http://localhost:8000/query', json={
"query": "dog to animal",
"use_nlp": False
})
result = response.json()
print(result['inference_chain'])
# Output: ['dog', 'mammal', 'animal']Edit api_server.py to configure:
hostandport(default: 0.0.0.0:8000)- CORS origins (default: all -
["*"]) - GPU usage (default: enabled)
- Demo knowledge (animal hierarchy pre-loaded)
Edit web_ui/index.html:
API_BASEconstant (line 333)- Default:
http://localhost:8000 - Change if API runs on different host/port
The API server starts with demo concepts:
- animal (living thing)
- mammal (is animal, warm-blooded, gives birth)
- dog (is mammal, domesticated, barks)
- cat (is mammal, domesticated, meows)
Try these queries:
dog to animalcat to animaldog(source) →cat(analogy target)
- Make sure API server is running:
python api_server.py - Check server output for errors
- Verify port 8000 is not in use
- Serve Web UI via HTTP server (not file://)
- Use:
python -m http.server 8080 --directory web_ui
- Install dependencies:
pip install fastapi uvicorn pydantic - Make sure you're in the project root directory
- API server should auto-initialize demo concepts
- Try creating a concept via API docs: http://localhost:8000/docs
- Add more concepts via API or Web UI
- Integrate with external ontologies (Phase 2 features)
- Build custom queries using the API
- Extend Web UI with graph visualization
✅ Issue #32: REST API with FastAPI
- 10+ endpoints
- Full Phase 4 feature coverage
- Interactive API docs
- CORS enabled for web UI
✅ Issue #33: Web UI
- Modern, responsive design
- Query interface with visual inference chains
- Concept browser with statistics
- Advanced tools (inference, analogy, synthesis)
- Real-time status updates
Next: Phase 5 - Consciousness Metrics (tomorrow!)