Observed since 20 Oct, 19:52 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
Ads for AI applications. Enabling the Freemium model for the AI era.
This is the LangChain toolkit for Ads4GPTs.
A Python package that integrates Ads4GPTs functionalities into LangChain applications, allowing for seamless retrieval of relevant advertisements based on contextual input.
Ads4GPTs LangChain Integration is a Python package designed to seamlessly incorporate Ads4GPTs functionalities into your LangChain and LangGraph applications. It provides tools and utilities to retrieve contextually relevant advertisements, leveraging the power of LangChain's agentic framework.
Whether you're building a chatbot, a recommendation system, or any application that can benefit from targeted ads, this package offers a robust and production-ready solution.
If you find our ADS4GPTs project helpful, please give it a star ⭐️
You can install the package directly from PyPI:
pip install ads4gpts-langchain
Alternatively, you can install the package from source:
git clone https://github.com/ADS4GPTs/ads4gpts.git
cd ads4gpts/libs/python-sdk/ads4gpts-langchain
pip install .
The package requires certain environment variables for API authentication:
Set them in your environment:
export OPENAI_API_KEY='your-openai-api-key'
export ADS4GPTS_API_KEY='your-ads4gpts-api-key'
Alternatively, you can pass the API keys directly when initializing classes or set up a .env file.
Import the necessary classes and functions in your Python script:
from ads4gpts_langchain import Ads4gptsInlineSponsoredResponsesTool, Ads4gptsSuggestedPromptsTool, Ads4gptsToolkit
Example 1: Using Ads4GPTsTool Directly
from ads4gpts_langchain import Ads4gptsInlineSponsoredResponsesTool
# Instantiate the tool (API key retrieved from environment variable)
ads_tool = Ads4gptsInlineSponsoredResponsesTool(ads4gpts_api_key="your-ads4gpts-api-key")
# Retrieve ads synchronously
ads = ads_tool._run(
id="test_id",
user={"gender": "female", "age_range": "25-34", "persona": "test_persona"},
ad_recommendation="test_recommendation",
undesired_ads="test_undesired_ads",
context="Looking for the latest smartphone deals",
num_ads=2,
style="neutral"
)
print(ads)
# Retrieve ads asynchronously
import asyncio
async def fetch_ads():
ads = await ads_tool._arun(
id="test_id",
user={"gender": "female", "age_range": "25-34", "persona": "test_persona"},
ad_recommendation="test_recommendation",
undesired_ads="test_undesired_ads",
context="Best travel packages to Europe",
num_ads=3,
style="neutral"
)
print(ads)
asyncio.run(fetch_ads())
### Using the Toolkit
from ads4gpts_langchain import Ads4gptsToolkit
# Initialize the toolkit
toolkit = Ads4gptsToolkit(ads4gpts_api_key="your-ads4gpts-api-key")
# Get the list of tools
tools = toolkit.get_tools()
# Use the tool from the toolkit
ads = tools[0]._run(
id="test_id",
user={"gender": "female", "age_range": "25-34", "persona": "test_persona"},
ad_recommendation="test_recommendation",
undesired_ads="test_undesired_ads",
context="Healthy recipes and cooking tips",
num_ads=1,
style="neutral"
)
print(ads)
Examples for using them in your LangChain and LangGraph application exist in the examples folder of the parent repo.
Contributions are welcome! Please follow these steps:
git clone git@github.com:ADS4GPTs/ads4gpts.git
git checkout -b feature/your-feature-name
pip install pytest pytest-asyncio
python -m unittest discover tests
Formal tests are still under development. 6. Commit Changes:
git commit -am 'Add your commit message here'
git push origin feature/your-feature-name
This project is licensed under the License of the Ads4GPTs repository.
For issues and feature requests, please use the GitHub issues page.
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.1.15 | 9 Jul 2025 | 0 |
This describes our collected data; it is not a security assessment.
Observed since 20 Oct, 19:52 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:0b3fe80cc46dcce2748173e7c69c2c5fd2e8b5af0779952c44df3de23da0fcee