Skip to content

Commit

Permalink
update proto
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardobl committed Apr 22, 2024
1 parent 52c928e commit b20f09f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
grpcio==1.62.1
protobuf==5.26.1
https://github.com/riccardobl/openagents-grpc-proto/releases/download/v0.6/openagents_grpc_proto-PYTHON.tar.gz
https://github.com/riccardobl/openagents-grpc-proto/releases/download/v0.7.2/openagents_grpc_proto-PYTHON.tar.gz
faiss-cpu==1.8.0
numpy==1.21.2
packaging
33 changes: 33 additions & 0 deletions src/OpenAgentsNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import traceback
import json
import asyncio
import pickle

class BlobStorage:
def __init__(self, id, url, node):
Expand Down Expand Up @@ -85,8 +86,40 @@ def __init__(self, filters, meta, template, sockets):
self._sockets = sockets


def cacheSet(self, path, value, version=0, expireAt=0):
try:
dataBytes = pickle.dumps(value)
client = self._node.getClient()
CHUNK_SIZE = 1024
def write_data():
for j in range(0, len(dataBytes), CHUNK_SIZE):
chunk = bytes(dataBytes[j:min(j+CHUNK_SIZE, len(dataBytes))])
request = rpc_pb2.RpcCacheSetRequest(
key=path,
data=chunk,
expireAt=expireAt,
version=version
)
yield request
res=client.cacheSet(write_data())
return res.success
except Exception as e:
print("Error setting cache "+str(e))
return False


def cacheGet(self, path, lastVersion = 0):
try:
client = self._node.getClient()
bytesOut = bytearray()
for chunk in client.cacheGet(rpc_pb2.RpcCacheGetRequest(key=path, lastVersion = lastVersion)):
if not chunk.exists:
return None
bytesOut.extend(chunk.data)
return pickle.loads(bytesOut)
except Exception as e:
print("Error getting cache "+str(e))
return None

def _setNode(self, node):
self._node = node
Expand Down

0 comments on commit b20f09f

Please sign in to comment.