Skip to main content

Dhenara Package for Multi Provider AI-Model API calls

Project description

Dhenara

Dhenara is a genuinely open source Python package for interacting with various AI models in a unified way. It is a lightweight, straightforward framework for integrating multiple AI models into Python applications. It's similar in spirit to LangChain but with a focus on simplicity and minimal dependencies along with type safety using Pydantic Models.

For full documentation, visit docs.dhenara.com.

Why Dhenara?

  • Genuinely Open Source: Built from the ground up as a community resource, not an afterthought or internal tool
  • Unified API: Interact with different AI providers through a consistent interface
  • Type Safety: Built with Pydantic for robust type checking and validation
  • Easy Regeneration across Providers: With a unified Pydantic output and built-in prompt formatting, send output from a model to any other model easily
  • Streaming: First-class support for streaming responses along with accumulated responses similar to non-streaming responses
  • Async Support: Both synchronous and asynchronous interfaces for maximum flexibility
  • Resource Management: Automatic handling of connections, retries, and timeouts
  • Foundation Models: Pre-configured models with sensible defaults
  • Test Mode: Bring up your app with dummy responses for streaming and non-streaming generation
  • Cost/Usage Data: Derived cost and usage data along with responses, with optional charge for each model endpoint for commercial deployment
  • Community-Oriented Design: An architecture separating API credentials, models, and configurations for flexible deployment and scaling

Example Usage

Here's a simple example of using Dhenara to interact with an AI model. You can find more examples in docs.dhenara.com.

from dhenara.ai import AIModelClient
from dhenara.ai.types import AIModelCallConfig, AIModelEndpoint
from dhenara.ai.types.external_api import AIModelAPIProviderEnum
from dhenara.ai.types.genai import AIModelAPI
from dhenara.ai.types.genai.foundation_models.anthropic.chat import Claude37Sonnet

# Create an API
api = AIModelAPI(
    provider=AIModelAPIProviderEnum.ANTHROPIC,
    api_key="your_api_key",
)

# Create an endpoint using a pre-configured model
model_endpoint = AIModelEndpoint(
    api=api,
    ai_model=Claude37Sonnet,
)

# Configure the api call
config = AIModelCallConfig(
    max_output_tokens=16000,
    reasoning=True,  # Thinking/reasoning mode
    max_reasoning_tokens=8000,
    streaming=False,
)

# Create the client
client = AIModelClient(
    model_endpoint=model_endpoint,
    config=config,
    is_async=False,
)

# Create a prompt
prompt = {
    "role": "user",
    "content": "Explain quantum computing in simple terms",
}

# Generate a response
response = client.generate(prompt=prompt)

# If not streaming
if response.chat_response:
    print(response.chat_response.choices[0].contents[0].get_text())

# If streaming
elif response.stream_generator:
    for chunk, _ in response.stream_generator:
        if chunk:
            print(
                chunk.data.choice_deltas[0].content_deltas[0].get_text_delta(),
                end="",
                flush=True,
            )

Documentation

For full documentation, visit docs.dhenara.com.

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

dhenara_ai-1.1.3.tar.gz (122.5 kB view details)

Uploaded Source

Built Distribution

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

dhenara_ai-1.1.3-py3-none-any.whl (167.0 kB view details)

Uploaded Python 3

File details

Details for the file dhenara_ai-1.1.3.tar.gz.

File metadata

  • Download URL: dhenara_ai-1.1.3.tar.gz
  • Upload date:
  • Size: 122.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.2

File hashes

Hashes for dhenara_ai-1.1.3.tar.gz
Algorithm Hash digest
SHA256 5e36bb7e69d3bdb60ff60469d88be367c5f07be9f749e26946736c8f30a4a3d4
MD5 7d478d710a1b17061c4bda77075806c0
BLAKE2b-256 22b6f0f5981a388fbe5f3938533768445d9b72e7f4165d92c93bd8d9e99c7ab5

See more details on using hashes here.

File details

Details for the file dhenara_ai-1.1.3-py3-none-any.whl.

File metadata

  • Download URL: dhenara_ai-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 167.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.2

File hashes

Hashes for dhenara_ai-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0bc1550500c6ed414b540b8d2dd0f4dc574a00ea65cebd13a79d6f3987c8a389
MD5 4f6a7ec3f615558600581a8481265080
BLAKE2b-256 812a8b484d633833c8ffa0e9d1c494c9ee228a8a5cafb4bd4b5ac76d9433a891

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