Skip to main content

Local LLM wrapper (import local_llm_wrapper) with a stable text-in text-out API.

Project description

local_llm_wrapper

Local LLM wrapper with a simple, stable text-in text-out API. It supports multiple local backends (for example Ollama and Apple) via pluggable transports, with structured output helpers and robust parsing plus retry for unattended runs.

Package name: local-llm-wrapper (import as local_llm_wrapper).

Overview

  • Library-first wrapper for local text models with a small, stable API.
  • Fallback across transports when a backend is unavailable.
  • Structured helpers for rename/sort workflows with strict parsing and format-fix retries.

Features

  • Pluggable transports in local_llm_wrapper/transports/.
  • Fallback chain in LLMClient with guardrail and context-window handling.
  • Structured prompts and parsers for rename, keep, and sort workflows.
  • Prompt sanitization and output normalization utilities.
  • Quiet mode for non-verbose runs.
  • Unified API for text prompts and chat-style message lists.

Quick start

import local_llm_wrapper.llm as llm

client = llm.LLMClient(
	transports=[
		llm.AppleTransport(),
		llm.OllamaTransport(model=llm.choose_model(None)),
	],
	quiet=True,
)

response = client.generate("Say hello in one sentence.", max_tokens=120)
print(response)

Chat example

import local_llm_wrapper.llm as llm

client = llm.LLMClient(
	transports=[llm.OllamaTransport(model="llama3.2:3b-instruct-q5_K_M")],
	quiet=True,
)
messages = [
	{"role": "system", "content": "Answer in one sentence."},
	{"role": "user", "content": "What is a mutex?"},
]
print(client.generate(messages=messages, max_tokens=120))

CLI example

source source_me.sh && python3 llm_generate.py -p "Say hello in one sentence." -t 80

CLI usage

llm_generate.py is a repo-root helper for quick prompt tests against the Ollama transport.

source source_me.sh && python3 llm_generate.py --help

Options:

  • -p, --prompt: Prompt text to send (default: "Say hello in one sentence.").
  • -m, --model: Override the auto-selected model (default: auto).
  • -t, --max-tokens: Maximum tokens to generate (default: 80).
  • -q, --quiet: Suppress progress output (default).
  • -v, --verbose: Show progress output.

CLI chat demo

llm_chat.py is an interactive chat loop that uses chat-style messages.

source source_me.sh && python3 llm_chat.py

Options:

  • -m, --model: Override the auto-selected model (default: auto).
  • -s, --system: Optional system message to start the chat.
  • -t, --max-tokens: Maximum tokens to generate per response (default: 240).
  • -q, --quiet: Suppress progress output (default).
  • -v, --verbose: Show progress output.

XML tag demo

llm_xml_demo.py requests a tagged response and extracts <answer> from the model output.

source source_me.sh && python3 llm_xml_demo.py -p "Say hello in one sentence."

Structured helpers

The engine includes structured helpers for common file-organization tasks.

import local_llm_wrapper.llm as llm

client = llm.LLMClient(transports=[llm.OllamaTransport(model="llama3.2:3b-instruct-q5_K_M")])
item = {
	"path": "notes.txt",
	"name": "notes",
	"ext": "txt",
	"description": "meeting notes",
}
result = client.sort([item])
print(result.assignments)

Transports

  • Apple: local_llm_wrapper/transports/apple.py.
  • Ollama: local_llm_wrapper/transports/ollama.py.
  • Protocol: local_llm_wrapper/transports/base.py.

Errors

Standardized exception types live in local_llm_wrapper/errors.py so callers can handle guardrails, context window errors, and transport availability consistently.

Testing

source source_me.sh && python3 -m pytest tests/

Docs

Notes

  • This repo is text-only; image or OCR workflows belong elsewhere.
  • Configuration is explicit through arguments or config objects, not custom environment variables.

Project details


Release history Release notifications | RSS feed

This version

26.4

Download files

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

Source Distribution

local_llm_wrapper-26.4.tar.gz (110.6 kB view details)

Uploaded Source

Built Distribution

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

local_llm_wrapper-26.4-py3-none-any.whl (43.9 kB view details)

Uploaded Python 3

File details

Details for the file local_llm_wrapper-26.4.tar.gz.

File metadata

  • Download URL: local_llm_wrapper-26.4.tar.gz
  • Upload date:
  • Size: 110.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for local_llm_wrapper-26.4.tar.gz
Algorithm Hash digest
SHA256 42505ba7d835e3b53c216f6ebb660ada907185a6e632229cf4f4867af242d4a4
MD5 2d500b689b549df47cd157af724e0021
BLAKE2b-256 b8eb355dfb610034fc1c7b5676faf3b3e14f3d3dd34962d5c23b6809cbbdc94c

See more details on using hashes here.

File details

Details for the file local_llm_wrapper-26.4-py3-none-any.whl.

File metadata

File hashes

Hashes for local_llm_wrapper-26.4-py3-none-any.whl
Algorithm Hash digest
SHA256 91d005b6e56e09753ffec61c5c0091cbe7c9cb8c03c5eb41bc42bb755cc134ff
MD5 b5ee110291635ca8d5ed963133d2f14f
BLAKE2b-256 362d8c4906c1e7ba1ef6120104a06e49d54532acdbc3264b695d1c4c317f576a

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