mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-21 11:11: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:
|
with open("docs/README.cats", "rb") as f:
|
||||||
doc = base64.b64encode(f.read()).decode("utf-8")
|
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"
|
source = "../sources/20160001634.pdf"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,9 @@ class LibrarianRequestor(ServiceRequestor):
|
||||||
|
|
||||||
def to_request(self, body):
|
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:
|
if "document-metadata" in body:
|
||||||
dm = to_document_metadata(body["document-metadata"])
|
dm = to_document_metadata(body["document-metadata"])
|
||||||
else:
|
else:
|
||||||
|
|
@ -43,9 +45,6 @@ class LibrarianRequestor(ServiceRequestor):
|
||||||
else:
|
else:
|
||||||
criteria = None
|
criteria = None
|
||||||
|
|
||||||
print("a")
|
|
||||||
print(type(body["content"]))
|
|
||||||
|
|
||||||
if "content" in body:
|
if "content" in body:
|
||||||
content = base64.b64decode(
|
content = base64.b64decode(
|
||||||
body["content"].encode("utf-8")
|
body["content"].encode("utf-8")
|
||||||
|
|
@ -53,17 +52,13 @@ class LibrarianRequestor(ServiceRequestor):
|
||||||
else:
|
else:
|
||||||
content = None
|
content = None
|
||||||
|
|
||||||
print("b")
|
|
||||||
|
|
||||||
print(type(content))
|
|
||||||
|
|
||||||
return LibrarianRequest(
|
return LibrarianRequest(
|
||||||
operation = body.get("operation", None),
|
operation = body.get("operation", None),
|
||||||
document_id = body.get("document-id", None),
|
document_id = body.get("document-id", None),
|
||||||
processing_id = body.get("processing-id", None),
|
processing_id = body.get("processing-id", None),
|
||||||
document_metadata = dm,
|
document_metadata = dm,
|
||||||
processing_metadata = pm,
|
processing_metadata = pm,
|
||||||
content = content,
|
content = base64.b64encode(content).decode("utf-8"),
|
||||||
user = body.get("user", None),
|
user = body.get("user", None),
|
||||||
collection = body.get("collection", None),
|
collection = body.get("collection", None),
|
||||||
criteria = criteria,
|
criteria = criteria,
|
||||||
|
|
@ -71,8 +66,6 @@ class LibrarianRequestor(ServiceRequestor):
|
||||||
|
|
||||||
def from_response(self, message):
|
def from_response(self, message):
|
||||||
|
|
||||||
print("from_response")
|
|
||||||
|
|
||||||
response = {}
|
response = {}
|
||||||
|
|
||||||
if message.document_metadata:
|
if message.document_metadata:
|
||||||
|
|
@ -81,9 +74,7 @@ class LibrarianRequestor(ServiceRequestor):
|
||||||
)
|
)
|
||||||
|
|
||||||
if message.content:
|
if message.content:
|
||||||
response["content"] = base64.b64encode(
|
response["content"] = message.content
|
||||||
message["content"]
|
|
||||||
).decode("utf-8")
|
|
||||||
|
|
||||||
if message.document_metadatas:
|
if message.document_metadatas:
|
||||||
response["document-metadatas"] = [
|
response["document-metadatas"] = [
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ from .. knowledge import hash
|
||||||
from .. exceptions import RequestError
|
from .. exceptions import RequestError
|
||||||
from . table_store import TableStore
|
from . table_store import TableStore
|
||||||
from . blob_store import BlobStore
|
from . blob_store import BlobStore
|
||||||
|
import base64
|
||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
|
@ -29,8 +30,6 @@ class Librarian:
|
||||||
|
|
||||||
async def add_document(self, request):
|
async def add_document(self, request):
|
||||||
|
|
||||||
print(request)
|
|
||||||
|
|
||||||
if request.document_metadata.kind not in (
|
if request.document_metadata.kind not in (
|
||||||
"text/plain", "application/pdf"
|
"text/plain", "application/pdf"
|
||||||
):
|
):
|
||||||
|
|
@ -41,12 +40,10 @@ class Librarian:
|
||||||
# Create object ID for blob
|
# Create object ID for blob
|
||||||
object_id = uuid.uuid4()
|
object_id = uuid.uuid4()
|
||||||
|
|
||||||
print("HERE")
|
self.blob_store.add(object_id, base64.b64decode(request.content),
|
||||||
self.blob_store.add(object_id, request.content,
|
|
||||||
request.document_metadata.kind)
|
request.document_metadata.kind)
|
||||||
|
|
||||||
self.table_store.add_document(request.document_metadata, object_id)
|
self.table_store.add_document(request.document_metadata, object_id)
|
||||||
print("HERE2")
|
|
||||||
|
|
||||||
# if document.kind == "application/pdf":
|
# if document.kind == "application/pdf":
|
||||||
# await self.load_document(document)
|
# await self.load_document(document)
|
||||||
|
|
@ -91,10 +88,6 @@ class Librarian:
|
||||||
|
|
||||||
raise RuntimeError("Not implemented")
|
raise RuntimeError("Not implemented")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
print("list")
|
|
||||||
|
|
||||||
info = self.table_store.list(user, collection)
|
info = self.table_store.list(user, collection)
|
||||||
|
|
||||||
print(">>", info)
|
print(">>", info)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue