Skip to main content

Ad network that delivers ads to the LLM's response

Project description

Adstract AI Python SDK

CI PyPI

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

  1. Bump the version in pyproject.toml.
  2. Update CHANGELOG.md.
  3. Commit the changes.
  4. Tag the release: git tag vX.Y.Z.
  5. Push commits and tags: git push && git push --tags.

Publishing to PyPI happens automatically via GitHub Actions using trusted publishing.

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

adstractai-0.0.4.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

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

adstractai-0.0.4-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file adstractai-0.0.4.tar.gz.

File metadata

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

File hashes

Hashes for adstractai-0.0.4.tar.gz
Algorithm Hash digest
SHA256 50020bdf2922184cb1f5b7e4e9aa31989e14c92ca71518b34cfff842be31a1f9
MD5 66dd763ddde34530918b8644be1039f3
BLAKE2b-256 7d3f1d31639b34c912316476541723c414a1b01567eb35773214133cf8d938bc

See more details on using hashes here.

Provenance

The following attestation bundles were made for adstractai-0.0.4.tar.gz:

Publisher: publish.yml on Adstract-AI/adstract-library

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

File details

Details for the file adstractai-0.0.4-py3-none-any.whl.

File metadata

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

File hashes

Hashes for adstractai-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 79d6c3810d57332789659b4f0e782aeea784848e50beccdbd496a80bec5b7bf9
MD5 d5a854028c44e460534f5755e5c45ccb
BLAKE2b-256 2b7078b8010eb0c66047e3120f6d18cfdc26ac324137af7bd984d117faa85bf4

See more details on using hashes here.

Provenance

The following attestation bundles were made for adstractai-0.0.4-py3-none-any.whl:

Publisher: publish.yml on Adstract-AI/adstract-library

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