mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-17 17:21:02 +02:00
Tidying clients
This commit is contained in:
parent
93bb2adb9e
commit
dc0bcba269
2 changed files with 10 additions and 9 deletions
|
|
@ -4,12 +4,17 @@ from .. schema import EmbeddingsReqeust, EmbeddingsResponse
|
|||
|
||||
class EmbeddingsClient(RequestResponse):
|
||||
async def embed(self, text, timeout=30):
|
||||
|
||||
resp = await self.request(
|
||||
EmbeddingsRequest(
|
||||
text = text
|
||||
),
|
||||
timeout=timeout
|
||||
)
|
||||
|
||||
if resp.error:
|
||||
raise RuntimeError(resp.error.message)
|
||||
|
||||
return resp.vectors
|
||||
|
||||
class EmbeddingsClientSpec(RequestResponseSpec):
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ from .... schema import PromptRequest, PromptResponse, Error
|
|||
from .... schema import TextCompletionRequest, TextCompletionResponse
|
||||
|
||||
from .... base import FlowProcessor
|
||||
from .... base import ProducerSpec, ConsumerSpec, RequestResponseSpec
|
||||
from .... base import ProducerSpec, ConsumerSpec, TextCompletionSpec
|
||||
|
||||
from . prompt_manager import PromptConfiguration, Prompt, PromptManager
|
||||
|
||||
|
|
@ -43,11 +43,9 @@ class Processor(FlowProcessor):
|
|||
)
|
||||
|
||||
self.register_specification(
|
||||
RequestResponseSpec(
|
||||
TextCompletionSpec(
|
||||
request_name = "text-completion-request",
|
||||
request_schema = TextCompletionRequest,
|
||||
response_name = "text-completion-response",
|
||||
response_schema = TextCompletionResponse,
|
||||
)
|
||||
)
|
||||
|
||||
|
|
@ -139,14 +137,12 @@ class Processor(FlowProcessor):
|
|||
print(system, flush=True)
|
||||
print(prompt, flush=True)
|
||||
|
||||
resp = await flow("text-completion-request").request(
|
||||
TextCompletionRequest(
|
||||
system=system, prompt=prompt
|
||||
),
|
||||
resp = await flow("text-completion-request").text_completion(
|
||||
system = system, prompt = prompt,
|
||||
)
|
||||
|
||||
try:
|
||||
return resp.response
|
||||
return resp
|
||||
except Exception as e:
|
||||
print("LLM Exception:", e, flush=True)
|
||||
return None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue