API Overview#

ML Research Tools provides a Python API for all functionality available through the command line. This section documents the important classes and functions available for use in your own Python code.

Key Components#

Core#

The core module provides the foundation of the ML Research Tools package:

  • Config - Configuration management

  • ServiceProvider - Service dependency injection system

  • BaseTool - Base class for all tools

  • LLMClient - Client for LLM API interaction

Cache#

The cache module provides utilities for caching function results:

  • RedisCache - Redis-based caching implementation

  • cached() - Decorator for caching function results

Tools#

Various tool implementations for specific tasks:

  • ml_research_tools.tex.LatexGrammarTool - LaTeX grammar checking

  • ml_research_tools.doc.AskDocumentTool - Document question answering

  • ml_research_tools.exp.WandbDownloaderTool - Weights & Biases run logs downloader

  • ml_research_tools.kube.PodForwardTool - Kubernetes pod port forwarding

Service Locator Pattern#

ML Research Tools uses a service locator pattern for dependency injection. The typical usage flow is:

  1. Create a configuration object:

    from ml_research_tools.core.config import Config
    
    config = Config.from_dict({
        "llm": {
            "default": "standard",
            "presets": {
                "standard": {
                    "model": "gpt-3.5-turbo",
                    "api_key": "your-api-key",
                    "tier": "standard"
                }
            }
        }
    })
    
  2. Set up the service provider:

    from ml_research_tools.core.service_provider import ServiceProvider
    from ml_research_tools.core.service_factories import register_common_services
    
    services = ServiceProvider(config)
    register_common_services(services)
    
  3. Create a tool instance with the service provider:

    from ml_research_tools.tex import LatexGrammarTool
    tool = LatexGrammarTool(services)
    
  4. Execute the tool:

    import argparse
    args = argparse.Namespace(input_file="paper.tex", output="improved.tex")
    tool.execute(config, args)
    

Package Structure#

The package is organized into several modules:

  • ml_research_tools.core - Core functionality

  • ml_research_tools.cache - Caching system

  • ml_research_tools.tex - LaTeX processing tools

  • ml_research_tools.doc - Document processing tools

  • ml_research_tools.exp - Experiment management tools

  • ml_research_tools.kube - Kubernetes tools