[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/php-ai-client/src/Builders/Traits/ -> ModelConfigurationTrait.php (source)

   1  <?php
   2  
   3  declare (strict_types=1);
   4  namespace WordPress\AiClient\Builders\Traits;
   5  
   6  use WordPress\AiClient\Providers\Models\DTO\ModelConfig;
   7  /**
   8   * Provides shared model configuration methods for builders.
   9   *
  10   * Builders that generate results from a model (e.g. {@see \WordPress\AiClient\Builders\PromptBuilder}
  11   * and {@see \WordPress\AiClient\Builders\EmbeddingBuilder}) use this trait to accumulate model
  12   * configuration, regardless of how they determine which model to use.
  13   *
  14   * @since 1.5.0
  15   */
  16  trait ModelConfigurationTrait
  17  {
  18      /**
  19       * @var ModelConfig The model configuration.
  20       */
  21      protected ModelConfig $modelConfig;
  22      /**
  23       * Sets the model configuration.
  24       *
  25       * Merges the provided configuration with the builder's configuration,
  26       * with builder configuration taking precedence.
  27       *
  28       * @since 0.1.0
  29       *
  30       * @param ModelConfig $config The model configuration to merge.
  31       * @return self
  32       */
  33      public function usingModelConfig(ModelConfig $config): self
  34      {
  35          $this->mergeModelConfig($config);
  36          return $this;
  37      }
  38      /**
  39       * Merges the given configuration into the builder's configuration.
  40       *
  41       * The builder's own configuration takes precedence for any overlapping settings, so that
  42       * explicitly configured values are never overwritten by defaults from another source.
  43       *
  44       * @since 1.5.0
  45       *
  46       * @param ModelConfig $config The model configuration to merge.
  47       * @return void
  48       */
  49      protected function mergeModelConfig(ModelConfig $config): void
  50      {
  51          // Merge arrays with builder config taking precedence
  52          $mergedArray = array_merge($config->toArray(), $this->modelConfig->toArray());
  53          // Create new config from merged array
  54          $this->modelConfig = ModelConfig::fromArray($mergedArray);
  55      }
  56  }


Generated : Wed Oct 14 08:20:33 2026 Cross-referenced by PHPXref