Skip to content

feat: incorporation of Llmfit tool in to cli

Bhaskar Battula requested to merge llmfit into develop

What is this MR?

This merge request introduces a comprehensive integration of the LLMFit tool into corpus-client-cli. It expands the CLI with capabilities for model recommendation, download, and execution, while maintaining a modular and self-contained design.


What does it do?

  • Enables system-aware LLM model recommendations
  • Supports model download and lifecycle management
  • Allows users to run downloaded LLMs locally
  • Adds self-healing dependency handling for missing binaries
  • Extends CLI functionality with new commands
  • Introduces persistent state for model selection
  • Provides full test coverage and documentation

Changes Included

1. New Core Logic Module (src/corpus_client_cli/llmfit.py)

  • Command Bridge
    • Implemented run_llmfit_command to execute llmfit via system binary or fallback to uv tool run
  • System Analysis
    • Added get_system_info to detect CPU, GPU, and RAM for model filtering
  • Model Discovery
    • Implemented get_recommended_models to fetch and parse model metadata from backend
  • Download & Lifecycle
    • Added download_model with GGUF resolution and storage handling
  • LLM Execution
    • Added llmfit_run_command to manage symlinks and run models
  • Dependency Self-Healing
    • Automatically downloads required llama-cli binaries if missing

2. State & Storage Updates (src/corpus_client_cli/state.py)

  • Defined MODELS_DIR (~/.corpus-cli/models) for centralized model storage
  • Extended State class to persist:
    • llmfit_choice
    • llmfit_resolved_id

3. CLI Command Registration (src/corpus_client_cli/cli.py)

  • Added new commands:
    • corpus-client llm manage → Analyze system and list compatible models
    • corpus-client llm run → Execute a selected model
  • Enhanced clear command:
    • Recursively deletes the models/ directory to reset local cache

4. Testing Infrastructure (tests/test_llmfit.py)

  • Built comprehensive test suite using unittest.mock
  • Simulated:
    • Hardware environments
    • LLMFit backend JSON responses
  • Added fixtures:
    • mock_binaries
    • mock_llmfit_recommend
  • Covered:
    • Model recommendation flow
    • Download and resolution logic
    • Execution and symlink behavior

5. Documentation

  • Added usage documentation under docs/
  • Includes:
    • System analysis instructions
    • Model selection guidance
    • Running LLMs locally

Acceptance Criteria

  • Users can run corpus-client llmfit to see recommended models
  • Users can download models with proper GGUF resolution
  • Users can execute models via corpus-client llm-run
  • CLI handles missing dependencies automatically
  • No regressions in existing CLI functionality
  • All tests pass successfully
  • Documentation is clear and complete

Test Coverage

  • Unit tests cover:
    • System detection logic
    • Model recommendation parsing
    • Download and file resolution
    • Execution flow and symlink handling
  • Uses mocks to isolate:
    • Filesystem interactions
    • External binary dependencies
    • Backend API responses
  • Ensures deterministic and environment-independent test execution

Design Notes

This integration is intentionally modular:

  • All LLM-specific logic is isolated within llmfit.py
  • Core CLI remains clean and maintainable
  • External dependencies are abstracted and handled gracefully

Closes: #42 (closed)

Edited by Bhaskar Battula

Merge request reports

Loading