trustgraph/trustgraph-flow/trustgraph/gateway/dispatch/embeddings.py
cybermaggedon a70ae9793a
Flow API - update gateway (#357)
* Altered API to incorporate Flow IDs, refactored for dynamic start/stop of flows
* Gateway: Split endpoint / dispatcher for maintainability
2025-05-02 21:11:50 +01:00

30 lines
868 B
Python

from ... schema import EmbeddingsRequest, EmbeddingsResponse
from . requestor import ServiceRequestor
class EmbeddingsRequestor(ServiceRequestor):
def __init__(
self, pulsar_client, request_queue, response_queue, timeout,
consumer, subscriber,
):
super(EmbeddingsRequestor, self).__init__(
pulsar_client=pulsar_client,
request_queue=request_queue,
response_queue=response_queue,
request_schema=EmbeddingsRequest,
response_schema=EmbeddingsResponse,
subscription = subscriber,
consumer_name = consumer,
timeout=timeout,
)
def to_request(self, body):
return EmbeddingsRequest(
text=body["text"]
)
def from_response(self, message):
return { "vectors": message.vectors }, True