Skip to main content

Ads for AI applications. Enabling the Freemium model for the AI era.

Project description

Ads4GPTs Langchain Toolkit

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.


Table of Contents


Introduction

Ads4GPTs LangChain Integration is a Python package designed to seamlessly incorporate Ads4GPTs functionalities into your LangChain 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.


Features

  • Easy Integration: Quickly integrate ad retrieval capabilities into your LangChain agents.
  • Contextual Ad Retrieval: Fetch relevant ads based on the provided context to enhance user engagement.
  • Asynchronous Support: Both synchronous and asynchronous operations are supported for flexibility.
  • Robust Error Handling: Comprehensive error handling and logging for reliable production deployments.
  • Secure API Key Management: Securely handle API keys through environment variables or direct input.

Installation

Using pip

You can install the package directly from PyPI:

pip install ads4gpts-langchain

From Source

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 .

Usage

Prerequisites

  • Python 3.11+
  • (Optional) OpenAI Account and API Key
    • In order to use the ads4gpts_agent you
    • Sign up at OpenAI and obtain an API key.
  • Ads4GPTs API Key

Dependencies

Install required Python packages:

pip install -r requirements.txt

Environment Variables

The package requires certain environment variables for API authentication:

  • OPENAI_API_KEY: Your OpenAI API key.
  • ADS4GPTS_API_KEY: Your Ads4GPTs API key.

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.

Initialization

Import the necessary classes and functions in your Python script:

from ads4gpts_langchain import Ads4GPTsTool, Ads4GPTsToolkit, get_ads4gpts_agent

Examples

Example 1: Using Ads4GPTsTool Directly

from ads4gpts_langchain import Ads4GPTsTool

# Instantiate the tool (API key retrieved from environment variable)
ads_tool = Ads4GPTsTool()

# Retrieve ads synchronously
ads = ads_tool._run(context="Looking for the latest smartphone deals", num_ads=2)
print(ads)

# Retrieve ads asynchronously
import asyncio

async def fetch_ads():
    ads = await ads_tool._arun(context="Best travel packages to Europe", num_ads=3)
    print(ads)

asyncio.run(fetch_ads())

from ads4gpts_langchain import Ads4GPTsToolkit

# Initialize the toolkit
toolkit = Ads4GPTsToolkit()

# Get the list of tools
tools = toolkit.get_tools()

# Use the tool from the toolkit
ads = tools[0]._run(context="Healthy recipes and cooking tips", num_ads=1)
print(ads)

Examples for using them in your LangChain and LangGraph application exist in the examples folder

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the Repository: Click the "Fork" button at the top right of the repository page.
  2. Clone Your Fork:
git clone https://github.com/ads4gpts.com/ads4gpts.git
  1. Create a Branch:
git checkout -b feature/your-feature-name
  1. Make Changes: Implement your feature or bug fix.
  2. Run Tests: Ensure all tests pass.
pip install pytest pytest-asyncio
python -m unittest discover tests

Formal tests are still under development. Tests are based on the library contribution.. 6. Commit Changes:

git commit -am 'Add your commit message here'
  1. Push to Your Fork:
git push origin feature/your-feature-name
  1. Open a Pull Request: Navigate to the original repository and click "New pull request".

License

This project is licensed under the License of the Ads4GPTs repository.

Contact

For issues and feature requests, please use the GitHub issues page.

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

ads4gpts_langchain-0.1.1.tar.gz (25.5 kB view details)

Uploaded Source

Built Distribution

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

ads4gpts_langchain-0.1.1-py3-none-any.whl (28.7 kB view details)

Uploaded Python 3

File details

Details for the file ads4gpts_langchain-0.1.1.tar.gz.

File metadata

  • Download URL: ads4gpts_langchain-0.1.1.tar.gz
  • Upload date:
  • Size: 25.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for ads4gpts_langchain-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a104a3ea60799142508ff8c329a0697611ce1d9e970d5ac0a13ea992a41bf986
MD5 e0bf2095b9eba57244880299228d0ae2
BLAKE2b-256 00442d4474756f6a88675d57345b7e2d84a363da6e65dd5637bc8f4b88225167

See more details on using hashes here.

File details

Details for the file ads4gpts_langchain-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ads4gpts_langchain-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b6ae9ff9187b77ef44275dba6a223402c2adf341c943bff9c62ad01d6bdd6198
MD5 32e3639ec1db4bba8680d6d584cdf3d7
BLAKE2b-256 b39ef133b4153b6baa22c80be09750776ce345f598e2b890bbb31273153999d6

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