Skip to main content

LLM powered Python

Project description

Nerif

Program with both Python and Natural Language.

LLMs can be tricky to work with. They sometimes give overly formal responses or get confused when they're unsure, making them challenging to use in real applications.

That's why we built Nerif - a simple tool that connects LLMs with Python code. We want to make it better than existing tools like Langchain and Dify.

Nerif helps you:

  • Control exactly how LLMs work in your code
  • Convert LLM responses into usable data formats
  • Track performance with metrics like cost and success rate

Our goal is to make LLMs easier to use for developers, turning complex AI capabilities into practical programming tools.

How to install

Pre-requisite

  • Python >= 3.10
  • Environment variable OPENAI_API_KEY or other LLM API keys, for more details, see here
  • Set default model and embedding model with NERIF_DEFAULT_LLM_MODEL and NERIF_DEFAULT_EMBEDDING_MODEL, for more details, see here

Example:

export OPENAI_API_KEY=`your_api_key`
export NERIF_DEFAULT_LLM_MODEL=gpt-4o
export NERIF_DEFAULT_EMBEDDING_MODEL=text-embedding-3-small

Install

pip install nerif

Optional feature groups:

pip install "nerif[rag]"      # NumPy vector store for RAG
pip install "nerif[img-gen]"   # Image generation (Pillow)

QuickStart

from nerif.core import nerif
from nerif.model import SimpleChatModel

model = SimpleChatModel()
# Default model is `gpt-4o`

# Use nerif judge "natural language statement"
if nerif("the sky is blue"):
    print("True")
else:
    # Call a simple model
    print("No", end=", ")
    print(model.chat("what is the color of the sky?"))

Changelog

v1.3.0

  • Async agent: NerifAgent.arun() with concurrent tool execution
  • Model fallback chain: automatic failover on transient errors
  • Callback/hook system: 7 event types for observability
  • PromptTemplate: variable substitution, defaults, conditional sections
  • Rate limiting: per-model/provider request throttling
  • Enhanced ASR: Transcriber with language/format/translate support
  • Enhanced TTS: Synthesizer with voice/speed/format/file output
  • Streaming now supports token counting and retry

v1.2.0

  • ConversationMemory: sliding window with auto-summarization
  • NerifTokenCounter: latency, cost, success rate tracking
  • Lightweight RAG with NumpyVectorStore
  • Custom exception hierarchy (NerifError, ProviderError, etc.)
  • CLI tools: nerif check, nerif test-model, nerif models

v1.1.0

  • Streaming and async support (stream_chat, achat)
  • Pydantic structured output (response_model=)
  • Retry with exponential backoff (RetryConfig)
  • Optional embedding model
  • Multi-provider routing (OpenAI, Anthropic, Gemini, Ollama, etc.)

Documentation

More detailed documentation is on the official website.

License

Nerif is licensed under the GNU General Public License v3.0.

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

nerif-1.3.1.tar.gz (7.6 MB view details)

Uploaded Source

Built Distribution

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

nerif-1.3.1-py3-none-any.whl (101.0 kB view details)

Uploaded Python 3

File details

Details for the file nerif-1.3.1.tar.gz.

File metadata

  • Download URL: nerif-1.3.1.tar.gz
  • Upload date:
  • Size: 7.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nerif-1.3.1.tar.gz
Algorithm Hash digest
SHA256 b3f23f5857bce6a6a4476cc1aced9998c6b454249c02c8b73ce5df0c78e6604c
MD5 213a932591cb0ddc36f508c01a7feae0
BLAKE2b-256 c63db4c119e091c90817b878e25efd3ea35fa2091be6d8068360576a40ac7370

See more details on using hashes here.

Provenance

The following attestation bundles were made for nerif-1.3.1.tar.gz:

Publisher: release.yml on Nerif-AI/Nerif

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nerif-1.3.1-py3-none-any.whl.

File metadata

  • Download URL: nerif-1.3.1-py3-none-any.whl
  • Upload date:
  • Size: 101.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nerif-1.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 557ee5140927280d42952bda7ee97420a71c57b8456dca9e087984584800ffa0
MD5 c4cc143e15d8c6bd152d5afccddb1763
BLAKE2b-256 98045464425331ae1271cd29038f3f2693012bf175e377cc568bee63de9d98fc

See more details on using hashes here.

Provenance

The following attestation bundles were made for nerif-1.3.1-py3-none-any.whl:

Publisher: release.yml on Nerif-AI/Nerif

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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