Dhenara is an open source Python package designed for seamless interaction with various AI models. It provides a unified API, type safety with Pydantic, and easy integration across different providers, focusing on simplicity and minimal dependencies for developers looking to enhance their applications with AI capabilities.
Dhenara is an open-source Python package designed for seamless interaction with a variety of AI models through a unified API. This lightweight framework simplifies the integration of multiple AI models into Python applications, prioritizing simplicity and minimal dependencies, while ensuring type safety through the use of Pydantic Models.
Here’s a straightforward example demonstrating how to utilize Dhenara to interact with an AI model. More examples can be found in the extensive documentation at 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,
)
For comprehensive documentation, visit docs.dhenara.com. This resource provides all the information necessary to maximize the potential of Dhenara in Python applications.
No comments yet.
Sign in to be the first to comment.