Skip to main content

Python client library for the Rebyte API

Project description

Rebyte Python Library

Static Badge PyPI PyPI - Downloads GitHub issues readthedocs License

The Rebyte Python library provides convenient access to the Rebyte API from applications written in the Python language. It includes a pre-defined set of classes for API resources that initialize themselves dynamically from API responses which makes it compatible with a wide range of versions of the Rebyte API.

Features

  1. Generate streaming or non-streaming output.
  2. Use async or sync method.
  3. Support stateful agent memory with session_id.

Installation

Python 3.7 and above is required.

pip install rebyte

If already installed, update package to the latest version:

pip install --upgrade rebyte

If wishing to modify this package, clone and install in editable mode:

git clone https://github.com/ReByteAI/rebyte-python.git
cd rebyte-python
pip install -e .

Prerequisites

ReByte API Key

To get your ReByte API key, follow these steps:

  1. Go to the ReByte website and sign up for an account if you haven't already.
  2. Once you're logged in, go to Settings > API Keys.
  3. Generate a new API key by clicking on the "Generate" button.
  4. Prepare to use it during configuration.

ReByte Agent Creation

  1. You can follow the tutorial in the webpage ReByte Quick Start to create your own agent. Or you can use agents in ReByte Community. Open an agent and clone to your personal project.

  2. Deploy the agent and get the project_id and agent_id in the following format: https://rebyte.ai/api/sdk/p/{project_id}/a/{agent_id}/r.

Usage (TODO)

API

Call the ReByte agent in sync and nonstreaming method:

from rebyte import RebyteAPIRequestor
requestor = RebyteAPIRequestor(
            key=<your api_key>,
            api_base=<rebyte endpoint, default to https://rebyte.ai>
        )
path = f'/api/sdk/p/{project_id}/a/{agent_id}/r'
data = {
    "version": "latest",
    "inputs": [{"messages": [{"role": "user","content": "My name is John"}]}],
    "config": {}
}
res, _, _ = requestor.request(
    method="POST",
    url=path,
    params=data,
    stream=False
)
print(res.data['run']['results'][0][0]["value"]["content"])

Async API

Async support is available in the API by prepending a to a network-bound method:

import asyncio
from rebyte import RebyteAPIRequestor

async def main():
    requestor = RebyteAPIRequestor(
        key=<your api_key>,
        api_base=<rebyte endpoint, default to https://rebyte.ai>
    )
    path = f'/api/sdk/p/{project_id}/a/{agent_id}/r'
    data = {
        "version": "latest",
        "inputs": [{"messages": [{"role": "user","content": "My name is John"}]}],
        "config": {}
    }
    res, _, _ = await requestor.arequest(
        method="POST",
        url=path,
        params=data,
        stream=False
    )
    print(res.data['run']['results'][0][0]["value"]["content"])

asyncio.run(main())

Stream API

Streaming support is available in the API by set request in stream=True mode:

from rebyte import RebyteAPIRequestor
requestor = RebyteAPIRequestor(
            key=<your api_key>,
            api_base=<rebyte endpoint, default to https://rebyte.ai>
        )
path = f'/api/sdk/p/{project_id}/a/{callable_id}/r'
data = {
    "version": "latest",
    "inputs": [{"messages": [{"role": "user","content": "My name is John"}]}],
    "config": {},
    "stream": True
}
res, _, _ = requestor.request(
    method="POST",
    url=path,
    params=data,
    stream=True
)

for msg in res:
    # print streaming output message
    stream_text = msg.get_stream_chunk()
    if msg and stream_text:
        print(stream_text)

API session

from rebyte import RebyteAPIRequestor
requestor = RebyteAPIRequestor(
            key=<your api_key>,
            api_base=<rebyte endpoint, default to https://rebyte.ai>
        )
path = f'/api/sdk/p/{project_id}/a/{callable_id}/r'

# You may use any string as session_id and try to avoid duplicate session_ids
# Note that you must set session_id if you want to enable stateful actions, such as threads (aka, memory), in your agent.
# Or you can leave it as empty when the agent has no stateful actions.
data = {
    "version": "latest",
    "inputs": [{"messages": [{"role": "user","content": "Please remember: My name is John"}]}],
    "config": {},
    "session_id" : "ANY_STRING"
}
res, _, _ = requestor.request(
    method="POST",
    url=path,
    params=data,
    stream=False
)
print(res.data['run']['results'][0][0]["value"]["content"])

data = {
    "version": "latest",
    "inputs": [{"messages": [{"role": "user","content": "Please answer me: What is my name?"}]}],
    "config": {},
    "session_id" : "ANY_STRING"
}
res, _, _ = requestor.request(
    method="POST",
    url=path,
    params=data,
    stream=False
)
print(res.data['run']['results'][0][0]["value"]["content"])

Please see more examples in test/ and examples.ipynb.

Documentation

More information can be found on the ReByte Documentation Site.

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

rebyte-0.0.5.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

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

rebyte-0.0.5-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file rebyte-0.0.5.tar.gz.

File metadata

  • Download URL: rebyte-0.0.5.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for rebyte-0.0.5.tar.gz
Algorithm Hash digest
SHA256 7cced8f2992071f7062d01c61090c51b2563a094944df2c3c7315db0189655df
MD5 39c47874c2382c985def90abbe581891
BLAKE2b-256 ea402a1ae5f5be0cd92c52f736f34b8bb86b8b2d61593667442fde311048c0d1

See more details on using hashes here.

File details

Details for the file rebyte-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: rebyte-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for rebyte-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 47d3eb00e4076b1ac7bda5a5636a3c1e3370f1dfe98a15935ff21e9711f2b436
MD5 d282b8aaf71406f98e70acb78886311a
BLAKE2b-256 1826af2b38d20f0d088c2df1c89dabaf3d3f6192c0711912e49fd27e5f79355c

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