Skip to main content

Python LLM operations service for the DevLama ecosystem

Project description

getllm

getllm is a Python package for managing LLM models with Ollama integration and generating Python code. It allows you to install, list, set the default model, update the model list, and generate code using LLM models. GetLLM is part of the PyLama ecosystem and integrates with LogLama as the primary service for centralized logging and environment management.

Features

  • Code Generation: Generate Python code using LLM models
  • Model Management: Install, list, and select models
  • Hugging Face Integration: Search and install models from Hugging Face
  • Automatic Model Installation: Automatically install models when they are not found
  • Fallback Mechanisms: Use fallback models when the requested model is not available
  • Environment Configuration: Configure Ollama through environment variables
  • Special Model Handling: Special installation process for SpeakLeash Bielik models
  • Mock Mode: Support for mock mode without requiring Ollama
  • Interactive Mode: Interactive CLI for model selection and code generation
  • Template System: Generate code with awareness of platform, dependencies, and more
  • Code Execution: Execute generated code directly

LogLama Integration

PyLLM integrates with LogLama as the primary service in the PyLama ecosystem. This integration provides:

  • Centralized Environment Management: Environment variables are loaded from the central .env file in the devlama directory
  • Shared Configuration: Model configurations are shared across all PyLama components
  • Dependency Management: Dependencies are validated and installed by LogLama
  • Service Orchestration: Services are started in the correct order using LogLama CLI
  • Centralized Logging: All PyLLM operations are logged to the central LogLama system
  • Structured Logging: Logs include component context for better filtering and analysis
  • Health Monitoring: LogLama monitors PyLLM service health and availability

General Diagram (Mermaid)

graph TD
    A[User] -->|CLI/Interactive| B[getllm/cli.py]
    B --> C[models.py]
    B --> D[interactive_cli.py]
    C --> E[LogLama Central .env]
    C --> F[Ollama API]
    D --> B
    G[LogLama] --> E

ASCII Diagram: CLI Command Flow

User
    |
    v
+-----------------+
|   getllm CLI     |
+-----------------+
    |
    v
+-----------------+
|   models.py     |
+-----------------+
    |
+-----------------+
| LogLama Central |
|    .env File    |
+-----------------+
    |
+-----------------+
|  Ollama API     |
+-----------------+

Usage

Basic Usage

# Generate code using the default model
getllm "create a function to calculate fibonacci numbers"

# Generate and run code
getllm -r "create a web server with Flask"

# Save generated code to a file
getllm -s "create a script to download files from URLs"

# Use a specific model
getllm --model codellama:7b "create a binary search tree implementation"

# Use mock mode (no Ollama required)
getllm --mock "print hello world"

# Use a model that will be automatically installed if not available
getllm --model SpeakLeash/bielik-1.5b-v3.0-instruct-gguf "print hello world"

Model Management

# List available models
getllm list

# Install a model
getllm install codellama:7b

# List installed models
getllm installed

# Set default model
getllm set-default codellama:7b

# Show default model
getllm default

# Update models list from Ollama
getllm update

Hugging Face Integration

# Search for models on Hugging Face
getllm --search bielik

# Update models list from Hugging Face
getllm --update-hf

Interactive Mode

# Start interactive mode
getllm -i

# Start interactive mode with mock implementation
getllm -i --mock

Installation

# Create a virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install the package in development mode
pip install -e .  # This is important! Always install in development mode before starting

IMPORTANT: Always run pip install -e . before starting the project to ensure all dependencies are properly installed and the package is available in development mode.


Using the Makefile

PyLLM includes a Makefile to simplify common development tasks:

# Set up the project (creates a virtual environment and installs dependencies)
make setup

# Run the API server (default port 8001)
make run

# Run the API server on a custom port
make run PORT=8080

# The run-port command is also available for backward compatibility
make run-port PORT=8080

# Run tests
make test

# Format code with black
make format

# Lint code with flake8
make lint

# Clean up project (remove __pycache__, etc.)
make clean

# Show all available commands
make help

Key Files

  • getllm/cli.py – main CLI
  • getllm/interactive_cli.py – interactive shell with menu and cursor selection
  • getllm/models.py – model logic, .env/env.example handling, Ollama integration
  • .env/env.example – environment config and default model

