mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-25 13:11:02 +02:00
* Tweak the structured query schema * Structure query service * Gateway support for nlp-query and structured-query * API support * Added CLI * Update tests * More tests
30 lines
No EOL
1.1 KiB
Python
30 lines
No EOL
1.1 KiB
Python
from ... schema import QuestionToStructuredQueryRequest, QuestionToStructuredQueryResponse
|
|
from ... messaging import TranslatorRegistry
|
|
|
|
from . requestor import ServiceRequestor
|
|
|
|
class NLPQueryRequestor(ServiceRequestor):
|
|
def __init__(
|
|
self, pulsar_client, request_queue, response_queue, timeout,
|
|
consumer, subscriber,
|
|
):
|
|
|
|
super(NLPQueryRequestor, self).__init__(
|
|
pulsar_client=pulsar_client,
|
|
request_queue=request_queue,
|
|
response_queue=response_queue,
|
|
request_schema=QuestionToStructuredQueryRequest,
|
|
response_schema=QuestionToStructuredQueryResponse,
|
|
subscription = subscriber,
|
|
consumer_name = consumer,
|
|
timeout=timeout,
|
|
)
|
|
|
|
self.request_translator = TranslatorRegistry.get_request_translator("nlp-query")
|
|
self.response_translator = TranslatorRegistry.get_response_translator("nlp-query")
|
|
|
|
def to_request(self, body):
|
|
return self.request_translator.to_pulsar(body)
|
|
|
|
def from_response(self, message):
|
|
return self.response_translator.from_response_with_completion(message) |