Skip to main content

Python langchain-like client library for the Rebyte API

Project description

rebyte-langchain

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

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 callable_id
# https://rebyte.ai/api/sdk/p/{test_project_id}/a/{test_callable_id}/r
test_project_id:str = "<test_project_id>"
test_callable_id:str = "<test_callable_id>"

# You may use any string as session_id 
# Note that you must set session_id if you use any states ("memory") in your agent, such as KV storage. Otherwise, the agent will raise error
# Or you can leave it as None when the agent has no states. The system will generate a random session_id for you.
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,
    callable_id=test_callable_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,
    callable_id=test_callable_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.3.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.

rebyte_langchain-0.0.3-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for rebyte_langchain-0.0.3.tar.gz
Algorithm Hash digest
SHA256 0d7dc68485142c23025586b7aec3dd61c39da31c9e6106983f11dc3e1689b22d
MD5 26a14e335d35c29af2cc9f8cb35c6d3b
BLAKE2b-256 ce9b49325e90c068b6ca47b88ad1d0272886d402b0bbfab430d6d7f7579d76a0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rebyte_langchain-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9eef1f2cb248c5cb9d53e9be2d6de3b9dbfa8d9726be9c82603fa99401d4930e
MD5 a58578161c80e9f526e2e006160ddf6b
BLAKE2b-256 1d0440796c1b77cb3097ad663a6568a60088a7232e71e0ed683b1ae1edfaf7fb

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