Skip to main content

Modular, backend-agnostic interface for interacting with large language models (LLMs).

This library is part of the darca-* ecosystem and provides a plug-and-play, extensible interface to communicate with LLM providers like OpenAI. It is designed with testability, structure, and future integration in mind.

Build Status Deploy Status Codecov Black code style License PyPi GitHub Pages

Features

  • ✅ Unified AIClient interface for all LLMs

  • 🔌 OpenAI integration out of the box (GPT-4, GPT-3.5)

  • 🧱 Extensible abstract interface (BaseLLMClient) for new providers

  • 🧪 Full pytest support with 100% coverage

  • 📦 Rich exception handling with structured DarcaException

  • 📋 Markdown-aware content formatting using _strip_markdown_prefix

  • 🧠 Logging support via darca-log-facility

Quickstart

  1. Install dependencies:

make install
  1. Run all quality checks (format, test, docs):

make check
  1. Run tests only:

make test
  1. Use the client:

from darca_llm import AIClient

ai = AIClient()
response = ai.get_raw_response(
    system="You are a helpful assistant.",
    user="What is a Python decorator?"
)
print(response)

Using get_file_content_response

The get_file_content_response() method allows for structured file content prompting with LLMs.

Example:

from darca_llm import AIClient

client = AIClient()

user_prompt = "Provide the content of a simple Python file."

result = client.get_file_content_response(
    system="Explain the code.",
    user=user_prompt
)
print(result)

This method ensures that only a single code block is returned and properly stripped of formatting using _strip_markdown_prefix().

Error Handling

All exceptions are subclasses of DarcaException and include:

  • LLMException: Base for all LLM-specific errors

  • LLMAPIKeyMissing: Raised when the API key is missing for the selected backend

  • LLMContentFormatError: Raised when: - Multiple blocks are detected within the response - The response cannot be properly stripped of markdown/code block formatting

  • LLMResponseError: Raised when the LLM provider returns an error or response parsing fails

All exceptions include:

  • error_code

  • message

  • Optional metadata

  • Optional cause

  • Full stack trace logging

Documentation

Build and view the docs:

make docs

Open the HTML documentation at:

docs/build/html/index.html

For detailed usage, refer to the usage.rst documentation.

Release files for darca-llm 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for darca-llm 0.2.0
File Size Uploaded
darca_llm-0.2.0.tar.gz 6.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for darca-llm 0.2.0
File Interpreter ABI Platform
darca_llm-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.5 kB

Release files / darca_llm-0.2.0.tar.gz

Download URL darca_llm-0.2.0.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ac90ddd2eb62354c41fb02780d9a13fde0bd44556b2c01d8aae29ac22400d9c0
BLAKE2b-256 checksum
How to use checksums
31b25875442c7b1355f7357cedb1b701037ff0156dea4abdb11d4a011a4354b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 30, 2025.

Transparency log

Release files / darca_llm-0.2.0-py3-none-any.whl

Download URL darca_llm-0.2.0-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
82b57a6ce1b2e061c6d4c048491192761659fa8aa302592fe63b21705546b3fc
BLAKE2b-256 checksum
How to use checksums
36849d628e1005e14488371cdc92566310dc652c63914e8278614e1337a896db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 30, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page