mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-21 11:11:03 +02:00
Multiple streams working
This commit is contained in:
parent
e606753f51
commit
5f08220ef1
2 changed files with 9 additions and 20 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import uuid
|
||||||
|
|
||||||
from . embeddings import EmbeddingsRequestor
|
from . embeddings import EmbeddingsRequestor
|
||||||
from . agent import AgentRequestor
|
from . agent import AgentRequestor
|
||||||
|
|
@ -27,9 +28,9 @@ request_response_dispatchers = {
|
||||||
}
|
}
|
||||||
|
|
||||||
receive_dispatchers = {
|
receive_dispatchers = {
|
||||||
"triples-store": TriplesStream,
|
"triples": TriplesStream,
|
||||||
"graph-embeddings-store": GraphEmbeddingsStream,
|
"graph-embeddings": GraphEmbeddingsStream,
|
||||||
"document-embeddings-store": DocumentEmbeddingsStream,
|
"document-embeddings": DocumentEmbeddingsStream,
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestDispatcher:
|
class TestDispatcher:
|
||||||
|
|
@ -130,9 +131,6 @@ class DispatcherManager:
|
||||||
flow = params.get("flow")
|
flow = params.get("flow")
|
||||||
kind = params.get("kind")
|
kind = params.get("kind")
|
||||||
|
|
||||||
# FIXME: What?!?!
|
|
||||||
kind += "-store"
|
|
||||||
|
|
||||||
if flow not in self.flows:
|
if flow not in self.flows:
|
||||||
raise RuntimeError("Invalid flow")
|
raise RuntimeError("Invalid flow")
|
||||||
|
|
||||||
|
|
@ -141,28 +139,25 @@ class DispatcherManager:
|
||||||
|
|
||||||
key = (flow, kind)
|
key = (flow, kind)
|
||||||
|
|
||||||
if key in self.dispatchers:
|
|
||||||
return self.dispatchers[key]
|
|
||||||
|
|
||||||
intf_defs = self.flows[flow]["interfaces"]
|
intf_defs = self.flows[flow]["interfaces"]
|
||||||
|
|
||||||
if kind not in intf_defs:
|
if kind not in intf_defs:
|
||||||
raise RuntimeError("This kind not supported by flow")
|
raise RuntimeError("This kind not supported by flow")
|
||||||
|
|
||||||
qconfig = intf_defs[kind]
|
# FIXME: The -store bit, does it make sense?
|
||||||
|
qconfig = intf_defs[kind + "-store"]
|
||||||
|
|
||||||
|
id = str(uuid.uuid4())
|
||||||
dispatcher = receive_dispatchers[kind](
|
dispatcher = receive_dispatchers[kind](
|
||||||
pulsar_client = self.pulsar_client,
|
pulsar_client = self.pulsar_client,
|
||||||
ws = ws,
|
ws = ws,
|
||||||
running = running,
|
running = running,
|
||||||
# FIXME!
|
# FIXME!
|
||||||
queue = qconfig,
|
queue = qconfig,
|
||||||
consumer = f"api-gateway-{flow}-{kind}-request",
|
consumer = f"api-gateway-{id}",
|
||||||
subscriber = f"api-gateway-{flow}-{kind}-request",
|
subscriber = f"api-gateway-{id}",
|
||||||
)
|
)
|
||||||
|
|
||||||
self.dispatchers[key] = dispatcher
|
|
||||||
|
|
||||||
return dispatcher
|
return dispatcher
|
||||||
|
|
||||||
async def process(self, data, responder, params):
|
async def process(self, data, responder, params):
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,10 @@ class SocketEndpoint:
|
||||||
|
|
||||||
async def listener(self, ws, dispatcher, running):
|
async def listener(self, ws, dispatcher, running):
|
||||||
|
|
||||||
print("In listener...!!!!!!!!!!!!!!!!!!!!")
|
|
||||||
async for msg in ws:
|
async for msg in ws:
|
||||||
|
|
||||||
# On error, finish
|
# On error, finish
|
||||||
print ("mt:", msg.type)
|
|
||||||
if msg.type == WSMsgType.TEXT:
|
if msg.type == WSMsgType.TEXT:
|
||||||
print("YER!!!!!")
|
|
||||||
await dispatcher.receive(msg)
|
await dispatcher.receive(msg)
|
||||||
continue
|
continue
|
||||||
elif msg.type == WSMsgType.BINARY:
|
elif msg.type == WSMsgType.BINARY:
|
||||||
|
|
@ -65,17 +62,14 @@ class SocketEndpoint:
|
||||||
|
|
||||||
running = Running()
|
running = Running()
|
||||||
|
|
||||||
print("Create...")
|
|
||||||
dispatcher = await self.dispatcher(
|
dispatcher = await self.dispatcher(
|
||||||
ws, running, request.match_info
|
ws, running, request.match_info
|
||||||
)
|
)
|
||||||
|
|
||||||
print("Create worker...")
|
|
||||||
worker_task = tg.create_task(
|
worker_task = tg.create_task(
|
||||||
self.worker(ws, dispatcher, running)
|
self.worker(ws, dispatcher, running)
|
||||||
)
|
)
|
||||||
|
|
||||||
print("Create listener")
|
|
||||||
lsnr_task = tg.create_task(
|
lsnr_task = tg.create_task(
|
||||||
self.listener(ws, dispatcher, running)
|
self.listener(ws, dispatcher, running)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue