mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-20 18:51:03 +02:00
Working, can add documents
This commit is contained in:
parent
385b02021f
commit
b0613fe0de
4 changed files with 9 additions and 25 deletions
|
|
@ -10,7 +10,7 @@ url = "http://localhost:8088/api/v1/"
|
|||
|
||||
############################################################################
|
||||
|
||||
id = "http://trustgraph.ai/doc/12345678"
|
||||
id = "http://trustgraph.ai/doc/9fdee98b-b259-40ac-bcb9-8e82ccedeb04"
|
||||
|
||||
with open("docs/README.cats", "rb") as f:
|
||||
doc = base64.b64encode(f.read()).decode("utf-8")
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ url = "http://localhost:8088/api/v1/"
|
|||
|
||||
############################################################################
|
||||
|
||||
id = "http://trustgraph.ai/doc/12345678"
|
||||
id = "http://trustgraph.ai/doc/6d034da9-2759-45c2-af24-14db7f4c44c2"
|
||||
|
||||
source = "../sources/20160001634.pdf"
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,9 @@ class LibrarianRequestor(ServiceRequestor):
|
|||
|
||||
def to_request(self, body):
|
||||
|
||||
print("to_request")
|
||||
# Content gets base64 decoded & encoded again. It at least makes
|
||||
# sure payload is valid base64.
|
||||
|
||||
if "document-metadata" in body:
|
||||
dm = to_document_metadata(body["document-metadata"])
|
||||
else:
|
||||
|
|
@ -43,9 +45,6 @@ class LibrarianRequestor(ServiceRequestor):
|
|||
else:
|
||||
criteria = None
|
||||
|
||||
print("a")
|
||||
print(type(body["content"]))
|
||||
|
||||
if "content" in body:
|
||||
content = base64.b64decode(
|
||||
body["content"].encode("utf-8")
|
||||
|
|
@ -53,17 +52,13 @@ class LibrarianRequestor(ServiceRequestor):
|
|||
else:
|
||||
content = None
|
||||
|
||||
print("b")
|
||||
|
||||
print(type(content))
|
||||
|
||||
return LibrarianRequest(
|
||||
operation = body.get("operation", None),
|
||||
document_id = body.get("document-id", None),
|
||||
processing_id = body.get("processing-id", None),
|
||||
document_metadata = dm,
|
||||
processing_metadata = pm,
|
||||
content = content,
|
||||
content = base64.b64encode(content).decode("utf-8"),
|
||||
user = body.get("user", None),
|
||||
collection = body.get("collection", None),
|
||||
criteria = criteria,
|
||||
|
|
@ -71,8 +66,6 @@ class LibrarianRequestor(ServiceRequestor):
|
|||
|
||||
def from_response(self, message):
|
||||
|
||||
print("from_response")
|
||||
|
||||
response = {}
|
||||
|
||||
if message.document_metadata:
|
||||
|
|
@ -81,9 +74,7 @@ class LibrarianRequestor(ServiceRequestor):
|
|||
)
|
||||
|
||||
if message.content:
|
||||
response["content"] = base64.b64encode(
|
||||
message["content"]
|
||||
).decode("utf-8")
|
||||
response["content"] = message.content
|
||||
|
||||
if message.document_metadatas:
|
||||
response["document-metadatas"] = [
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ from .. knowledge import hash
|
|||
from .. exceptions import RequestError
|
||||
from . table_store import TableStore
|
||||
from . blob_store import BlobStore
|
||||
import base64
|
||||
|
||||
import uuid
|
||||
|
||||
|
|
@ -29,8 +30,6 @@ class Librarian:
|
|||
|
||||
async def add_document(self, request):
|
||||
|
||||
print(request)
|
||||
|
||||
if request.document_metadata.kind not in (
|
||||
"text/plain", "application/pdf"
|
||||
):
|
||||
|
|
@ -41,12 +40,10 @@ class Librarian:
|
|||
# Create object ID for blob
|
||||
object_id = uuid.uuid4()
|
||||
|
||||
print("HERE")
|
||||
self.blob_store.add(object_id, request.content,
|
||||
self.blob_store.add(object_id, base64.b64decode(request.content),
|
||||
request.document_metadata.kind)
|
||||
|
||||
self.table_store.add_document(request.document_metadata, object_id)
|
||||
print("HERE2")
|
||||
|
||||
# if document.kind == "application/pdf":
|
||||
# await self.load_document(document)
|
||||
|
|
@ -91,10 +88,6 @@ class Librarian:
|
|||
|
||||
raise RuntimeError("Not implemented")
|
||||
|
||||
|
||||
|
||||
print("list")
|
||||
|
||||
info = self.table_store.list(user, collection)
|
||||
|
||||
print(">>", info)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue