�PNG  IHDR22?�� pHYs  �� OiCCPPhotoshop ICC profilexڝSgTS�=���BK���KoR RB���&*! J�!��Q�EEȠ�����Q, � ��!���������{�kּ������>���� �H3Q5� �B�������.@� $p�d!s�#�~<<+"��x� �M��0���B�\���t�8K�@z�B�@F���&S�`�cb�P-`'������{[�!�� e�Dh;��V�EX0fK�9�-0IWfH���� � 0Q��){`�##x��F�W<�+��*x��<�$9E�[-qWW.(�I+6aa�@.�y�2�4���������x����6��_-��"bb���ϫp@�t~��,/��;�m��%�h^ �u��f�@����W�p�~<�5�j>{�-�]c�K'Xt����o��(�h���w��?�G�%�fI�q^D$.Tʳ?�D��*�A��,���� �`6�B$��BB d�r`)��B(�Ͱ*`/�@4�Qh��p.�U�=p�a��(�� A�a!ڈb�X#����!�H�$ ɈQ"K�5H1R�T UH�=r9�\F��;�2����G1���Q=� �C��7�F� �dt1�����r�=�6��Ыhڏ>C�0��3�l0.��B�8, �c˱"� ���V����cϱw�E� 6wB aAHXLXN�H� $4� 7 �Q�'"��K�&���b21�XH,#��/{�C�7$�C2'��I��T��F�nR#�,��4H#���dk�9�, +ȅ����3��!�[ �b@q��S�(R�jJ��4�e�2AU��Rݨ�T5�ZB���R�Q��4u�9̓IK�����hh�i��t�ݕN��W���G���w ��Ljg(�gw��L�Ӌ�T071���oUX*�*|�� �J�&�*/T����ު U�U�T��^S}�FU3S� Ԗ�U��P�SSg�;���g�oT?�~Y��Y�L�OC�Q��_�� c�x,!k ��u�5�&���|v*�����=���9C3J3W�R�f?�q��tN �(���~���)�)�4L�1e\k����X�H�Q�G�6������E�Y��A�J'\'Gg����S�Sݧ �M=:��.�k���Dw�n��^��Lo��y���}/�T�m���G X� $� �<�5qo</���QC]�@C�a�a�ᄑ��<��F�F�i�\�$�m�mƣ&&!&KM�M�RM��)�;L;L���͢�֙5�=1�2��כ߷`ZxZ,����eI��Z�Yn�Z9Y�XUZ]�F���%ֻ�����N�N���gð�ɶ�����ۮ�m�}agbg�Ů��}�}��= ���Z~s�r:V:ޚΜ�?}����/gX���3��)�i�S��Ggg�s�󈋉K��.�>.���Ƚ�Jt�q]�z���������ۯ�6�i�ܟ�4�)�Y3s���C�Q��? ��0k߬~OCO�g��#/c/�W�װ��w��a�>�>r��>�<7�2�Y_�7��ȷ�O�o�_��C#�d�z����%g��A�[��z|!��?:�e����A���AA�������!h�쐭!��Α�i�P~���a�a��~ '���W�?�p�X�1�5w��Cs�D�D�Dޛg1O9�-J5*>�.j<�7�4�?�.fY��X�XIlK9.*�6nl������� �{�/�]py�����.,:�@L�N8��A*��%�w%� y��g"/�6ш�C\*N�H*Mz�쑼5y$�3�,幄'���L Lݛ:��v m2=:�1����qB�!M��g�g�fvˬe����n��/��k���Y- �B��TZ(�*�geWf�͉�9���+��̳�ې7�����ᒶ��KW-X潬j9�������(�x��oʿ�ܔ���Ĺd�f�f���-�[����n �ڴ �V����E�/��(ۻ��C���<��e����;?T�T�T�T6��ݵa��n��{��4���[���>ɾ�UUM�f�e�I���?�������m]�Nmq����#�׹���=TR��+�G�����w- 6 U����#pDy��� �� :�v�{���vg/jB��F�S��[b[�O�>����z�G��499�?r����C�d�&����ˮ/~�����јѡ�򗓿m|������������x31^�V���w�w��O�| (�h���SЧ��������c3-� cHRMz%������u0�`:�o�_�F5IDATx��ytUս�?�;���fN$$��@B�!�k��� -*�gE���j�O�kQ�ʠ`U�B_ �AÐ0%�Ȕ�@r3ޛ;߳��$�@��v����^�s����������$��ߢ !�W��5�̱'-٘������4�>�Rƫ$�G��0U�H}�_ _� #��k�MJ/=�9Du *ڲ�k�PQ;0��j|�*�$�^컂脛y���>�z×� B��� ��(�:$�ʔ_�6��C!B����MVx��a��ζyY����j��ƋY2�9�F�{r��r�딟F��Q��hY6��� x��[l��RC��������nt@��;P��3��� F�w��7��:�P���ɋ'���mj���Bƪ�$�Q�L��y��߷g��\���z����v5�p�v$�v櫻�`6~K �Y�X����,�:��"�o�e0II"(��,������l_�C���/4�+f�E�!q��:����u����c��樼.UE�@� �]K�W���$-�h]�JG���Dz)�`��.�A/ ���mᏣc�3jK� �!�>���$�Q�!�_�? \�C2(E �M$Z I{�U���s�ǣ���=��@Բe ޻��W�����@ �w����}�9v,)��.}*|"�s��di���,���G�]W�AC�������|<����[��ߕ������K�*�G nߴ!��‹��J�!��6(L�a)��Am��������;adf��:�xm��nh�;֦I��(���o�C~ډa?�=��s����h��E������xp����)���_���t��W�����´;8���`dz=(��@@�+,�;�`�fhl��XȌ�3,uI�~z(J����� �ZX�A����H'�À�㜦�82|��a�n�z2��I���� ���EY�h�ε<�0�q�{��C��v�˅��?"@��χ�x�WS+��N�~�KQ�J�8ل�� _.W��� !TU{�����,��"�� �;�������HI S� ��))�o�1�H�D� ���� (� ;����"Ҕ��,���� �F=���O��&�Ph>�`���y��߲ &S��P�<��'��1s�1cĂ�N����2)����@�u��tv��<�+�-&�����h��[!FSG���' � z z0��<����8d&�����E0�,��<��"!P�b4��� �{S�����X����.�囤���T��hEF��X�q0"-<����h���]�Py*����F⩍��@v�˂�Y08�� .q��a��s����(!<̫1�3�L�H��7sYW�`��qtu�\7��?�@�Y�� %Ka�x�GZ�*W�P��y�����N0r9��Z�c�%���q,��k�����!!,��>���IB��� �x1�Xu�Y���v-���ֺ��N������JP��a�2`�e5��w��u;�6�i���̃��(K���ťa��(l51��JL��O'%���]���ٖ뿉!��{*�p+f ���i8��D�ȑ���ܩ�M��V��ӟz��x�7Z�1i}�^͜���6e����x��)u�d�ˏ�V�eG�\�X1�����=n�U'�~Y����L�\,�(d!x ,�:�TW8� M`r���@��r+v�Q0��>^;˴�VbF��('����� �*O��i��j�Ӆ����^�S3&� ���{������.ی�� N;��NU%d0�Ce\r"�C�b��&t7N�7��� �ȪD�[%l�۪�$��'m?�A9tI�9>��NVL ��� 6v~M�����ъ�B���0����9$&=ώm��W�0���L���&��E���f�f��'+�9��hv��7,���M��6�D�&�^� �����8 D֮�����o��k^z��O��hP�8q�5d*��YVq3�{��������#LX4�?��jP=3�~�؅c�ݰ�̱�ұ��8̲��2�G�����j��έ�9��w7���U�X�w�85C��?!I&���o&����L���I#�^�eV�,�^t5�k� �xs˛\��U�8��."���{���ǵ�l4��ݼ�;��r"���G�/~���gJV�N糦��ZZ^k+NN�D��I$�=OE�z����|*�*{��%k���G��>�`9��b;�s���8,�qs��c��.b��q�%�>r��n�R�Ƨ�%�,�A��le#�8���}; 21�0�b�&�QX�f���q�00����$>�h�N�'�a3��A���/�r ��L5�8�GԲ'�����w;��c#�q1���h$*��V^�k��QĽ�b:i������� ����H F#�_���,��]g����Ը����`RUU���� ��"�qD���>-��ϤI�~��3�̴�����NZ[[555�eeek7�m����YF#[��Đ��R��i��L�H�r ��@��J-�Pŝ��_|�-��6y��ks�V�U~��6���w.����(��0A� 4��f��� /���C�xŊ�ٳ����z=6�����rg���mKo��o�/����a�g���?'9%9��P��斓��~���L{�� �H��{AW��B��$����v�1b�&Mb�ر��ر#�0`�`xMBp! )Z�Nmo�mZ�g�}�eذaWTVV ���'99��C5��&�&+5�bT>|8��PUUETT����&���t��~TE%��'������b�tEGG;RSS�S�N�v��ѯ��t����u1@�ޚ"f��͈���r'L�Ph��m��ƌ�74o��`�x�q�P���NRSS�X,�����l&&&��MFFA!-��`��ҷ�n��Yuu�����x<I�LB%����KԒ50�!�3�bz�����ʸKL���;---�l6[��`��������Ȏ;�����egg4��!D�T��jWujyZ��������K����%����p�^���X,6��sV=�ܖ����6�3�X ���4ҿ��A2�&����_k�;d�� �VfOIEND�B`� 0x0x
PHP 8.1.34
Preview: EmbeddingBuilder.php Size: 22.59 KB
/home2/astrociv/public_html/vaastruelogy.in/WordPress-master/wp-includes/php-ai-client/src/Builders/EmbeddingBuilder.php
<?php

declare (strict_types=1);
namespace WordPress\AiClient\Builders;

use WordPress\AiClientDependencies\Psr\EventDispatcher\EventDispatcherInterface;
use WordPress\AiClient\Builders\Traits\ModelConfigurationTrait;
use WordPress\AiClient\Common\AbstractEnum;
use WordPress\AiClient\Common\Contracts\AiClientExceptionInterface;
use WordPress\AiClient\Common\Exception\InvalidArgumentException;
use WordPress\AiClient\Common\Exception\RuntimeException;
use WordPress\AiClient\Events\AfterGenerateEmbeddingEvent;
use WordPress\AiClient\Events\BeforeGenerateEmbeddingEvent;
use WordPress\AiClient\Files\DTO\File;
use WordPress\AiClient\Messages\DTO\MessagePart;
use WordPress\AiClient\Providers\ApiBasedImplementation\Contracts\ApiBasedModelInterface;
use WordPress\AiClient\Providers\Http\DTO\RequestOptions;
use WordPress\AiClient\Providers\ModelResolver;
use WordPress\AiClient\Providers\Models\Contracts\ModelInterface;
use WordPress\AiClient\Providers\Models\DTO\ModelConfig;
use WordPress\AiClient\Providers\Models\DTO\ModelRequirements;
use WordPress\AiClient\Providers\Models\DTO\RequiredOption;
use WordPress\AiClient\Providers\Models\EmbeddingGeneration\Contracts\EmbeddingGenerationModelInterface;
use WordPress\AiClient\Providers\Models\Enums\CapabilityEnum;
use WordPress\AiClient\Providers\ProviderRegistry;
use WordPress\AiClient\Results\DTO\Embedding;
use WordPress\AiClient\Results\DTO\EmbeddingResult;
/**
 * Fluent builder for generating embeddings.
 *
 * Embeddings transform inputs into vector representations rather than generating a conversational
 * response. Each input is embedded independently, and the builder produces one embedding vector per
 * input.
 *
 * Unlike {@see PromptBuilder}, this builder never selects a model on the caller's behalf. Embedding
 * vectors are only comparable to other vectors produced by the same model, so a stored corpus is
 * permanently bound to the model that created it. Automatically choosing a model could therefore
 * silently invalidate existing vectors, for example when the registered providers change. The model
 * must be specified via {@see self::usingModel()} or {@see self::usingProviderModel()}; the builder
 * verifies that the given model can fulfill the request instead of searching for one that can.
 *
 * @since 1.4.0
 *
 * @phpstan-import-type MessagePartArrayShape from MessagePart
 * @phpstan-import-type UnmetModelRequirementsShape from ModelRequirements
 * @phpstan-import-type ProviderModelTuple from ModelResolver
 *
 * @phpstan-type EmbeddingInput string|MessagePart|File|MessagePartArrayShape
 */
class EmbeddingBuilder
{
    use ModelConfigurationTrait;
    /**
     * @var string Message used when no model was specified.
     */
    private const NO_MODEL_MESSAGE = 'An embedding model must be specified. Embeddings are only comparable to ' . 'other embeddings from the same model, so no model is selected automatically. ' . 'Use usingModel() or usingProviderModel().';
    /**
     * @var ProviderRegistry The provider registry used to prepare the model.
     */
    protected ProviderRegistry $registry;
    /**
     * @var list<MessagePart> The inputs to embed.
     */
    protected array $inputs = [];
    /**
     * @var ModelInterface|null The explicitly provided model, if any.
     */
    protected ?ModelInterface $model = null;
    /**
     * @var ProviderModelTuple|null The provider ID or class name and model ID, if any.
     */
    protected ?array $providerModel = null;
    /**
     * @var RequestOptions|null The request options for HTTP transport.
     */
    protected ?RequestOptions $requestOptions = null;
    /**
     * @var EventDispatcherInterface|null The event dispatcher for embedding lifecycle events.
     */
    private ?EventDispatcherInterface $eventDispatcher;
    /**
     * Constructor.
     *
     * @since 1.4.0
     *
     * @param ProviderRegistry $registry The provider registry used to prepare the model.
     * @param EmbeddingInput|list<EmbeddingInput>|null $input Optional initial input(s) to embed.
     * @param EventDispatcherInterface|null $eventDispatcher Optional event dispatcher for lifecycle events.
     */
    public function __construct(ProviderRegistry $registry, $input = null, ?EventDispatcherInterface $eventDispatcher = null)
    {
        $this->registry = $registry;
        $this->modelConfig = new ModelConfig();
        $this->eventDispatcher = $eventDispatcher;
        if ($input === null) {
            return;
        }
        if (is_array($input) && array_is_list($input)) {
            /** @var list<EmbeddingInput> $input */
            $this->withInput(...$input);
            return;
        }
        /** @var EmbeddingInput $input */
        $this->withInput($input);
    }
    /**
     * Creates a deep clone of this builder.
     *
     * Clones the inputs, model configuration, and request options. Service objects (registry, model,
     * event dispatcher) are intentionally NOT cloned as they are shared dependencies.
     *
     * @since 1.4.0
     */
    public function __clone()
    {
        $clonedInputs = [];
        foreach ($this->inputs as $input) {
            $clonedInputs[] = clone $input;
        }
        $this->inputs = $clonedInputs;
        $this->modelConfig = clone $this->modelConfig;
        if ($this->requestOptions !== null) {
            $this->requestOptions = clone $this->requestOptions;
        }
        // Note: $registry, $model, and $eventDispatcher are service objects and are intentionally
        // NOT cloned - they should be shared references.
    }
    /**
     * Adds one or more inputs to embed.
     *
     * @since 1.4.0
     *
     * @param EmbeddingInput ...$input The inputs to embed, each treated as an independent input.
     * @return self
     * @throws InvalidArgumentException If no inputs are provided or an input is invalid.
     */
    public function withInput(...$input): self
    {
        if ($input === []) {
            throw new InvalidArgumentException('At least one input must be provided.');
        }
        foreach ($input as $singleInput) {
            $this->inputs[] = $this->parseInput($singleInput);
        }
        return $this;
    }
    /**
     * Sets the model to use for embedding generation.
     *
     * The model's configuration will be merged with the builder's configuration,
     * with the builder's configuration taking precedence for any overlapping settings. The merge
     * happens when the model is used rather than here, so replacing the model replaces its
     * configuration along with it.
     *
     * @since 1.4.0
     *
     * @param ModelInterface $model The model to use.
     * @return self
     */
    public function usingModel(ModelInterface $model): self
    {
        $this->model = $model;
        $this->providerModel = null;
        return $this;
    }
    /**
     * Sets the model to use for embedding generation, by provider and model identifier.
     *
     * This is an alternative to {@see self::usingModel()} that does not require the caller to
     * reference a provider class directly. The model is retrieved from the registry when the
     * embeddings are generated, so it receives any configuration set afterwards.
     *
     * @since 1.5.0
     *
     * @param string $providerIdOrClassName The provider ID or class name.
     * @param string $modelId The model identifier.
     * @return self
     * @throws InvalidArgumentException If the provider or model identifier is empty.
     */
    public function usingProviderModel(string $providerIdOrClassName, string $modelId): self
    {
        if (trim($providerIdOrClassName) === '') {
            throw new InvalidArgumentException('Provider identifier cannot be empty.');
        }
        if (trim($modelId) === '') {
            throw new InvalidArgumentException('Model identifier cannot be empty.');
        }
        $this->providerModel = [$providerIdOrClassName, $modelId];
        $this->model = null;
        return $this;
    }
    /**
     * Sets the request options for HTTP transport.
     *
     * @since 1.4.0
     *
     * @param RequestOptions $requestOptions The request options.
     * @return self
     */
    public function usingRequestOptions(RequestOptions $requestOptions): self
    {
        $this->requestOptions = $requestOptions;
        return $this;
    }
    /**
     * Sets the embedding dimensions.
     *
     * @since 1.4.0
     *
     * @param int $dimensions The embedding dimensions.
     * @return self
     */
    public function usingDimensions(int $dimensions): self
    {
        $this->modelConfig->setDimensions($dimensions);
        return $this;
    }
    /**
     * Checks whether the specified model supports the current inputs and configuration.
     *
     * This reports whether the model set via {@see self::usingModel()} or
     * {@see self::usingProviderModel()} can fulfill the request, rather than whether any available
     * model can.
     *
     * Any reason the specified model cannot fulfill the request is reported as `false`, including an
     * unregistered or unconfigured provider, a model ID the provider does not offer, and a provider
     * that could not be reached. Only failing to specify a model at all is treated as a programming
     * error and throws.
     *
     * A model instance provided via {@see self::usingModel()} is left untouched, so that checking
     * for support does not alter it. Determining whether the model's provider is configured may
     * require a request to the provider, which is cached for the remainder of the request.
     *
     * @since 1.4.0
     *
     * @return bool True if the specified model supports embedding generation for the current
     *              inputs and configuration.
     * @throws InvalidArgumentException If no model was specified.
     */
    public function isSupported(): bool
    {
        if ($this->providerModel === null && $this->model === null) {
            throw new InvalidArgumentException(self::NO_MODEL_MESSAGE);
        }
        try {
            $model = $this->locateModel();
        } catch (AiClientExceptionInterface $e) {
            // The model is unusable: its provider is not registered or configured, the provider has
            // no model with the given ID, or the provider could not be reached. Either way it cannot
            // fulfill the request.
            return \false;
        }
        if (!$model instanceof EmbeddingGenerationModelInterface) {
            return \false;
        }
        return $this->describeUnmetRequirements($model) === null;
    }
    /**
     * Generates an embedding result from the configured inputs.
     *
     * @since 1.4.0
     *
     * @return EmbeddingResult The generated embedding result.
     * @throws InvalidArgumentException If no inputs are configured, no model was specified, or the
     *                                  specified model cannot fulfill the request.
     * @throws RuntimeException If the model returns an embedding count that does not match the
     *                          number of inputs.
     */
    public function generateEmbeddingResult(): EmbeddingResult
    {
        if ($this->inputs === []) {
            throw new InvalidArgumentException('Cannot generate embeddings from empty input. Add content using withInput().');
        }
        $capability = CapabilityEnum::embeddingGeneration();
        $model = $this->resolveModel();
        $this->dispatchEvent(new BeforeGenerateEmbeddingEvent($this->inputs, $model, $capability));
        $result = $model->generateEmbeddingResult($this->inputs);
        // Embeddings map positionally to inputs, so the counts must match.
        if (count($result->getEmbeddings()) !== count($this->inputs)) {
            throw new RuntimeException(sprintf('Expected %d embedding(s) from the model, but received %d.', count($this->inputs), count($result->getEmbeddings())));
        }
        $this->dispatchEvent(new AfterGenerateEmbeddingEvent($this->inputs, $model, $capability, $result));
        return $result;
    }
    /**
     * Generates a single embedding from the configured input.
     *
     * @since 1.4.0
     *
     * @return Embedding The generated embedding vector.
     * @throws InvalidArgumentException If no inputs are configured, no model was specified, the
     *                                  specified model cannot fulfill the request, or multiple
     *                                  inputs were provided.
     */
    public function generateEmbedding(): Embedding
    {
        if (count($this->inputs) > 1) {
            throw new InvalidArgumentException('generateEmbedding() returns a single vector; use generateEmbeddings() for multiple inputs.');
        }
        return $this->generateEmbeddingResult()->getEmbedding();
    }
    /**
     * Generates embeddings from the configured inputs.
     *
     * @since 1.4.0
     *
     * @return list<Embedding> The generated embedding vectors.
     * @throws InvalidArgumentException If no inputs are configured, no model was specified, or the
     *                                  specified model cannot fulfill the request.
     * @throws RuntimeException If the model returns an embedding count that does not match the
     *                          number of inputs.
     */
    public function generateEmbeddings(): array
    {
        return $this->generateEmbeddingResult()->getEmbeddings();
    }
    /**
     * Resolves the specified model and verifies it can fulfill the request.
     *
     * @since 1.5.0
     *
     * @return ModelInterface&EmbeddingGenerationModelInterface The verified model.
     * @throws InvalidArgumentException If no model was specified, the model's provider is not
     *                                  configured, or the model cannot fulfill the request.
     */
    private function resolveModel(): ModelInterface
    {
        $model = $this->prepareModel();
        if (!$model instanceof EmbeddingGenerationModelInterface) {
            throw new InvalidArgumentException(sprintf('Model "%s" from provider "%s" does not support embedding generation.', $model->metadata()->getId(), $model->providerMetadata()->getId()));
        }
        $unmetRequirements = $this->describeUnmetRequirements($model);
        if ($unmetRequirements !== null) {
            throw new InvalidArgumentException(sprintf('Model "%s" from provider "%s" cannot fulfill this embedding request. %s', $model->metadata()->getId(), $model->providerMetadata()->getId(), $unmetRequirements));
        }
        return $model;
    }
    /**
     * Locates the specified model, without preparing it for use.
     *
     * Unlike {@see self::prepareModel()}, this leaves a model instance provided by the caller
     * untouched, so that it can be inspected without altering it.
     *
     * @since 1.5.0
     *
     * @return ModelInterface The located model.
     * @throws InvalidArgumentException If no model was specified, the model's provider is not
     *                                  configured, or the model could not be retrieved.
     */
    private function locateModel(): ModelInterface
    {
        if ($this->providerModel !== null) {
            [$providerIdOrClassName, $modelId] = $this->providerModel;
            $this->assertProviderConfigured($providerIdOrClassName);
            // Retrieving the model also binds its provider dependencies.
            return $this->registry->getProviderModel($providerIdOrClassName, $modelId, $this->modelConfig);
        }
        if ($this->model !== null) {
            $model = $this->model;
            $this->assertProviderConfigured($model->providerMetadata()->getId());
            return $model;
        }
        throw new InvalidArgumentException(self::NO_MODEL_MESSAGE);
    }
    /**
     * Prepares the specified model for use, without verifying that it can fulfill the request.
     *
     * @since 1.5.0
     *
     * @return ModelInterface The prepared model, with its dependencies and configuration bound.
     * @throws InvalidArgumentException If no model was specified, the model's provider is not
     *                                  configured, or the model could not be retrieved.
     */
    private function prepareModel(): ModelInterface
    {
        $model = $this->locateModel();
        // A model retrieved from the registry is already bound and configured, so only a model
        // instance provided by the caller needs its dependencies and configuration bound here.
        if ($model === $this->model) {
            $model->setConfig($this->effectiveModelConfig($model));
            $this->registry->bindModelDependencies($model);
        }
        // Request options are only applicable to API-based models that make HTTP requests.
        if ($this->requestOptions !== null && $model instanceof ApiBasedModelInterface) {
            $model->setRequestOptions($this->requestOptions);
        }
        return $model;
    }
    /**
     * Combines a model's own configuration with the configuration set on this builder.
     *
     * The builder's configuration takes precedence for any overlapping settings. Combining happens
     * here, when the model is used, rather than when the model is set, so that the configuration of
     * a model that was subsequently replaced is not applied to its replacement.
     *
     * @since 1.5.0
     *
     * @param ModelInterface $model The model whose configuration to combine with the builder's.
     * @return ModelConfig The effective configuration for the given model.
     */
    private function effectiveModelConfig(ModelInterface $model): ModelConfig
    {
        return ModelConfig::fromArray(array_merge($model->getConfig()->toArray(), $this->modelConfig->toArray()));
    }
    /**
     * Asserts that the given provider is configured and therefore usable.
     *
     * @since 1.5.0
     *
     * @param string $providerIdOrClassName The provider ID or class name.
     * @return void
     * @throws InvalidArgumentException If the provider is not registered or not usable.
     */
    private function assertProviderConfigured(string $providerIdOrClassName): void
    {
        // A provider reports itself unconfigured for any reason it cannot be used, including
        // credentials that are missing, invalid, or rejected, so the message covers all of them.
        if (!$this->registry->isProviderConfigured($providerIdOrClassName)) {
            throw new InvalidArgumentException(sprintf('Provider "%s" is not registered, or is not configured with valid credentials. ' . 'Ensure the provider is registered and its credentials are present and valid ' . 'before generating embeddings.', $providerIdOrClassName));
        }
    }
    /**
     * Describes the requirements of the current request that the given model does not meet.
     *
     * @since 1.5.0
     *
     * @param ModelInterface $model The model to check.
     * @return string|null A description of the unmet requirements, or null if the model meets them all.
     */
    private function describeUnmetRequirements(ModelInterface $model): ?string
    {
        $requirements = ModelRequirements::fromEmbeddingData($this->inputs, $this->effectiveModelConfig($model));
        /** @var UnmetModelRequirementsShape $unmetRequirements */
        $unmetRequirements = $requirements->getUnmetRequirements($model->metadata());
        $descriptions = [];
        if ($unmetRequirements['capabilities'] !== []) {
            $descriptions[] = sprintf('Unsupported capabilities: %s.', implode(', ', array_map(static fn(CapabilityEnum $capability): string => $capability->value, $unmetRequirements['capabilities'])));
        }
        if ($unmetRequirements['options'] !== []) {
            $descriptions[] = sprintf('Unsupported options: %s.', implode(', ', array_map(fn(RequiredOption $option): string => sprintf('%s (%s)', $option->getName()->value, $this->describeOptionValue($option->getValue())), $unmetRequirements['options'])));
        }
        if ($descriptions === []) {
            return null;
        }
        return implode(' ', $descriptions);
    }
    /**
     * Describes an option value for use in an error message.
     *
     * @since 1.5.0
     *
     * @param mixed $value The option value to describe.
     * @return string The human readable description.
     */
    private function describeOptionValue($value): string
    {
        if ($value === null) {
            return 'null';
        }
        if (is_bool($value)) {
            return $value ? 'true' : 'false';
        }
        if ($value instanceof AbstractEnum) {
            return $value->value;
        }
        if (is_array($value)) {
            return '[' . implode(', ', array_map(fn($item): string => $this->describeOptionValue($item), $value)) . ']';
        }
        if (is_scalar($value)) {
            return (string) $value;
        }
        return is_object($value) ? get_class($value) : gettype($value);
    }
    /**
     * Parses a single input into a message part.
     *
     * @since 1.4.0
     *
     * @param mixed $input The input to parse. Accepts a string, MessagePart, File, or
     *                     MessagePartArrayShape.
     * @return MessagePart The parsed message part.
     * @throws InvalidArgumentException If the input type is not supported or is an invalid part type.
     */
    private function parseInput($input): MessagePart
    {
        if ($input instanceof MessagePart) {
            return $this->validatePart($input);
        }
        if (is_string($input)) {
            if (trim($input) === '') {
                throw new InvalidArgumentException('Cannot create an embedding input from an empty string.');
            }
            return new MessagePart($input);
        }
        if ($input instanceof File) {
            return new MessagePart($input);
        }
        if (is_array($input) && MessagePart::isArrayShape($input)) {
            return $this->validatePart(MessagePart::fromArray($input));
        }
        throw new InvalidArgumentException('Embedding input must be a string, MessagePart, File, or MessagePartArrayShape.');
    }
    /**
     * Validates that a message part is a valid embedding input.
     *
     * @since 1.4.0
     *
     * @param MessagePart $part The part to validate.
     * @return MessagePart The validated part.
     * @throws InvalidArgumentException If the part is not a text or file part.
     */
    private function validatePart(MessagePart $part): MessagePart
    {
        $type = $part->getType();
        if (!$type->isText() && !$type->isFile()) {
            throw new InvalidArgumentException('Embedding inputs must be text or file parts.');
        }
        return $part;
    }
    /**
     * Dispatches an event if an event dispatcher is registered.
     *
     * @since 1.4.0
     *
     * @param object $event The event to dispatch.
     * @return void
     */
    private function dispatchEvent(object $event): void
    {
        if ($this->eventDispatcher !== null) {
            $this->eventDispatcher->dispatch($event);
        }
    }
}

Directory Contents

Dirs: 1 × Files: 3
Name Size Perms Modified Actions
Traits DIR
- drwxr-xr-x 2026-10-28 14:44:54
Edit Download
22.59 KB lrw-r--r-- 2026-10-28 14:44:54
Edit Download
6.43 KB lrw-r--r-- 2026-10-28 14:44:54
Edit Download
41.32 KB lrw-r--r-- 2026-10-28 14:44:54
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).
© 2026 0xNothings — Secure File Manager. All rights reserved. Built with ❤️ & Tailwind x Dark UI