Skip to main content

Cloudflare AI Python SDK

Project description

Cloudflare AI Python Wrapper

This Python library provides a convenient way to interact with the Cloudflare AI API asynchronously, allowing you to leverage the power of Cloudflare's AI models in your applications. With this wrapper, you can easily integrate AI-driven features into your projects without the hassle of handling API requests and responses manually.

Installation

Install from PyPI:

pip install cloudflareai

Install from Github:

python -m pip install -U git+https://github.com/alexraskin/cloudflareai-py

Or build from source:

git clone
cd cloudflareai
python setup.py install

Usage

Import the CloudflareAI class and the desired model enums. Then, create an instance of the CloudflareAI class with your Cloudflare API key and account identifier. You can then use the instance to call the desired AI model.

import asyncio

from cloudflareai import (
    CloudflareAI,
    AiTextToImageModels,
    AiTextGenerationModels,
    AiImageClassificationModels,
)


async def main():
    ai = CloudflareAI(
        Cloudflare_API_Key=<Your Token>,
        Cloudflare_Account_Identifier=<Account ID>,
    )

    text = await ai.TextGeneration(
        prompt="You are helpful",
        system_prompt="Hello, my name is Alex",
        model_name=AiTextGenerationModels.CODE_LLAMA_7B,
    )
    image = await ai.TextToImage(
      prompt="a Cat",
      model_name=AiTextToImageModels.XL_BASE
    )
    print(text.text) # returns string
    print(image.image) # returns bytes

    ### Also get status codes
    print(text.status_code)
    print(image.status_code)

asyncio.run(main())

Models

This wrapper also includes enums for AI models, making it easier to select the desired model for your tasks. Available enums include:

  • AiImageClassificationModels
  • AiTranslationModels
  • AiTextGenerationModels
  • AiSpeechRecognitionModels
  • AiTextToImageModels
  • TranslationLanguages

Contributing

If you'd like to contribute to this project, please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Submit a pull request with a clear description of your changes.

License

Mozilla Public License Version 2.0 (MPL-2.0) - See LICENSE for more information.

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

cloudflareai-0.1.2.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

cloudflareai-0.1.2-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file cloudflareai-0.1.2.tar.gz.

File metadata

  • Download URL: cloudflareai-0.1.2.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for cloudflareai-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f0a92005ef304c2273499b82eb25b0dbca99550a3f95b697b536dc212aa5dd8d
MD5 9419eb0d31999aa99d53e78703e93456
BLAKE2b-256 566622edf10ddefbddcac4966e52fd7843e1d915eab0e96c07045d3283e0177f

See more details on using hashes here.

File details

Details for the file cloudflareai-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: cloudflareai-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for cloudflareai-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 69027bd74c8c0cc029bf2222bf156c6d3d4626be9868eed19691710fc96361f8
MD5 e35ccf5303e013199f6cab001ecc86af
BLAKE2b-256 1f32ace3292fab890a84b70e8445b4d63a8be4bfcb41c47a612f218abcc13bfb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page