Spaces:
Sleeping
Sleeping
Create shared/config.py
Browse files- shared/config.py +63 -0
shared/config.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Configuration for Gradio + MCP Linux administration system.
|
| 3 |
+
Simplified for Gradio's built-in MCP support.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
from typing import List
|
| 8 |
+
from dataclasses import dataclass
|
| 9 |
+
|
| 10 |
+
@dataclass
|
| 11 |
+
class OpenAIConfig:
|
| 12 |
+
"""OpenAI API configuration"""
|
| 13 |
+
api_key: str
|
| 14 |
+
model: str = "gpt-4o-mini"
|
| 15 |
+
temperature: float = 0.7
|
| 16 |
+
max_tokens: int = 1000
|
| 17 |
+
|
| 18 |
+
@classmethod
|
| 19 |
+
def from_env(cls) -> 'OpenAIConfig':
|
| 20 |
+
api_key = os.getenv('OPENAI_API_KEY')
|
| 21 |
+
if not api_key:
|
| 22 |
+
raise ValueError("OPENAI_API_KEY environment variable is required")
|
| 23 |
+
return cls(api_key=api_key)
|
| 24 |
+
|
| 25 |
+
@dataclass
|
| 26 |
+
class SecurityConfig:
|
| 27 |
+
"""Security settings for command execution"""
|
| 28 |
+
# Whitelist of safe commands
|
| 29 |
+
safe_commands: List[str] = None
|
| 30 |
+
|
| 31 |
+
# Maximum command timeout (seconds)
|
| 32 |
+
command_timeout: int = 30
|
| 33 |
+
|
| 34 |
+
def __post_init__(self):
|
| 35 |
+
if self.safe_commands is None:
|
| 36 |
+
self.safe_commands = [
|
| 37 |
+
"ls", "df", "cat", "ps", "whoami", "pwd", "date",
|
| 38 |
+
"uptime", "free", "top", "netstat", "ss",
|
| 39 |
+
"tail", "head", "grep", "find", "which"
|
| 40 |
+
]
|
| 41 |
+
|
| 42 |
+
@dataclass
|
| 43 |
+
class GradioConfig:
|
| 44 |
+
"""Gradio interface configuration"""
|
| 45 |
+
title: str = "Linux MCP Administration"
|
| 46 |
+
description: str = "AI-powered Linux system administration with MCP tools"
|
| 47 |
+
theme: str = "soft"
|
| 48 |
+
share: bool = False
|
| 49 |
+
|
| 50 |
+
# Chat interface settings
|
| 51 |
+
chatbot_height: int = 600
|
| 52 |
+
textbox_placeholder: str = "Ask me about Linux administration..."
|
| 53 |
+
|
| 54 |
+
class Config:
|
| 55 |
+
"""Main configuration class"""
|
| 56 |
+
|
| 57 |
+
def __init__(self):
|
| 58 |
+
self.openai = OpenAIConfig.from_env()
|
| 59 |
+
self.security = SecurityConfig()
|
| 60 |
+
self.gradio = GradioConfig()
|
| 61 |
+
|
| 62 |
+
# Global config instance
|
| 63 |
+
config = Config()
|