Ad network that delivers ads to the LLM's response
Project description
Adstract AI Python SDK
Ad network SDK that delivers ads into LLM responses.
Install
python -m pip install adstractai
Quickstart
from adstractai import AdClient
client = AdClient(api_key="sk_test_1234567890")
response = client.request_ad(
prompt="How do I improve analytics in my LLM app?",
conversation={
"conversation_id": "conv-1",
"session_id": "sess-1",
"message_id": "msg-1",
},
user_agent=(
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
"(KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
),
)
print(response.ads)
client.close()
Authentication
Pass an API key when initializing the client or set ADSTRACT_API_KEY.
export ADSTRACT_API_KEY="sk_test_1234567890"
from adstractai import AdClient
client = AdClient()
Advanced usage
from adstractai import AdClient
client = AdClient(api_key="sk_test_1234567890", retries=2)
response = client.request_ad(
prompt="Need performance tips",
conversation={
"conversation_id": "conv-42",
"session_id": "sess-42",
"message_id": "msg-42",
},
user_agent=(
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 "
"(KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
),
metadata={
"client": {
"referrer": "https://example.com",
}
},
constraints={
"max_ads": 2,
"safe_mode": "standard",
},
)
print(response.raw)
client.close()
Async usage
import asyncio
from adstractai import AdClient
async def main() -> None:
client = AdClient(api_key="sk_test_1234567890")
response = await client.request_ad_async(
prompt="Need performance tips",
conversation={
"conversation_id": "conv-99",
"session_id": "sess-99",
"message_id": "msg-99",
},
user_agent=(
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 "
"(KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
),
)
print(response.ads)
await client.aclose()
asyncio.run(main())
Development setup
python -m venv .venv
source .venv/bin/activate
python -m pip install -e ".[dev]"
pre-commit install
Scripts
ruff format .
ruff check .
pyright
pytest
python -m build
Release
- Bump the version in
pyproject.toml. - Update
CHANGELOG.md. - Commit the changes.
- Tag the release:
git tag vX.Y.Z. - Push commits and tags:
git push && git push --tags.
Publishing to PyPI happens automatically via GitHub Actions using trusted publishing.
Project details
Release history Release notifications | RSS feed
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 adstractai-0.0.3.tar.gz.
File metadata
- Download URL: adstractai-0.0.3.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a66b6e456b12bc417c11fd7052f861b5028869d02e3b3ad916473ed15593e00
|
|
| MD5 |
90e09b5b32db40f0c43079af8791c7a4
|
|
| BLAKE2b-256 |
8fb1d82aaedd4d92aed407756a19a9d3a1bedbced17899591be0a89cc7742cac
|
Provenance
The following attestation bundles were made for adstractai-0.0.3.tar.gz:
Publisher:
publish.yml on Adstract-AI/adstract-library
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
adstractai-0.0.3.tar.gz -
Subject digest:
0a66b6e456b12bc417c11fd7052f861b5028869d02e3b3ad916473ed15593e00 - Sigstore transparency entry: 843825521
- Sigstore integration time:
-
Permalink:
Adstract-AI/adstract-library@fbe93a7d44c43450f30eb69bcd8da8d59ec3190d -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/Adstract-AI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fbe93a7d44c43450f30eb69bcd8da8d59ec3190d -
Trigger Event:
push
-
Statement type:
File details
Details for the file adstractai-0.0.3-py3-none-any.whl.
File metadata
- Download URL: adstractai-0.0.3-py3-none-any.whl
- Upload date:
- Size: 3.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f446e563933487a45aef35eb5643c4b0bec3c1b324c0e8e85bca0fa2ec87c98c
|
|
| MD5 |
aa635708b89f0548d954092c0eb534dd
|
|
| BLAKE2b-256 |
89dc40831a32cbb62391b2858accc666592d90864d0cba0e16b884156dbcc541
|
Provenance
The following attestation bundles were made for adstractai-0.0.3-py3-none-any.whl:
Publisher:
publish.yml on Adstract-AI/adstract-library
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
adstractai-0.0.3-py3-none-any.whl -
Subject digest:
f446e563933487a45aef35eb5643c4b0bec3c1b324c0e8e85bca0fa2ec87c98c - Sigstore transparency entry: 843825522
- Sigstore integration time:
-
Permalink:
Adstract-AI/adstract-library@fbe93a7d44c43450f30eb69bcd8da8d59ec3190d -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/Adstract-AI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fbe93a7d44c43450f30eb69bcd8da8d59ec3190d -
Trigger Event:
push
-
Statement type: