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
Exceptionis raised immediately. - Invalid Keys: If the keys are provided but rejected by the server, a
ValueErroris 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?"))
Raw response access
When you need ad metadata or success status, use adify_full():
response = adlib.adify_full("My LLM answer text")
if response["success"]:
print(f"Adified Text: {response['adified']}")
print(f"Ad Info: {response['ad']}")
else:
print(f"Error: {response['error']}")
The Response Format
adify_full() returns a dictionary:
{
"success": true,
"adified": "...the output with an ad included...",
"ad": {
"url": "https://example.com/ad",
"description": "Check out this product!"
}
}
success: Boolean indicating if the request was processed correctly.adified: The final string (contains the original text if no ad was added or if an error occurred).ad: A dictionary containingurlanddescription. It will be empty{}if no ad was inserted.error: Included only ifsuccessisfalse.
Error Handling
- Initialization:
Exceptionfor missing keys,ValueErrorfor invalid keys. - Network Errors: Failed HTTP requests raise standard
requestsexceptions (e.g., connection issues). - Service Errors: If the adify service fails during a call,
adify_full()setssuccess: Falseand provides anerrormessage, whileadify()safely returns the original LLM output.
Notes
adlib.adify()only inserts ads when the text is appropriate.- You can render the ad metadata separately from the main response text for cleaner UI.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file adlib_client-0.1.8.tar.gz.
File metadata
- Download URL: adlib_client-0.1.8.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40ef8c8126fa5e5994238a84d4dfa93908a284d50472ad3634522ee392a4158c
|
|
| MD5 |
f404dacf921b5b0f4e400120276b770a
|
|
| BLAKE2b-256 |
9328995fe9baed69ec370959f274882079ab4e98592cfa10fc89c5b1b8207031
|
File details
Details for the file adlib_client-0.1.8-py3-none-any.whl.
File metadata
- Download URL: adlib_client-0.1.8-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5fdc32665f2551da36f22f42c6041e73f6b67d1a158e903ed177121d30b5ce31
|
|
| MD5 |
70d404650ff4f13fec20b6df2f0fb570
|
|
| BLAKE2b-256 |
9dec21cc69702f7199cde35fdd2fadc109595e9a3bc0b7c54a4ac023312de865
|