2025-04-19 13:38:48 +01:00
|
|
|
|
|
|
|
|
from . request_response_spec import RequestResponse, RequestResponseSpec
|
|
|
|
|
from .. schema import EmbeddingsReqeust, EmbeddingsResponse
|
|
|
|
|
|
|
|
|
|
class EmbeddingsClient(RequestResponse):
|
|
|
|
|
async def embed(self, text, timeout=30):
|
2025-04-19 13:41:33 +01:00
|
|
|
|
2025-04-19 13:38:48 +01:00
|
|
|
resp = await self.request(
|
|
|
|
|
EmbeddingsRequest(
|
|
|
|
|
text = text
|
|
|
|
|
),
|
|
|
|
|
timeout=timeout
|
|
|
|
|
)
|
2025-04-19 13:41:33 +01:00
|
|
|
|
|
|
|
|
if resp.error:
|
|
|
|
|
raise RuntimeError(resp.error.message)
|
|
|
|
|
|
2025-04-19 13:38:48 +01:00
|
|
|
return resp.vectors
|
|
|
|
|
|
|
|
|
|
class EmbeddingsClientSpec(RequestResponseSpec):
|
|
|
|
|
def __init__(
|
|
|
|
|
self, request_name, response_name,
|
|
|
|
|
):
|
|
|
|
|
super(EmbeddingsRequestResponseSpec, self).__init__(
|
|
|
|
|
request_name = request_name,
|
|
|
|
|
request_schema = EmbeddingsRequest,
|
|
|
|
|
response_name = response_name,
|
|
|
|
|
response_schema = EmbeddingsResponse,
|
|
|
|
|
impl = EmbeddingsClient,
|
|
|
|
|
)
|
|
|
|
|
|