mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-22 03:31:02 +02:00
Text & doc load working
This commit is contained in:
parent
f8b888855d
commit
8e9c72fda5
8 changed files with 145 additions and 42 deletions
33
test-api/test-llm2-api
Executable file
33
test-api/test-llm2-api
Executable file
|
|
@ -0,0 +1,33 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
|
||||||
|
url = "http://localhost:8088/api/v1/"
|
||||||
|
|
||||||
|
############################################################################
|
||||||
|
|
||||||
|
input = {
|
||||||
|
"system": "",
|
||||||
|
"prompt": "Add 2 and 3"
|
||||||
|
}
|
||||||
|
|
||||||
|
resp = requests.post(
|
||||||
|
f"{url}text-completion",
|
||||||
|
json=input,
|
||||||
|
)
|
||||||
|
|
||||||
|
if resp.status_code != 200:
|
||||||
|
raise RuntimeError(f"Status code: {resp.status_code}")
|
||||||
|
|
||||||
|
resp = resp.json()
|
||||||
|
|
||||||
|
if "error" in resp:
|
||||||
|
print(f"Error: {resp['error']}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
print(resp["response"])
|
||||||
|
|
||||||
|
############################################################################
|
||||||
|
|
||||||
|
|
@ -5,7 +5,7 @@ import json
|
||||||
import sys
|
import sys
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
url = "http://localhost:8088/api/v1/"
|
url = "http://localhost:8088/api/v1/flow/0000/document-load"
|
||||||
|
|
||||||
############################################################################
|
############################################################################
|
||||||
|
|
||||||
|
|
@ -88,10 +88,7 @@ input = {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resp = requests.post(
|
resp = requests.post(url, json=input)
|
||||||
f"{url}load/document",
|
|
||||||
json=input,
|
|
||||||
)
|
|
||||||
|
|
||||||
resp = resp.json()
|
resp = resp.json()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import json
|
||||||
import sys
|
import sys
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
url = "http://localhost:8088/api/v1/"
|
url = "http://localhost:8088/api/v1/flow/0000/text-load"
|
||||||
|
|
||||||
############################################################################
|
############################################################################
|
||||||
|
|
||||||
|
|
@ -85,10 +85,7 @@ input = {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resp = requests.post(
|
resp = requests.post(url, json=input)
|
||||||
f"{url}load/text",
|
|
||||||
json=input,
|
|
||||||
)
|
|
||||||
|
|
||||||
resp = resp.json()
|
resp = resp.json()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,18 @@
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
from .. schema import Document, Metadata
|
from ... schema import Document, Metadata
|
||||||
from .. schema import document_ingest_queue
|
|
||||||
|
|
||||||
from . sender import ServiceSender
|
from . sender import ServiceSender
|
||||||
from . serialize import to_subgraph
|
from . serialize import to_subgraph
|
||||||
|
|
||||||
class DocumentLoadSender(ServiceSender):
|
class DocumentLoad(ServiceSender):
|
||||||
def __init__(self, pulsar_client):
|
def __init__(self, pulsar_client, queue):
|
||||||
|
|
||||||
super(DocumentLoadSender, self).__init__(
|
super(DocumentLoad, self).__init__(
|
||||||
pulsar_client=pulsar_client,
|
pulsar_client = pulsar_client,
|
||||||
request_queue=document_ingest_queue,
|
queue = queue,
|
||||||
request_schema=Document,
|
schema = Document,
|
||||||
)
|
)
|
||||||
|
|
||||||
def to_request(self, body):
|
def to_request(self, body):
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@ from . triples_query import TriplesQueryRequestor
|
||||||
from . embeddings import EmbeddingsRequestor
|
from . embeddings import EmbeddingsRequestor
|
||||||
from . graph_embeddings_query import GraphEmbeddingsQueryRequestor
|
from . graph_embeddings_query import GraphEmbeddingsQueryRequestor
|
||||||
from . prompt import PromptRequestor
|
from . prompt import PromptRequestor
|
||||||
|
from . text_load import TextLoad
|
||||||
|
from . document_load import DocumentLoad
|
||||||
|
|
||||||
from . triples_stream import TriplesStream
|
from . triples_stream import TriplesStream
|
||||||
from . graph_embeddings_stream import GraphEmbeddingsStream
|
from . graph_embeddings_stream import GraphEmbeddingsStream
|
||||||
|
|
@ -32,6 +34,11 @@ request_response_dispatchers = {
|
||||||
"triples-query": TriplesQueryRequestor,
|
"triples-query": TriplesQueryRequestor,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sender_dispatchers = {
|
||||||
|
"text-load": TextLoad,
|
||||||
|
"document-load": DocumentLoad,
|
||||||
|
}
|
||||||
|
|
||||||
receive_dispatchers = {
|
receive_dispatchers = {
|
||||||
"triples": TriplesStream,
|
"triples": TriplesStream,
|
||||||
"graph-embeddings": GraphEmbeddingsStream,
|
"graph-embeddings": GraphEmbeddingsStream,
|
||||||
|
|
@ -141,9 +148,6 @@ class DispatcherManager:
|
||||||
if flow not in self.flows:
|
if flow not in self.flows:
|
||||||
raise RuntimeError("Invalid flow")
|
raise RuntimeError("Invalid flow")
|
||||||
|
|
||||||
if kind not in request_response_dispatchers:
|
|
||||||
raise RuntimeError("Invalid kind")
|
|
||||||
|
|
||||||
key = (flow, kind)
|
key = (flow, kind)
|
||||||
|
|
||||||
if key in self.dispatchers:
|
if key in self.dispatchers:
|
||||||
|
|
@ -156,15 +160,23 @@ class DispatcherManager:
|
||||||
|
|
||||||
qconfig = intf_defs[kind]
|
qconfig = intf_defs[kind]
|
||||||
|
|
||||||
dispatcher = request_response_dispatchers[kind](
|
if kind in request_response_dispatchers:
|
||||||
pulsar_client = self.pulsar_client,
|
dispatcher = request_response_dispatchers[kind](
|
||||||
request_queue = qconfig["request"],
|
pulsar_client = self.pulsar_client,
|
||||||
response_queue = qconfig["response"],
|
request_queue = qconfig["request"],
|
||||||
timeout = 120,
|
response_queue = qconfig["response"],
|
||||||
consumer = f"api-gateway-{flow}-{kind}-request",
|
timeout = 120,
|
||||||
subscriber = f"api-gateway-{flow}-{kind}-request",
|
consumer = f"api-gateway-{flow}-{kind}-request",
|
||||||
)
|
subscriber = f"api-gateway-{flow}-{kind}-request",
|
||||||
|
)
|
||||||
|
elif kind in sender_dispatchers:
|
||||||
|
dispatcher = sender_dispatchers[kind](
|
||||||
|
pulsar_client = self.pulsar_client,
|
||||||
|
queue = qconfig,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
raise RuntimeError("Invalid kind")
|
||||||
|
|
||||||
await dispatcher.start()
|
await dispatcher.start()
|
||||||
|
|
||||||
self.dispatchers[key] = dispatcher
|
self.dispatchers[key] = dispatcher
|
||||||
|
|
|
||||||
|
|
@ -15,18 +15,20 @@ class ServiceSender:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
pulsar_client,
|
pulsar_client,
|
||||||
request_queue, request_schema,
|
queue, schema,
|
||||||
):
|
):
|
||||||
|
|
||||||
self.pub = Publisher(
|
self.pub = Publisher(
|
||||||
pulsar_client, request_queue,
|
pulsar_client, queue,
|
||||||
schema=request_schema,
|
schema=schema,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def start(self):
|
async def start(self):
|
||||||
|
|
||||||
await self.pub.start()
|
await self.pub.start()
|
||||||
|
|
||||||
|
async def stop(self):
|
||||||
|
await self.pub.stop()
|
||||||
|
|
||||||
def to_request(self, request):
|
def to_request(self, request):
|
||||||
raise RuntimeError("Not defined")
|
raise RuntimeError("Not defined")
|
||||||
|
|
||||||
|
|
@ -39,6 +41,8 @@ class ServiceSender:
|
||||||
if responder:
|
if responder:
|
||||||
await responder({}, True)
|
await responder({}, True)
|
||||||
|
|
||||||
|
return {}
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
||||||
logging.error(f"Exception: {e}")
|
logging.error(f"Exception: {e}")
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,18 @@
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
from .. schema import TextDocument, Metadata
|
from ... schema import TextDocument, Metadata
|
||||||
from .. schema import text_ingest_queue
|
|
||||||
|
|
||||||
from . sender import ServiceSender
|
from . sender import ServiceSender
|
||||||
from . serialize import to_subgraph
|
from . serialize import to_subgraph
|
||||||
|
|
||||||
class TextLoadSender(ServiceSender):
|
class TextLoad(ServiceSender):
|
||||||
def __init__(self, pulsar_client):
|
def __init__(self, pulsar_client, queue):
|
||||||
|
|
||||||
super(TextLoadSender, self).__init__(
|
super(TextLoad, self).__init__(
|
||||||
pulsar_client=pulsar_client,
|
pulsar_client = pulsar_client,
|
||||||
request_queue=text_ingest_queue,
|
queue = queue,
|
||||||
request_schema=TextDocument,
|
schema = TextDocument,
|
||||||
)
|
)
|
||||||
|
|
||||||
def to_request(self, body):
|
def to_request(self, body):
|
||||||
|
|
|
||||||
62
trustgraph-flow/trustgraph/gateway/endpoint/manager.py
Normal file
62
trustgraph-flow/trustgraph/gateway/endpoint/manager.py
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
from aiohttp import web
|
||||||
|
|
||||||
|
from . constant_endpoint import ConstantEndpoint
|
||||||
|
from . variable_endpoint import VariableEndpoint
|
||||||
|
from . socket import SocketEndpoint
|
||||||
|
from . metrics import MetricsEndpoint
|
||||||
|
|
||||||
|
from .. dispatch.manager import DispatcherManager
|
||||||
|
|
||||||
|
class EndpointManager:
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self, dispatcher_manager, auth, prometheus_url, timeout=600
|
||||||
|
):
|
||||||
|
|
||||||
|
self.dispatcher_manager = dispatcher_manager
|
||||||
|
self.timeout = timeout
|
||||||
|
|
||||||
|
self.services = {
|
||||||
|
}
|
||||||
|
|
||||||
|
self.endpoints = [
|
||||||
|
ConstantEndpoint(
|
||||||
|
endpoint_path = "/api/v1/librarian", auth = auth,
|
||||||
|
dispatcher = dispatcher_manager.dispatch_librarian(),
|
||||||
|
),
|
||||||
|
ConstantEndpoint(
|
||||||
|
endpoint_path = "/api/v1/config", auth = auth,
|
||||||
|
dispatcher = dispatcher_manager.dispatch_config(),
|
||||||
|
),
|
||||||
|
ConstantEndpoint(
|
||||||
|
endpoint_path = "/api/v1/flow", auth = auth,
|
||||||
|
dispatcher = dispatcher_manager.dispatch_flow(),
|
||||||
|
),
|
||||||
|
MetricsEndpoint(
|
||||||
|
endpoint_path = "/api/v1/metrics",
|
||||||
|
prometheus_url = prometheus_url,
|
||||||
|
auth = auth,
|
||||||
|
),
|
||||||
|
VariableEndpoint(
|
||||||
|
endpoint_path = "/api/v1/flow/{flow}/{kind}",
|
||||||
|
auth = auth,
|
||||||
|
dispatcher = dispatcher_manager.dispatch_flow_service(),
|
||||||
|
),
|
||||||
|
SocketEndpoint(
|
||||||
|
endpoint_path = "/api/v1/flow/{flow}/receive/{kind}",
|
||||||
|
auth = auth,
|
||||||
|
dispatcher = dispatcher_manager.dispatch_flow_receive()
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
def add_routes(self, app):
|
||||||
|
for ep in self.endpoints:
|
||||||
|
ep.add_routes(app)
|
||||||
|
|
||||||
|
async def start(self):
|
||||||
|
for ep in self.endpoints:
|
||||||
|
await ep.start()
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue