Skip to main content

AI-powered natural language to REST API translation. LLM tool calling (OpenAI default, Anthropic optional), zero hardcoding.

Project description

Enable AI

Natural language to REST API translation using LLM tool calling.

Zero hardcoding - works with any OpenAPI spec. Parent module provides all configuration.

Installation

pip install enable-ai

# For Anthropic/Claude support:
pip install enable-ai[anthropic]

Quick Start

from enable_ai_v2 import Orchestrator, Config, JWTAuth

config = Config(
    openapi_schema="path/to/openapi.json",  # or dict
    base_url="https://api.example.com",
    # llm_provider="openai",  # default
    # llm_provider="anthropic",  # optional
)

ai = Orchestrator(
    config=config,
    auth=JWTAuth(token="your-jwt-token"),
)

result = ai.process("show all pending orders")
print(result.message)

Features

  • LLM tool calling - OpenAPI spec converted to LLM tools (OpenAI default, Anthropic optional)
  • Server-side scoping - doesn't inject user filters; server's get_queryset() handles permissions
  • Resource hints - status values, enums from your API for better accuracy
  • Status synonyms - map natural language ("pending") to actual values ("DRAFT")
  • Query caching - exact match + pattern match for fast repeat queries
  • Progress tracking - real-time callbacks for UI updates

Configuration

Parent module provides everything:

from enable_ai_v2 import (
    Config,
    ResourceHint,
    UserContext,
    build_resource_hints_from_api,
    build_status_synonyms,
)

# Fetch from your APIs (parent module's responsibility)
openapi_schema = your_api.get_schema()
statuses = your_api.get_service_order_statuses()
priorities = your_api.get_service_order_priorities()

config = Config(
    # Required
    openapi_schema=openapi_schema,
    base_url="https://api.example.com",

    # Recommended (for accuracy)
    resource_hints=build_resource_hints_from_api(
        openapi_schema,
        statuses,
        priorities,
    ),
    status_synonyms=build_status_synonyms(statuses),

    # Optional
    # Optional
    model="gpt-4o",  # default; or "claude-sonnet-4-20250514" with llm_provider="anthropic"
    temperature=0.0,
    cache_enabled=True,
    include_trace=False,  # True for debugging
)

User Context

Parent module provides user context (doesn't fetch from APIs):

from enable_ai_v2 import UserContext

user_ctx = UserContext(
    user_id=123,
    username="john.doe",
    role="Technician",
    company_id=456,
    is_admin=False,
)

result = ai.process("show my orders", user_context=user_ctx)

Authentication

from enable_ai_v2 import JWTAuth, APIKeyAuth, BasicAuth, NoAuth

# JWT (most common)
auth = JWTAuth(token="your-jwt-token")

# API Key
auth = APIKeyAuth(api_key="your-api-key", header_name="X-API-Key")

# Basic Auth
auth = BasicAuth(username="user", password="pass")

# No auth
auth = NoAuth()

ai = Orchestrator(config=config, auth=auth)

Progress Tracking

def on_progress(message: str, progress: float):
    print(f"[{int(progress*100)}%] {message}")

config = Config(
    openapi_schema=schema,
    base_url="https://api.example.com",
    progress_callback=on_progress,
)

Response

result = ai.process("show pending orders")

result.message   # Natural language response
result.data      # Raw API data
result.success   # True/False
result.trace     # Debug info (if include_trace=True)

Key Principle

Server handles data scoping. The system prompt instructs Claude:

Do NOT add user ID filters (like technician=, customer=, created_by=) unless the user explicitly asks to filter by a specific person.

Your backend's get_queryset() permissions handle which data each user sees.

Requirements

  • Python 3.9+
  • OPENAI_API_KEY environment variable (default provider)
  • Or ANTHROPIC_API_KEY if using llm_provider="anthropic"

License

MIT

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

enable_ai-1.2.0.tar.gz (47.2 kB view details)

Uploaded Source

Built Distribution

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

enable_ai-1.2.0-py3-none-any.whl (55.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: enable_ai-1.2.0.tar.gz
  • Upload date:
  • Size: 47.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.9.6 Darwin/25.2.0

File hashes

Hashes for enable_ai-1.2.0.tar.gz
Algorithm Hash digest
SHA256 d75390059aaf6039c9e07ac78b9c138190fb3f50f3e7e7a9dbe714d1223d36b0
MD5 daa1942ed0863485865436aa896fc994
BLAKE2b-256 c8f84dc56c7f1d246894d282a3e18d78558e7e50223cd7588187739493ceb9ac

See more details on using hashes here.

File details

Details for the file enable_ai-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: enable_ai-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 55.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.9.6 Darwin/25.2.0

File hashes

Hashes for enable_ai-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 64a1e7202c28c94d6524dc3e558c3e8eab39d011d019d6696652591eaa760e2e
MD5 725138712cd3b0d2a617ffda5f668a0e
BLAKE2b-256 4d2130fcd0c93aaf2be45c9f9abf998cbc1a908cdf5a2d4b8e14eb729ca9c9d6

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