Skip to main content

The official Python library for the xler.ai API

Project description

XlerAI Python API library

PyPI version

The XlerAI Python library provides convenient access to the XlerAI REST API from any Python 3.7+ application. The library wraps the openai python library, points it at api.xler.ai/v1 for you, and extends their library further with additional functionality.

Documentation

The REST API documentation can be found on docs.xler.ai.

Installation

pip install xlerai

Usage

The full API of this library can be found in api.md.

import os
from xlerai import XlerAI

client = XlerAI(
    # This is the default and can be omitted
    api_key=os.environ.get("OPENAI_API_KEY"),
)

chat_completion = client.chat.completions.create(
    messages=[
        {
            "role": "user",
            "content": "Say this is a test",
        }
    ],
    model="gpt-3.5-turbo",
)

While you can provide an api_key keyword argument, we recommend using python-dotenv to add OPENAI_API_KEY="My API Key" to your .env file so that your API Key is not stored in source control.

Async usage

Simply import AsyncXlerAI instead of XlerAI and use await with each API call:

import os
import asyncio
from xlerai import AsyncXlerAI

client = AsyncXlerAI(
    # This is the default and can be omitted
    api_key=os.environ.get("OPENAI_API_KEY"),
)


async def main() -> None:
    chat_completion = await client.chat.completions.create(
        messages=[
            {
                "role": "user",
                "content": "Say this is a test",
            }
        ],
        model="gpt-3.5-turbo",
    )


asyncio.run(main())

Functionality between the synchronous and asynchronous clients is otherwise identical.

Streaming Responses

We provide support for streaming responses using Server Side Events (SSE).

from xlerai import XlerAI

client = XlerAI()

stream = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Say this is a test"}],
    stream=True,
)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="")

The async client uses the exact same interface.

from xlerai import AsyncXlerAI

client = AsyncXlerAI()


async def main():
    stream = await client.chat.completions.create(
        model="gpt-4",
        messages=[{"role": "user", "content": "Say this is a test"}],
        stream=True,
    )
    async for chunk in stream:
        print(chunk.choices[0].delta.content or "", end="")


asyncio.run(main())

Requirements

Python 3.7 or higher.

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

xlerai-1.12.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

xlerai-1.12.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file xlerai-1.12.0.tar.gz.

File metadata

  • Download URL: xlerai-1.12.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for xlerai-1.12.0.tar.gz
Algorithm Hash digest
SHA256 12f264a45b18ddd35612d8c56098c35908391769f37fb28fe5fbe043e4fb0386
MD5 952bde8ab0aa9152bc3a482ece5c4e00
BLAKE2b-256 078b4c9b0b510e4dbd24e4af3a577e907443e566884e8d92ed24737e45631812

See more details on using hashes here.

File details

Details for the file xlerai-1.12.0-py3-none-any.whl.

File metadata

  • Download URL: xlerai-1.12.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for xlerai-1.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5f86daf256816de2aa6bcb5775019c507c07eba3e934aaea631082e534aaa164
MD5 4a4e9d3e6ad11950a4f3b3b4765fbad2
BLAKE2b-256 0c9a1e6d478bc272a9bea5d7bf5232ccb8dc9731b221faf41e4e3cb19a84c320

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