Usage#

ML Research Tools provides a command-line interface for accessing various tools. This guide covers basic usage patterns and common examples.

Command-Line Interface#

The package provides a single command-line entry point ml_research_tools with subcommands for each tool:

ml_research_tools [global options] <tool-name> [tool options]
Usage: ml_research_tools [-h] [--config CONFIG]
                         [--log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL}]
                         [--log-file LOG_FILE] [-v] [--redis-host REDIS_HOST]
                         [--redis-port REDIS_PORT] [--redis-db REDIS_DB]
                         [--redis-password REDIS_PASSWORD] [--redis-disable]
                         [--redis-recache] [--llm-preset LLM_PRESET]
                         [--llm-tier LLM_TIER] [--llm-api-key LLM_API_KEY]
                         [--llm-base-url LLM_BASE_URL] [--llm-model LLM_MODEL]
                         [--llm-max-tokens LLM_MAX_TOKENS]
                         [--llm-temperature LLM_TEMPERATURE]
                         [--llm-top-p LLM_TOP_P]
                         [--llm-retry-attempts LLM_RETRY_ATTEMPTS]
                         [--llm-retry-delay LLM_RETRY_DELAY] [--list-presets]
                         [--list-tools]
                         [--rich-capture-output RICH_CAPTURE_OUTPUT]
                         {help,ask-document,wandb-downloader,kube-pod-forward,latex-grammar}
                         ...

ML Research Tools - A collection of utilities for ML research

Options:
  -h, --help            show this help message and exit
  --list-presets        List available LLM presets and exit
  --list-tools          List available tools and exit
  --rich-capture-output RICH_CAPTURE_OUTPUT
                        Capture output in a rich format to this file

Configuration:
  --config CONFIG       Path to configuration file (default:
                        ~/.config/ml_research_tools/config.yaml)

Logging:
  --log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL}
                        Logging level
  --log-file LOG_FILE   Path to log file
  -v, --verbose         Enable verbose logging

Redis:
  --redis-host REDIS_HOST
                        Redis host
  --redis-port REDIS_PORT
                        Redis port
  --redis-db REDIS_DB   Redis database number
  --redis-password REDIS_PASSWORD
                        Redis password
  --redis-disable       Disable Redis caching
  --redis-recache       Disable Redis caching retrieval, but allow saving

Llm:
  --llm-preset LLM_PRESET
                        LLM preset name to use (e.g., 'standard', 'premium')
  --llm-tier LLM_TIER   LLM tier to use (e.g., 'standard', 'premium')
  --llm-api-key LLM_API_KEY
                        API key for LLM service
  --llm-base-url LLM_BASE_URL
                        Base URL for the LLM API endpoint
  --llm-model LLM_MODEL
                        LLM model to use
  --llm-max-tokens LLM_MAX_TOKENS
                        Maximum tokens for LLM response
  --llm-temperature LLM_TEMPERATURE
                        Temperature for LLM sampling
  --llm-top-p LLM_TOP_P
                        Top-p value for LLM sampling
  --llm-retry-attempts LLM_RETRY_ATTEMPTS
                        Number of retry attempts for LLM API calls
  --llm-retry-delay LLM_RETRY_DELAY
                        Delay between retry attempts for LLM API calls
                        (seconds)

Tools:
  {help,ask-document,wandb-downloader,kube-pod-forward,latex-grammar}
                        Available tools
    help                Display help information about available tools
    ask-document        Interactive chat with document content using LLMs
    wandb-downloader    Download artifacts and runs from Weights & Biases
    kube-pod-forward    Forward port to a Kubernetes pod with a specific name
                        pattern.
    latex-grammar       Check and improve LaTeX grammar and style with LLM

Available Tools#

The toolkit includes the following tools:

LaTeX Grammar Tool#

Check and improve grammar in LaTeX documents:

ml_research_tools latex-grammar paper.tex --output-file improved_paper.tex

Ask Document Tool#

Chat with document content using LLMs:

ml_research_tools ask-document research_paper.pdf

W&B Downloader Tool#

Download Weights & Biases run logs:

ml_research_tools wandb-downloader --entity myuser --project myproject

Kubernetes Pod Forward Tool#

Forward ports to Kubernetes pods:

ml_research_tools kube-pod-forward --namespace default web-app

Scripting#

ML Research Tools can be used programmatically in Python scripts:

from ml_research_tools.tex import LatexGrammarTool
from ml_research_tools.core.config import Config
from ml_research_tools.core.service_provider import ServiceProvider
from ml_research_tools.core.service_factories import register_common_services

# Create configuration
config = Config.from_dict({
    "llm": {
        "default": "standard",
        "presets": {
            "standard": {
                "api_key": "your-api-key",
                "model": "gpt-3.5-turbo",
                "tier": "standard"
            }
        }
    }
})

# Create service provider
services = ServiceProvider(config)
register_common_services(services)

# Initialize the tool
tool = LatexGrammarTool(services)

# Create args object with required parameters
class Args:
    pass

args = Args()
args.input_file = "paper.tex"
args.output_file = "improved_paper.tex"

# Execute the tool
tool.execute(config, args)

Getting Help#

To see a list of available tools:

ml_research_tools --list-tools

To get help for a specific tool:

ml_research_tools TOOL --help

# For example:
ml_research_tools latex-grammar --help

LLM Features#

The tools that use LLM capabilities support selecting different models:

# Use a specific preset
ml_research_tools --llm-preset=premium latex-grammar paper.tex

# Use a specific tier
ml_research_tools  --llm-tier=standard latex-grammar paper.tex

To list available LLM presets:

ml_research_tools --list-presets

Using Redis Caching#

Many tools support Redis caching to speed up repeated operations:

# Enable Redis caching
ml_research_tools --redis-host=localhost --redis-port=6379 latex-grammar paper.tex

# Disable Redis caching
ml_research_tools --redis-disable latex-grammar paper.tex

Python API#

You can also use ML Research Tools directly in your Python code:

from ml_research_tools.core.config import Config
from ml_research_tools.core.service_provider import ServiceProvider
from ml_research_tools.core.service_factories import register_common_services
from ml_research_tools.tex import LatexGrammarTool

# Load configuration
config = Config.from_dict({
    "llm": {
        "default": "standard",
        "presets": {
            "standard": {
                "model": "gpt-3.5-turbo",
                "api_key": "your-api-key",
                "tier": "standard"
            }
        }
    }
})

# Set up services
services = ServiceProvider(config)
register_common_services(services)

# Create tool instance
tool = LatexGrammarTool(services)

# Execute the tool
exit_code = tool.execute(config, args)

For more detailed examples, see the individual tool documentation pages.