Example Usage

List available models

getllm list

Install a model

getllm install deepseek-coder:6.7b

Set default model

getllm set-default deepseek-coder:6.7b

Show default model

getllm default

Update model list from Ollama

getllm update

Run interactive mode (menu, cursor selection)

getllm -i

set_default_model function flow (Mermaid)

flowchart TD
    S[Start] --> C{Does .env exist?}
    C -- Yes --> R[Update OLLAMA_MODEL in .env]
    C -- No --> K[Copy env.example to .env]
    K --> R
    R --> E[End]

Interactive mode - menu (ASCII)

+--------------------------------+
|  getllm - interactive mode       |
+--------------------------------+
| > List available models         |
|   Show default model           |
|   List installed models        |
|   Install model                |
|   Set default model            |
|   Update model list            |
|   Test default model           |
|   Exit                         |
+--------------------------------+
  (navigation: arrow keys + Enter)

Installation

pip install getllm

Usage

Basic Model Management

from getllm import get_models, get_default_model, set_default_model, install_model

# Get available models
models = get_models()
for model in models:
    print(f"{model['name']} - {model.get('desc', '')}")

# Get the current default model
default_model = get_default_model()
print(f"Current default model: {default_model}")

# Set a new default model
set_default_model("codellama:7b")

# Install a model
install_model("deepseek-coder:6.7b")

Direct Ollama Integration

from getllm import OllamaIntegration, get_ollama_integration, start_ollama_server

# Start the Ollama server if it's not already running
ollama = start_ollama_server()

# Or create an OllamaIntegration instance with a specific model
ollama = get_ollama_integration(model="codellama:7b")

# Check if the model is available
if ollama.check_model_availability():
    print(f"Model {ollama.model} is available")
else:
    print(f"Model {ollama.model} is not available")

    # Install the model
    if ollama.install_model(ollama.model):
        print(f"Successfully installed {ollama.model}")

# List installed models
installed_models = ollama.list_installed_models()
for model in installed_models:
    print(f"Installed model: {model['name']}")

Environment Variables

The package uses the following environment variables for Ollama integration:

  • OLLAMA_PATH: Path to the Ollama executable (default: 'ollama')
  • OLLAMA_MODEL: Default model to use (default: 'codellama:7b')
  • OLLAMA_FALLBACK_MODELS: Comma-separated list of fallback models (default: 'codellama:7b,phi3:latest,tinyllama:latest')
  • OLLAMA_AUTO_SELECT_MODEL: Whether to automatically select an available model if the requested model is not found (default: 'true')
  • OLLAMA_AUTO_INSTALL_MODEL: Whether to automatically install a model when it's not found (default: 'true')
  • OLLAMA_TIMEOUT: API timeout in seconds (default: '30')

These variables can be set in a .env file in the project root directory or in the system environment.

License

This project is licensed under the Apache 2.0 License (see LICENSE file).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

getllm-0.1.16.tar.gz (36.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

getllm-0.1.16-py3-none-any.whl (55.9 kB view details)

Uploaded Python 3

File details

Details for the file getllm-0.1.16.tar.gz.

File metadata

  • Download URL: getllm-0.1.16.tar.gz
  • Upload date:
  • Size: 36.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for getllm-0.1.16.tar.gz
Algorithm Hash digest
SHA256 605b32b9ad117efa926c546caa782076fe19781f4229a32cf2dcc4fc8bf97615
MD5 f954b6946214e5be13fac8e57ad1d6d2
BLAKE2b-256 a8d49c584d58c10b0e0093bfdcd8e2893060bcf3ff90af4adf0b1679fa71b619

See more details on using hashes here.

File details

Details for the file getllm-0.1.16-py3-none-any.whl.

File metadata

  • Download URL: getllm-0.1.16-py3-none-any.whl
  • Upload date:
  • Size: 55.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for getllm-0.1.16-py3-none-any.whl
Algorithm Hash digest
SHA256 b3f1b376cadc7efb377def849153e4be10d6113c7798ee8cc59e470bbed3d8ee
MD5 9b9ef00a5626b9f6bc6fabaff5231e3e
BLAKE2b-256 71fb71d5eb77024c357314f07e3a54d0303637da66444e98e6c9d78a15794db6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page