The official Python library for the xler.ai API
Project description
XlerAI Python API library
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
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12f264a45b18ddd35612d8c56098c35908391769f37fb28fe5fbe043e4fb0386
|
|
| MD5 |
952bde8ab0aa9152bc3a482ece5c4e00
|
|
| BLAKE2b-256 |
078b4c9b0b510e4dbd24e4af3a577e907443e566884e8d92ed24737e45631812
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f86daf256816de2aa6bcb5775019c507c07eba3e934aaea631082e534aaa164
|
|
| MD5 |
4a4e9d3e6ad11950a4f3b3b4765fbad2
|
|
| BLAKE2b-256 |
0c9a1e6d478bc272a9bea5d7bf5232ccb8dc9731b221faf41e4e3cb19a84c320
|