Skip to main content

Python langchain-like client library for the Rebyte API

Project description

rebyte-langchain

Static Badge PyPI PyPI - Downloads GitHub issues readthedocs License

rebyte-langchain is a Python library to access the ReByte Agent REST API. This library enables you to use rebyte in a langchain-like style.

Features

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

Install

pip install rebyte-langchain

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.

Simple Demo

# import packages
from rebyte_langchain.rebyte_langchain import RebyteEndpoint
import os
import asyncio
from langchain.schema.messages import HumanMessage
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler

# required keys & config
# You can set REBYTE_API_KEY as an environment variable 
os.environ['REBYTE_API_KEY'] = "<rebyte_api_key>"
# Or pass it as an argument to the RebyteEndpoint constructor
test_rebyte_api_key:str = "<rebyte_api_key>"

# create an agent on rebyte platform and get the project_id and agent_id
# https://rebyte.ai/api/sdk/p/{test_project_id}/a/{test_agent_id}/r
# An example agent for Mark Zuckerberg: https://rebyte.ai/p/d4e521a67bb8189c2189/callable/a38ec8c60c3925696385/editor
test_project_id:str = "d4e521a67bb8189c2189"
test_agent_id:str = "a38ec8c60c3925696385"

# 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 None when the agent has no stateful actions.
test_session_id:str = None

# test input
human_messages = [HumanMessage(content="Who are you")]

def generate(stream = False):
  model = RebyteEndpoint(
    rebyte_api_key=test_rebyte_api_key,
    project_id=test_project_id,
    agent_id=test_agent_id,
    session_id=test_session_id,
    streaming=stream
  )
  response = model.generate([human_messages],
                            callbacks=[StreamingStdOutCallbackHandler()]
                            )
  return response

async def agenerate(stream = False):
  model = RebyteEndpoint(
    rebyte_api_key=test_rebyte_api_key,
    project_id=test_project_id,
    agent_id=test_agent_id,
    session_id=test_session_id,
    streaming=stream
  )
  response = await model.agenerate(messages=
                                   [human_messages],
                                   callbacks=[StreamingStdOutCallbackHandler()]
                                   )
  return response

if __name__ == "__main__":
  print("\n\nTEST GENERATE\n\n")
  response = generate(stream=True)

  print("\n\nTEST AGENERATE\n\n")
  loop = asyncio.get_event_loop()
  loop.run_until_complete(agenerate(stream=True))

Please see more examples in main.py and example.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_langchain-0.0.11.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

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

rebyte_langchain-0.0.11-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file rebyte_langchain-0.0.11.tar.gz.

File metadata

  • Download URL: rebyte_langchain-0.0.11.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for rebyte_langchain-0.0.11.tar.gz
Algorithm Hash digest
SHA256 53dbd0714ae9d49b5830453977a7287baf3195040f4eb5f8b7871f009efc8dd2
MD5 a8d6c9373cc4a80a8f89c976084200dd
BLAKE2b-256 9bc2b401e38880e754f935a7df0d4a81e78a11d9cb2bfdfb02e03d048a294773

See more details on using hashes here.

File details

Details for the file rebyte_langchain-0.0.11-py3-none-any.whl.

File metadata

File hashes

Hashes for rebyte_langchain-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 66c2b52e56a50b2f6e06f99fffd4550cc8e56c962d6de9efc71b1ea30a7dcf5d
MD5 f6ea27a6d6a0912b9f51ad3a702e8e09
BLAKE2b-256 dc7a824f86a9c3d49389027be8306503b2631d1f509ff18adb30cc7b22bf41b8

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