Main orchestrator class for goLLM functionality.
from gollm import GollmCore
# Initialize with default configuration
gollm = GollmCore()
# Initialize with custom config path
gollm = GollmCore(config_path="path/to/config.json")
validate_file(file_path: str) -> DictValidate a single file against configured rules.
Parameters:
file_path: Path to the file to validateReturns:
{
"valid": bool,
"violations": List[Violation],
"score": float,
"summary": Dict[str, int]
}
validate_project(directory: str = ".") -> DictValidate all Python files in a directory.
Parameters:
directory: Directory path to scan (default: current directory)Returns:
{
"valid": bool,
"files": Dict[str, FileResult],
"summary": Dict[str, int],
"score": float
}
async handle_code_generation(prompt: str, context: Dict = None) -> DictGenerate code using the configured LLM.
Parameters:
prompt: User’s code generation requestcontext: Additional context (optional)Returns:
{
"code": str,
"explanation": str,
"valid": bool,
"score": float
}
Validates Python code against quality rules.
from gollm.validation.validators import CodeValidator
from gollm.config.config import GollmConfig
config = GollmConfig.load()
validator = CodeValidator(config)
validate_file(file_path: str) -> DictValidate a single file.
validate_project(directory: str = ".") -> DictValidate all Python files in a directory.
validate_code(code: str, filename: str = "<string>") -> DictValidate a string containing Python code.
Manages interactions with LLM providers.
from gollm.llm.orchestrator import LLMOrchestrator
from gollm.config.config import GollmConfig
config = GollmConfig.load()
orchestrator = LLMOrchestrator(config)
async generate_code(prompt: str, context: Dict = None) -> DictGenerate code based on the given prompt.
Parameters:
prompt: Code generation promptcontext: Additional context (optional)Returns:
{
"code": str,
"explanation": str,
"metadata": Dict
}
async chat(messages: List[Dict]) -> DictHave a conversation with the LLM.
Parameters:
messages: List of message dictionaries with ‘role’ and ‘content’Returns:
{
"response": str,
"metadata": Dict
}
Utility functions for file operations.
backup_file(file_path: str) -> strCreate a backup of a file.
safe_write(file_path: str, content: str) -> NoneSafely write content to a file with backup.
get_file_hash(file_path: str) -> strCalculate MD5 hash of a file.
Represents a code quality violation.
rule_id: str - Identifier of the violated rulemessage: str - Description of the violationfilename: str - Path to the fileline: int - Line numbercolumn: int - Column numberseverity: str - One of: ‘error’, ‘warning’, ‘info’context: str - Code context around the violationSee Configuration Reference for detailed configuration options.
All API methods raise specific exceptions:
GollmError: Base exception classValidationError: Raised for validation failuresLLMError: Raised for LLM-related errorsConfigError: Raised for configuration issuesExample error handling:
try:
result = gollm.validate_file("myfile.py")
except gollm.ValidationError as e:
print(f"Validation failed: {e}")
except gollm.GollmError as e:
print(f"Error: {e}")
Configure logging using Python’s standard logging module:
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("gollm")