Skip to main content

A shared library for common utilities.

Project description

Nitro

A shared library for common utilities, including LLM management.

Installation

pip install nitrotools

For LLM functionality with LangChain and OpenAI support:

pip install nitrotools[llm]

Usage

Core Utilities

from nitro.core import hello

print(hello())

LLM Management

Nitro provides a configurable LLM factory for easy integration with multiple providers.

Setup

  1. Copy the sample config and customize it:
cp /path/to/site-packages/nitro/llm_config.yaml.sample llm_config.yaml
# Or create llm_config.yaml in your project root (or set NITRO_CONFIG_PATH env var)

Example llm_config.yaml:

servers:
  llamacpp:
    - endpoint: "http://your-llamacpp-server:11435"
      interface: "langchain"
      models:
        - name: "qwen"
          model_name: "gpt-oss-20b-Q6_K.gguf"
          temperature: 0.7
          max_tokens: 1000
  openrouter:
    endpoint: "https://openrouter.ai/api/v1"
    api_key: "${OPENROUTER_API_KEY}"
    interface: "openai_compatible"
    headers:
      HTTP-Referer: "${OPENROUTER_HTTP_REFERER}"
      X-Title: "${OPENROUTER_X_TITLE}"
    models:
      - name: "grok-fast-free"
        model: "x-ai/grok-4-fast:free"
        temperature: 0.3
        max_tokens: 1000
      - name: "nemotron-nano-free"
        model: "nvidia/nemotron-nano-9b-v2:free"
        temperature: 0.1
        max_tokens: 1500

purposes:
  general: "llamacpp:qwen"
  coding: "llamacpp:qwen"
  reasoning: "openrouter:grok-fast-free"
  analysis: "openrouter:nemotron-nano-free"
  assistant: "openrouter:grok-fast-free"
  1. Set environment variables in .env:
OPENROUTER_API_KEY=your_key_here
OPENROUTER_HTTP_REFERER=https://your-site.com
OPENROUTER_X_TITLE=Your App
LLAMACPP_BASE_URL=http://localhost:11435

Basic Usage

from nitro import get_llm

# Get LLM for a purpose
llm = get_llm("coding")

# Generate text
response = llm.generate([
    {"role": "user", "content": "Write a Python function to reverse a string."}
])
print(response)

# Full chat response
full_response = llm.chat([
    {"role": "user", "content": "Explain recursion."}
])
print(full_response)  # Raw response object

Advanced Usage

from nitro import LLMFactory

factory = LLMFactory()

# Health check
status = factory.health_check()
print(status)  # {'general': '✅ llamacpp:qwen', ...}

# Direct factory usage
llm = factory.get_llm("assistant")

Testing with Real LLMs

To run integration tests with real endpoints:

  1. Set credentials in .env as above.
  2. Run tests: pytest tests/test_llm.py::TestLLMIntegration -v

Tests will skip if credentials are not provided.

Contributing

Contributions are welcome!

License

MIT

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

nitrotools-0.1.1.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

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

nitrotools-0.1.1-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file nitrotools-0.1.1.tar.gz.

File metadata

  • Download URL: nitrotools-0.1.1.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.22

File hashes

Hashes for nitrotools-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3f4a087c581146f7e22d94dabadb893efefb66c3eb6510e891698fe59da76dba
MD5 7949b741ae64721842052af1e4ab51d6
BLAKE2b-256 b3a7f524528b3773a017901761848ab955b14e52ddbed1eefd2cda71a6c02481

See more details on using hashes here.

File details

Details for the file nitrotools-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: nitrotools-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.22

File hashes

Hashes for nitrotools-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 513122e18ebdf77cc603b7ccbd8deec7051012cf67bb688b3eb9dd4aadb34117
MD5 f11bdacb5d9466e597c82163631618ba
BLAKE2b-256 5d3aec6273e24b7d13effe9086b373e2a9cde68b37aea91c0dd1abc0515f90b7

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