Skip to main content

Yet Another LLM Client

Project description

Yet Another LLM Client

An opinionated python wrapper for LLM calls. Supports multiple LLM providers:

  • OpenAI
  • Anthropic
  • more to come...

Uses pydantic models to serialize LLM responses. Every response has to be serialized into a pydantic model.

Full async support.

Usage

Every call to the LLM returns some metadata. Metadata contains token usage, costs, model used and context messages. YALC supports 2 modes of operations for handling metadata.

Metadata return mode

Metadata is returned directly alongside the response as a tuple.

client = create_client(LLMModel.gpt_4o_mini)

result, metadata = await client.structured_response(
    JudgmentResult, messages
)

Advantages:

  • Simple, no setup required
  • Direct access to metadata at the call site

Disadvantages:

  • Must handle metadata manually on every call
  • Easy to forget or handle inconsistently across call sites

Strategy metadata mode

A metadata handler strategy is provided during client creation. The strategy is automatically invoked on every call when a context is passed. The provided context is used for any additional data that needs to be used when handling LLM call metadata.

# 1. Define your strategy
class LogStrategy(ClientMetadataStrategy[LLMLogContext]):
    def handle(self, call: ClientCall, context: LLMLogContext):
        print(f"Tokens: {call.input_tokens + call.output_tokens}")
        print(f"Cost: {call.input_tokens_cost + call.output_tokens_cost}")
        db.save(call.model_dump(), context.request_id)

# 2. Create client with the strategy
client = create_client(LLMModel.gpt_4o_mini, metadata_strategies=[LogStrategy()])

# 3. Pass context to trigger the strategy
result = await client.structured_response(
    JudgmentResult, messages, context=llm_log_context
)

Advantages:

  • Metadata handling is set up once and applied consistently
  • Call sites stay clean — no need to unpack or handle metadata each time

Disadvantages:

  • More initial setup
  • Metadata handling is implicit, which can be harder to trace

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

yalc-0.2.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

yalc-0.2.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file yalc-0.2.0.tar.gz.

File metadata

  • Download URL: yalc-0.2.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for yalc-0.2.0.tar.gz
Algorithm Hash digest
SHA256 85125262d227af2a8fa283da21973c2a7d469c485e65ec03a642aa7913a7de7e
MD5 fedc7ff8a41309eab14c310da3603493
BLAKE2b-256 2b24a66b64dc5f9e469a80201e977b6873ac5fb9496c3d125dc93add9b64cb20

See more details on using hashes here.

Provenance

The following attestation bundles were made for yalc-0.2.0.tar.gz:

Publisher: publish.yml on cognitai-labs-dev/yalc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file yalc-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: yalc-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for yalc-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ef1906a05e6acc86817abbfad1aa11aad37a2bc420be6563f5b61c36eae868f6
MD5 187197c3205a9c3fb1e8c451729bdac7
BLAKE2b-256 8fe3bfad0a097bc2ed069a48414a0f3f363702ae6fc7a643b156f77f79e55cd2

See more details on using hashes here.

Provenance

The following attestation bundles were made for yalc-0.2.0-py3-none-any.whl:

Publisher: publish.yml on cognitai-labs-dev/yalc

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