GitHub

API reference for Service.

Attributes

AttributeTypeDescription
resolverRequestResolver[EmbeddingRequest, E.AiError]

Functions

__init__

__init__(resolver, _embed_many) -> None
ParameterTypeDescription
resolverRequestResolver[EmbeddingRequest, E.AiError]
_embed_manyEmbedMany

embed

embed(input) -> Effect[EmbedResponse, E.AiError]

The vector of input. Concurrent calls (with the same batch_key) share one provider call; fails with the provider's AiError, or an InvalidOutputError one when the provider returns another number of vectors than it was given inputs.

ParameterTypeDescription
inputstr

Returns Effect[EmbedResponse, E.AiError]

def embed(self, input: str) -> Effect[EmbedResponse, E.AiError]:
    """The vector of ``input``. Concurrent calls (with the same
    ``batch_key``) share one provider call; fails with the provider's
    ``AiError``, or an ``InvalidOutputError`` one when the provider
    returns another number of vectors than it was given inputs."""
    return _request(EmbeddingRequest(input), self.resolver).with_span("EmbeddingModel.embed")

embed_many

embed_many(inputs) -> Effect[EmbedManyResponse, E.AiError]

The vectors of inputs in order, with the provider's token usage, from one provider call (none for no inputs). Fails with the provider's AiError, or an InvalidOutputError one when the provider returns another number of vectors.

ParameterTypeDescription
inputsSequence[str]

Returns Effect[EmbedManyResponse, E.AiError]

def embed_many(self, inputs: Sequence[str]) -> Effect[EmbedManyResponse, E.AiError]:
    """The vectors of ``inputs`` in order, with the provider's token
    usage, from one provider call (none for no inputs). Fails with the
    provider's ``AiError``, or an ``InvalidOutputError`` one when the
    provider returns another number of vectors."""
    inputs = tuple(inputs)
    if not inputs:
        return fx.succeed(EmbedManyResponse(())).with_span("EmbeddingModel.embedMany")
    return (
        fx.suspend(lambda: self._embed_many(ProviderOptions(inputs)))
        .flat_map(
            lambda response: _vectors(len(inputs), response).map(
                lambda embeddings: EmbedManyResponse(
                    embeddings, EmbeddingUsage(response.input_tokens)
                )
            )
        )
        .with_span("EmbeddingModel.embedMany")
    )