mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-04-25 00:16:23 +02:00
API-side support for Wikipedia, DBpedia and internet search functions This incorporates a refactor of the API code to break it up, separate classes for endpoints to reduce duplication
30 lines
908 B
Python
30 lines
908 B
Python
|
|
from ... schema import AgentRequest, AgentResponse
|
|
from ... schema import agent_request_queue
|
|
from ... schema import agent_response_queue
|
|
|
|
from . endpoint import MultiResponseServiceEndpoint
|
|
|
|
class AgentEndpoint(MultiResponseServiceEndpoint):
|
|
def __init__(self, pulsar_host, timeout):
|
|
|
|
super(AgentEndpoint, self).__init__(
|
|
pulsar_host=pulsar_host,
|
|
request_queue=agent_request_queue,
|
|
response_queue=agent_response_queue,
|
|
request_schema=AgentRequest,
|
|
response_schema=AgentResponse,
|
|
endpoint_path="/api/v1/agent",
|
|
timeout=timeout,
|
|
)
|
|
|
|
def to_request(self, body):
|
|
return AgentRequest(
|
|
question=body["question"]
|
|
)
|
|
|
|
def from_response(self, message):
|
|
if message.answer:
|
|
return { "answer": message.answer }, True
|
|
else:
|
|
return {}, False
|