- md5
- 97a9807f7030b3d58c5b9f671e29ae02
- sha1
- 7ffed2c4a4794340c1ec3d4742299a46e0a38ae1
- sha256
- 1ac026c7a5d9af63cb50fb81d1c21d867f99d766847e9247af73ff8a881c080c
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
<?php
declare (strict_types=1);
namespace WordPress\AiClient\Builders\Traits;
use WordPress\AiClient\Providers\Models\DTO\ModelConfig;
/**
* Provides shared model configuration methods for builders.
*
* Builders that generate results from a model (e.g. {@see \WordPress\AiClient\Builders\PromptBuilder}
* and {@see \WordPress\AiClient\Builders\EmbeddingBuilder}) use this trait to accumulate model
* configuration, regardless of how they determine which model to use.
*
* @since 1.5.0
*/
trait ModelConfigurationTrait
{
/**
* @var ModelConfig The model configuration.
*/
protected ModelConfig $modelConfig;
/**
* Sets the model configuration.
*
* Merges the provided configuration with the builder's configuration,
* with builder configuration taking precedence.
*
* @since 0.1.0
*
* @param ModelConfig $config The model configuration to merge.
* @return self
*/
public function usingModelConfig(ModelConfig $config): self
{
$this->mergeModelConfig($config);
return $this;
}
/**
* Merges the given configuration into the builder's configuration.
*
* The builder's own configuration takes precedence for any overlapping settings, so that
* explicitly configured values are never overwritten by defaults from another source.
*
* @since 1.5.0
*
* @param ModelConfig $config The model configuration to merge.
* @return void
*/
protected function mergeModelConfig(ModelConfig $config): void
{
// Merge arrays with builder config taking precedence
$mergedArray = array_merge($config->toArray(), $this->modelConfig->toArray());
// Create new config from merged array
$this->modelConfig = ModelConfig::fromArray($mergedArray);
}
}
The same content is in 6 releases, WordPress 7.2-beta1 to 7.2-RC1. See them all, or every version of this file.