mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-22 03:31:02 +02:00
- Keeps processing in different flows separate so that data can go to different stores / collections etc. - Potentially supports different processing flows - Tidies the processing API with common base-classes for e.g. LLMs, and automatic configuration of 'clients' to use the right queue names in a flow
30 lines
955 B
Python
30 lines
955 B
Python
|
|
from . request_response_spec import RequestResponse, RequestResponseSpec
|
|
from .. schema import TextCompletionRequest, TextCompletionResponse
|
|
|
|
class TextCompletionClient(RequestResponse):
|
|
async def text_completion(self, system, prompt, timeout=600):
|
|
resp = await self.request(
|
|
TextCompletionRequest(
|
|
system = system, prompt = prompt
|
|
),
|
|
timeout=timeout
|
|
)
|
|
|
|
if resp.error:
|
|
raise RuntimeError(resp.error.message)
|
|
|
|
return resp.response
|
|
|
|
class TextCompletionClientSpec(RequestResponseSpec):
|
|
def __init__(
|
|
self, request_name, response_name,
|
|
):
|
|
super(TextCompletionClientSpec, self).__init__(
|
|
request_name = request_name,
|
|
request_schema = TextCompletionRequest,
|
|
response_name = response_name,
|
|
response_schema = TextCompletionResponse,
|
|
impl = TextCompletionClient,
|
|
)
|
|
|