Feature/librarian (#310)

* Add fields to library schema

* Added list function, incomplete

* Librarian list operation
This commit is contained in:
cybermaggedon 2025-03-11 16:52:59 +00:00 committed by GitHub
parent 5575e885e5
commit f1559c5944
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 177 additions and 27 deletions

View file

@ -223,11 +223,11 @@ class Processor(ConsumerProducer):
self.librarian.handle_document_embeddings(msg)
async def load_document(self, id, document):
async def load_document(self, document):
doc = Document(
metadata = Metadata(
id = id,
id = document.id,
metadata = document.metadata,
user = document.user,
collection = document.collection
@ -237,14 +237,14 @@ class Processor(ConsumerProducer):
self.document_load.send(None, doc)
async def load_text(self, id, document):
async def load_text(self, document):
text = base64.b64decode(document.document)
text = text.decode("utf-8")
doc = TextDocument(
metadata = Metadata(
id = id,
id = document.id,
metadata = document.metadata,
user = document.user,
collection = document.collection
@ -259,19 +259,33 @@ class Processor(ConsumerProducer):
if v.operation is None:
raise RequestError("Null operation")
print("op", v.operation)
if v.operation == "add":
if (
v.id and v.document and v.document.metadata and
v.document and v.document.id and v.document.metadata and
v.document.document and v.document.kind
):
return partial(
self.librarian.add,
id = v.id,
document = v.document,
)
else:
raise RequestError("Invalid call")
if v.operation == "list":
print("list", v)
print(v.user)
if v.user:
return partial(
self.librarian.list,
user = v.user,
collection = v.collection,
)
else:
print("BROK")
raise RequestError("Invalid call")
raise RequestError("Invalid operation: " + v.operation)
async def handle(self, msg):
@ -298,6 +312,7 @@ class Processor(ConsumerProducer):
try:
resp = await func()
print("->", resp)
except RequestError as e:
resp = LibrarianResponse(
error = Error(
@ -318,7 +333,7 @@ class Processor(ConsumerProducer):
await self.send(resp, properties={"id": id})
return
print("Send response...", flush=True)
print("Send response..!.", flush=True)
await self.send(resp, properties={"id": id})