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.9
  • 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[img-gen]"
pip install "nerif[asr]"
pip install "nerif[tts]"
pip install "nerif[pydantic]"

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?"))

v1.1 Features

Streaming

from nerif.model import SimpleChatModel

model = SimpleChatModel()
for chunk in model.stream_chat("Tell me a story"):
    print(chunk, end="", flush=True)

Async Support

import asyncio
from nerif.model import SimpleChatModel

async def main():
    model = SimpleChatModel()
    result = await model.achat("Hello!")
    print(result)

asyncio.run(main())

Pydantic Structured Output

from pydantic import BaseModel
from nerif.model import SimpleChatModel

class City(BaseModel):
    name: str
    country: str
    population: int

model = SimpleChatModel()
city = model.chat("Tell me about Tokyo.", response_model=City)
print(f"{city.name}: {city.population:,}")

Retry Configuration

from nerif.model import SimpleChatModel
from nerif.utils import RetryConfig

model = SimpleChatModel(retry_config=RetryConfig(max_retries=5))

Optional Embedding

from nerif.core import Nerif

# Works without embedding model
judge = Nerif(model="gpt-4o", embed_model=None)
result = judge.judge("the sky is blue")

v1.2.0 Features

Conversation Memory

Sliding window and token-based context management with auto-summarization and persistence.

Enhanced Observability

Latency tracking, cost calculation, success/failure rates, and callback hooks via NerifTokenCounter.

Lightweight RAG

Abstract vector store interface with built-in NumPy implementation for retrieval-augmented generation.

Custom Exceptions

Structured error hierarchy: NerifError, ProviderError, FormatError, ConfigError.

CLI Tools

nerif check        # Verify environment and API keys
nerif test-model   # Test model connectivity
nerif models       # List available models

Type Hints

py.typed marker included for full IDE and mypy support.

Installation

pip install nerif           # Core features
pip install nerif[pydantic] # + Pydantic structured output

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.2.0.tar.gz (7.5 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.2.0-py3-none-any.whl (91.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for nerif-1.2.0.tar.gz
Algorithm Hash digest
SHA256 afa98306008ddf0ff778108cf191eb8e4f19e8e553cb6e518afc287914723a05
MD5 a78028c236026b50fb6a466d676eae43
BLAKE2b-256 dc6cbf70bd260518be2c92952568e0c8684ba1e2193cc5b377b6cedabefa84a9

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: nerif-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 91.1 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 060a620b2680f08f5f376597917f0ef990660fc5913f8d90296cfb2c414561f7
MD5 baf859ada7d0d9d6553b00afc76cac11
BLAKE2b-256 956093476f7e2253585eb92e014072d8853b97fcd8ea4a51c82cda9325bc6b82

See more details on using hashes here.

Provenance

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