Initial commit: LLM Automation Docs & Remediation Engine v2.0
Features: - Automated datacenter documentation generation - MCP integration for device connectivity - Auto-remediation engine with safety checks - Multi-factor reliability scoring (0-100%) - Human feedback learning loop - Pattern recognition and continuous improvement - Agentic chat support with AI - API for ticket resolution - Frontend React with Material-UI - CI/CD pipelines (GitLab + Gitea) - Docker & Kubernetes deployment - Complete documentation and guides v2.0 Highlights: - Auto-remediation with write operations (disabled by default) - Reliability calculator with 4-factor scoring - Human feedback system for continuous learning - Pattern-based progressive automation - Approval workflow for critical actions - Full audit trail and rollback capability
This commit is contained in:
0
src/datacenter_docs/utils/__init__.py
Normal file
0
src/datacenter_docs/utils/__init__.py
Normal file
60
src/datacenter_docs/utils/config.py
Normal file
60
src/datacenter_docs/utils/config.py
Normal file
@@ -0,0 +1,60 @@
|
||||
"""
|
||||
Configuration management using Pydantic Settings
|
||||
"""
|
||||
|
||||
from pydantic_settings import BaseSettings
|
||||
from typing import List
|
||||
from functools import lru_cache
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
"""Application settings"""
|
||||
|
||||
# MongoDB
|
||||
MONGODB_URL: str = "mongodb://admin:password@localhost:27017"
|
||||
MONGODB_DATABASE: str = "datacenter_docs"
|
||||
|
||||
# Redis
|
||||
REDIS_URL: str = "redis://localhost:6379/0"
|
||||
|
||||
# MCP Server
|
||||
MCP_SERVER_URL: str
|
||||
MCP_API_KEY: str
|
||||
|
||||
# Anthropic Claude API
|
||||
ANTHROPIC_API_KEY: str
|
||||
|
||||
# CORS
|
||||
CORS_ORIGINS: List[str] = ["*"]
|
||||
|
||||
# Application
|
||||
LOG_LEVEL: str = "INFO"
|
||||
DEBUG: bool = False
|
||||
|
||||
# API Configuration
|
||||
API_HOST: str = "0.0.0.0"
|
||||
API_PORT: int = 8000
|
||||
WORKERS: int = 4
|
||||
|
||||
# LLM Configuration
|
||||
MAX_TOKENS: int = 4096
|
||||
TEMPERATURE: float = 0.3
|
||||
MODEL: str = "claude-sonnet-4-20250514"
|
||||
|
||||
# Vector Store
|
||||
VECTOR_STORE_PATH: str = "./data/chroma_db"
|
||||
EMBEDDING_MODEL: str = "sentence-transformers/all-MiniLM-L6-v2"
|
||||
|
||||
# Celery
|
||||
CELERY_BROKER_URL: str = "redis://localhost:6379/0"
|
||||
CELERY_RESULT_BACKEND: str = "redis://localhost:6379/0"
|
||||
|
||||
class Config:
|
||||
env_file = ".env"
|
||||
case_sensitive = True
|
||||
|
||||
|
||||
@lru_cache()
|
||||
def get_settings() -> Settings:
|
||||
"""Get cached settings instance"""
|
||||
return Settings()
|
||||
115
src/datacenter_docs/utils/database.py
Normal file
115
src/datacenter_docs/utils/database.py
Normal file
@@ -0,0 +1,115 @@
|
||||
"""
|
||||
MongoDB Database Connection and Utilities
|
||||
"""
|
||||
|
||||
import logging
|
||||
from typing import Optional
|
||||
from motor.motor_asyncio import AsyncIOMotorClient
|
||||
from beanie import init_beanie
|
||||
|
||||
from .api.models import (
|
||||
Ticket,
|
||||
DocumentationSection,
|
||||
ChatSession,
|
||||
SystemMetric,
|
||||
AuditLog
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Database:
|
||||
"""MongoDB Database Manager"""
|
||||
|
||||
client: Optional[AsyncIOMotorClient] = None
|
||||
|
||||
@classmethod
|
||||
async def connect_db(cls, mongodb_url: str, database_name: str = "datacenter_docs"):
|
||||
"""
|
||||
Connect to MongoDB and initialize Beanie
|
||||
|
||||
Args:
|
||||
mongodb_url: MongoDB connection string
|
||||
database_name: Database name
|
||||
"""
|
||||
try:
|
||||
# Create Motor client
|
||||
cls.client = AsyncIOMotorClient(mongodb_url)
|
||||
|
||||
# Test connection
|
||||
await cls.client.admin.command('ping')
|
||||
logger.info(f"Connected to MongoDB at {mongodb_url}")
|
||||
|
||||
# Initialize Beanie with document models
|
||||
await init_beanie(
|
||||
database=cls.client[database_name],
|
||||
document_models=[
|
||||
Ticket,
|
||||
DocumentationSection,
|
||||
ChatSession,
|
||||
SystemMetric,
|
||||
AuditLog
|
||||
]
|
||||
)
|
||||
|
||||
logger.info("Beanie ODM initialized successfully")
|
||||
|
||||
# Create indexes
|
||||
await cls._create_indexes()
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to connect to MongoDB: {e}")
|
||||
raise
|
||||
|
||||
@classmethod
|
||||
async def _create_indexes(cls):
|
||||
"""Create additional indexes if needed"""
|
||||
try:
|
||||
# Beanie creates indexes automatically from model definitions
|
||||
# But we can create additional ones here if needed
|
||||
|
||||
# Text search index for tickets
|
||||
db = cls.client.datacenter_docs
|
||||
await db.tickets.create_index([
|
||||
("title", "text"),
|
||||
("description", "text"),
|
||||
("resolution", "text")
|
||||
])
|
||||
|
||||
logger.info("Additional indexes created")
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to create some indexes: {e}")
|
||||
|
||||
@classmethod
|
||||
async def close_db(cls):
|
||||
"""Close database connection"""
|
||||
if cls.client:
|
||||
cls.client.close()
|
||||
logger.info("MongoDB connection closed")
|
||||
|
||||
|
||||
# Dependency for FastAPI
|
||||
async def get_database():
|
||||
"""
|
||||
FastAPI dependency to get database instance
|
||||
Not needed with Beanie as models are directly accessible
|
||||
"""
|
||||
return Database.client
|
||||
|
||||
|
||||
# Initialize database on startup
|
||||
async def init_db(mongodb_url: str, database_name: str = "datacenter_docs"):
|
||||
"""
|
||||
Initialize database connection
|
||||
|
||||
Usage:
|
||||
await init_db("mongodb://localhost:27017")
|
||||
"""
|
||||
await Database.connect_db(mongodb_url, database_name)
|
||||
|
||||
|
||||
# Close database on shutdown
|
||||
async def close_db():
|
||||
"""Close database connection"""
|
||||
await Database.close_db()
|
||||
Reference in New Issue
Block a user