2024-12-02 17:41:30 +00:00
|
|
|
|
2024-12-06 13:37:44 +00:00
|
|
|
from .. schema import GraphRagQuery, GraphRagResponse
|
|
|
|
|
from .. schema import graph_rag_request_queue
|
|
|
|
|
from .. schema import graph_rag_response_queue
|
2024-12-02 17:41:30 +00:00
|
|
|
|
|
|
|
|
from . endpoint import ServiceEndpoint
|
2024-12-06 23:56:10 +00:00
|
|
|
from . requestor import ServiceRequestor
|
2024-12-02 17:41:30 +00:00
|
|
|
|
2024-12-06 23:56:10 +00:00
|
|
|
class GraphRagRequestor(ServiceRequestor):
|
2025-02-12 23:39:24 +00:00
|
|
|
def __init__(self, pulsar_client, timeout, auth):
|
2024-12-02 17:41:30 +00:00
|
|
|
|
2024-12-06 23:56:10 +00:00
|
|
|
super(GraphRagRequestor, self).__init__(
|
2025-02-12 23:39:24 +00:00
|
|
|
pulsar_client=pulsar_client,
|
2024-12-02 17:41:30 +00:00
|
|
|
request_queue=graph_rag_request_queue,
|
|
|
|
|
response_queue=graph_rag_response_queue,
|
|
|
|
|
request_schema=GraphRagQuery,
|
|
|
|
|
response_schema=GraphRagResponse,
|
|
|
|
|
timeout=timeout,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def to_request(self, body):
|
|
|
|
|
return GraphRagQuery(
|
|
|
|
|
query=body["query"],
|
|
|
|
|
user=body.get("user", "trustgraph"),
|
|
|
|
|
collection=body.get("collection", "default"),
|
2025-03-12 17:51:47 +00:00
|
|
|
entity_limit=body.get("entity-limit", 50),
|
|
|
|
|
triple_limit=body.get("triple-limit", 30),
|
|
|
|
|
doc_limit=body.get("doc-limit", 1000),
|
2024-12-02 17:41:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def from_response(self, message):
|
2024-12-06 23:56:10 +00:00
|
|
|
return { "response": message.response }, True
|
2024-12-02 17:41:30 +00:00
|
|
|
|