Package: rebyte
Rebyte Python LibraryThe 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.FeaturesGenerate streaming or non-streaming output.Use async or sync method.Support stateful agent memory with session_id.InstallationPython 3.7 and above is required.pipinstallrebyteIf already installed, update package to the latest version:pipinstall--upgraderebyteIf wishing to modify this package, clone and install in editable mode:gitclonehttps://github.com/ReByteAI/rebyte-python.gitcdrebyte-python
pipinstall-e.PrerequisitesReByte API KeyTo get your ReByte API key, follow these steps:Go to theReByte websiteand sign up for an account if you haven't already.Once you're logged in, go to Settings > API Keys.Generate a new API key by clicking on the "Generate" button.Prepare to use it during configuration.ReByte Agent CreationYou can follow the tutorial in the webpageReByte Quick Startto create your own agent. Or you can use agents in ReByte Community. Open an agent and clone to your personal project.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)APICall the ReByte agent in sync and nonstreaming method:fromrebyteimportRebyteAPIRequestorrequestor=RebyteAPIRequestor(key=<yourapi_key>,api_base=<rebyteendpoint,defaulttohttps://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 APIAsync support is available in the API by prependingato a network-bound method:importasynciofromrebyteimportRebyteAPIRequestorasyncdefmain():requestor=RebyteAPIRequestor(key=<yourapi_key>,api_base=<rebyteendpoint,defaulttohttps://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,_,_=awaitrequestor.arequest(method="POST",url=path,params=data,stream=False)print(res.data['run']['results'][0][0]["value"]["content"])asyncio.run(main())Stream APIStreaming support is available in the API by set request instream=Truemode:fromrebyteimportRebyteAPIRequestorrequestor=RebyteAPIRequestor(key=<yourapi_key>,api_base=<rebyteendpoint,defaulttohttps://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":{},"stream":True}res,_,_=requestor.request(method="POST",url=path,params=data,stream=True)formsginres:# print streaming output messagestream_text=msg.get_stream_chunk()ifmsgandstream_text:print(stream_text)API sessionfromrebyteimportRebyteAPIRequestorrequestor=RebyteAPIRequestor(key=<yourapi_key>,api_base=<rebyteendpoint,defaulttohttps://rebyte.ai>)path=f'/api/sdk/p/{project_id}/a/{agent_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 intest/andexamples.ipynb.DocumentationMore information can be found on theReByte Documentation Site.