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:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- 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
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
File details
Details for the file cloudflareai-0.7.0.tar.gz
.
File metadata
- Download URL: cloudflareai-0.7.0.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffd918342b9e2de364d6fcb3d14e1da6b76756f3f3f27aa95326ecde70ff4a24 |
|
MD5 | 8ffde56f13bd0a141ed10464f8808bb4 |
|
BLAKE2b-256 | 94ea7da14b6d44f5fcb7187cd9f699827fcac224536cb173e68def7c1d19480f |
File details
Details for the file cloudflareai-0.7.0-py3-none-any.whl
.
File metadata
- Download URL: cloudflareai-0.7.0-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cc16073647c81612084abb5062c37568827b7686c3ef693179b3254b65c04f2 |
|
MD5 | 1eab7cf1fefc35f9193ca5500ae63131 |
|
BLAKE2b-256 | f6845d813f91e7ebaefbba1112048e81edc642b6c6afd3adecb421e3b2b33cbe |