""" Convert comprehensive knowledge base to ALU Brain JSON format """ import json from pathlib import Path def convert_kb_to_brain_format(): """Convert the comprehensive KB into ALU Brain JSON entries""" # Read the comprehensive knowledge base kb_file = Path("data/alu_knowledge/alu_ultimate_knowledge_base.txt") if not kb_file.exists(): print(f"❌ Knowledge base file not found: {kb_file}") return with open(kb_file, 'r', encoding='utf-8') as f: kb_text = f.read() # Split into sections sections = kb_text.split('\n## ') brain_entries = [] for section in sections[1:]: # Skip first empty section lines = section.split('\n') title = lines[0].strip() content = '\n'.join(lines[1:]).strip() # Create brain entry entry = { "question": f"Tell me about {title}", "answer": content[:500] + "..." if len(content) > 500 else content, # Limit length "type": "text", "category": "comprehensive_kb", "keywords": title.lower().split() } brain_entries.append(entry) # Save to new JSON file output_file = Path("alu_brain/comprehensive_kb.json") with open(output_file, 'w', encoding='utf-8') as f: json.dump(brain_entries, f, indent=2) print(f"✅ Created {len(brain_entries)} entries in {output_file}") print(f"📝 Sample entry: {brain_entries[0]['question']}") if __name__ == "__main__": convert_kb_to_brain_format()