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)

For local development setup, see docs/setup_guide.md.

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.5.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.5-py3-none-any.whl (109.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nerif-1.3.5.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.5.tar.gz
Algorithm Hash digest
SHA256 08c740aa04831446e7ccb9f928a321512a938deddafaf17cc1032aaf10d1d1eb
MD5 f2e8eba5f86bbe5198705692882e235a
BLAKE2b-256 20e9fb10f0edaa58c7be50182d630b98fa9152d758f19c2c12b6fdbe110bffea

See more details on using hashes here.

Provenance

The following attestation bundles were made for nerif-1.3.5.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.5-py3-none-any.whl.

File metadata

  • Download URL: nerif-1.3.5-py3-none-any.whl
  • Upload date:
  • Size: 109.2 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 3e61171d91a0fba27c5e729b060fc605a8bfb61520dfe3beaa779bef50dedec8
MD5 eab8760d368fae551233c0a1a17c6c59
BLAKE2b-256 a318b829cf8af138d9122255a60b0d209508e2e852e71fb9ea21c2d79fd6d9a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for nerif-1.3.5-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