gollm.mainMain entry point for the goLLM application.
main()Main entry point that parses command line arguments and executes the appropriate command.
gollm.llm.orchestratorOrchestrates LLM operations and manages the execution flow.
LLMOrchestratorMain class that handles LLM orchestration.
class LLMOrchestrator:
def __init__(self, config: Optional[Dict] = None):
"""Initialize the LLM orchestrator with optional configuration."""
def handle_code_generation_request(
self,
prompt: str,
context: Optional[Dict] = None,
validate: bool = True
) -> str:
"""Handle a code generation request.
Args:
prompt: The prompt for code generation
context: Optional context for the generation
validate: Whether to validate the generated code
Returns:
Generated code as a string
"""
gollm generate <prompt>Generate code from a natural language prompt.
Options:
--fast: Skip validation (faster but less reliable)--adapter-type: Choose adapter type (modular, http)--output: Output file pathExample:
gollm generate "Create a Python class for a user with name and email"
gollm validate <path>Validate code at the given path.
Options:
--rules: Comma-separated list of rules to apply--fix: Automatically fix issues when possible--format: Format the codeExample:
gollm validate src/ --rules=pep8,security --fix
gollm initInitialize a new goLLM project.
gollm statusShow project status and metrics.
goLLM can be configured using a gollm.json file in your project root:
{
"validation": {
"enabled": true,
"rules": ["pep8", "security"],
"ignore": ["tests/*", "migrations/*"]
},
"generation": {
"default_adapter": "modular",
"validate_output": true,
"temperature": 0.7,
"max_tokens": 2000
},
"model": {
"name": "gpt-4",
"api_key": "${GOLLM_API_KEY}"
}
}
goLLM uses custom exceptions for error handling:
gollm.exceptions.GollmErrorBase exception class for all goLLM exceptions.
gollm.exceptions.ValidationErrorRaised when code validation fails.
gollm.exceptions.GenerationErrorRaised when code generation fails.
gollm.utils.file_utilsread_file(path: str) -> strRead a file and return its contents.
write_file(path: str, content: str) -> NoneWrite content to a file.
gollm.utils.string_utilssanitize_input(text: str) -> strSanitize user input to prevent injection attacks.
Create a new validator by subclassing gollm.validation.CodeValidator:
from gollm.validation import CodeValidator
class MyCustomValidator(CodeValidator):
def validate(self, code: str) -> List[ValidationResult]:
# Your validation logic here
pass
Create a new adapter by implementing the LLMAdapter interface:
from typing import Dict, Any
from gollm.llm.base import LLMAdapter
class MyCustomAdapter(LLMAdapter):
def __init__(self, config: Dict[str, Any]):
self.config = config
def generate(self, prompt: str, **kwargs) -> str:
# Your generation logic here
pass
# Run all tests
pytest
# Run tests with coverage
pytest --cov=gollm
Tests should be placed in the tests/ directory and follow the pattern test_*.py.
Example test file:
def test_my_feature():
# Test setup
# Test execution
# Assertions
pass
See Contributing Guide for details on how to contribute to goLLM.