mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-05-13 01:02:37 +02:00
Feature/translator classes (#414)
Pull the JSON/Pulsar message translation into a separate module, will be useful for other comms channels
This commit is contained in:
parent
3fa004d628
commit
a4e2f67cb1
34 changed files with 1506 additions and 377 deletions
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
from ... schema import GraphRagQuery, GraphRagResponse
|
||||
from ... messaging import TranslatorRegistry
|
||||
|
||||
from . requestor import ServiceRequestor
|
||||
|
||||
|
|
@ -20,17 +21,12 @@ class GraphRagRequestor(ServiceRequestor):
|
|||
timeout=timeout,
|
||||
)
|
||||
|
||||
self.request_translator = TranslatorRegistry.get_request_translator("graph-rag")
|
||||
self.response_translator = TranslatorRegistry.get_response_translator("graph-rag")
|
||||
|
||||
def to_request(self, body):
|
||||
return GraphRagQuery(
|
||||
query=body["query"],
|
||||
user=body.get("user", "trustgraph"),
|
||||
collection=body.get("collection", "default"),
|
||||
entity_limit=int(body.get("entity-limit", 50)),
|
||||
triple_limit=int(body.get("triple-limit", 30)),
|
||||
max_subgraph_size=int(body.get("max-subgraph-size", 1000)),
|
||||
max_path_length=int(body.get("max-path-length", 2)),
|
||||
)
|
||||
return self.request_translator.to_pulsar(body)
|
||||
|
||||
def from_response(self, message):
|
||||
return { "response": message.response }, True
|
||||
return self.response_translator.from_response_with_completion(message)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue