Skip to main content

Python Package for Monetizing your LLM using AdLib

Project description

adlib-client

A Python wrapper for monetizing LLM output with AdLib.

Install

Install from PyPI:

pip install adlib-client

Required API keys

AdLib requires two keys:

ADLIB_API_KEY=your_adlib_api_key_here
ADLIB_CHATBOT_PUBLIC_KEY=your_chatbot_public_key_here

You can provide them using environment variables (in a .env file) or directly when creating AdLib():

from adlib_client import AdLib

adlib = AdLib(
    adlib_api_key="your_adlib_api_key_here",
    adlib_chatbot_api_key="your_chatbot_public_key_here",
)

Authorization on Initialization

When you create an instance of AdLib(), it automatically attempts to validate your credentials against the AdLib service.

  • Success: The object is initialized and ready for use.
  • Missing Keys: If either key is missing (and not found in environment variables), an Exception is raised immediately.
  • Invalid Keys: If the keys are provided but rejected by the server, a ValueError is raised with the specific error message from the service.

Basic usage

from adlib_client import AdLib

# Automatically loads keys from environment or .env
adlib = AdLib()

llm_output = "Here is the answer from your model."
adified_output = adlib.adify(llm_output)

print(adified_output)

adlib.adify() sends text to AdLib and returns the final transformed output string. If an ad is inserted, it's included in the string; otherwise, the original text is returned.

Use AdLib as a decorator

You can wrap your generation functions directly:

from adlib_client import AdLib

adlib = AdLib()

@adlib.adify
def generate_answer(prompt: str) -> str:
    # Your LLM logic here
    answer = ...
    return answer

# The returned value is now automatically adified
print(generate_answer("What is the weather?"))

Error Handling

  • Initialization: Exception for missing keys, ValueError for invalid keys.
  • Network Errors: Failed HTTP requests raise standard requests exceptions (e.g., connection issues).
  • Service Errors: If the adify service fails during a call, adify() safely returns the original LLM output.

Notes

  • adlib.adify() returns the transformed text string directly.
  • Use adify when you want to wrap LLM outputs or decorate generation functions.

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

adlib_client-0.1.9.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

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

adlib_client-0.1.9-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file adlib_client-0.1.9.tar.gz.

File metadata

  • Download URL: adlib_client-0.1.9.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for adlib_client-0.1.9.tar.gz
Algorithm Hash digest
SHA256 10be0a44bb1f5619eec0183d366b008283522f110544ba668524266fde59ecbc
MD5 6feaa924e822b56cc99aabac3f6e0723
BLAKE2b-256 8e9959f81650060aa4d097718e30a59c953f00954f1b2dd59bb0e664b9600cfc

See more details on using hashes here.

File details

Details for the file adlib_client-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: adlib_client-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for adlib_client-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 94e6128543727416a1be27e59ce29aa829cc4c45553770d86adc8f3e59263a18
MD5 04fa9004526b24fcc9068c6956a0faa5
BLAKE2b-256 7911fc48cb5c41c31e2414292851b838112be9e55394a4f6195e6b9cd1d596b4

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