[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/php-ai-client/src/Providers/ -> ModelResolver.php (summary)

(no description)

File Size: 378 lines (16 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

ModelResolver:: (15 methods):
  __construct()
  __clone()
  setModel()
  getModel()
  setModelPreferences()
  setProvider()
  setRequestOptions()
  resolve()
  isSupported()
  bindModelRequestOptions()
  getCandidateModelsMap()
  generateMapFromCandidates()
  normalizePreferenceIdentifier()
  createProviderModelPreferenceKey()
  createModelPreferenceKey()


Class: ModelResolver  - X-Ref

Resolves the concrete AI model to use based on selection preferences.

This class owns all model-selection state and logic: an explicitly set model,
ordered model preferences, a provider constraint, and HTTP request options. It
is shared between the builders (via the model resolution trait) so that model
selection behaves identically regardless of what is being generated.

__construct(\WordPress\AiClient\Providers\ProviderRegistry $registry)   X-Ref
Constructor.

param: ProviderRegistry $registry The provider registry for finding suitable models.

__clone()   X-Ref
Creates a deep clone of this resolver.

Clones the request options (which contain only primitives). The registry and
explicitly set model are service objects and are intentionally NOT cloned, as
they should be shared references.


setModel(ModelInterface $model)   X-Ref
Sets the model to use for generation.

return: void
param: ModelInterface $model The model to use.

getModel()   X-Ref
Gets the explicitly set model, if any.

return: ModelInterface|null The explicitly set model, or null if none was set.

setModelPreferences(...$preferredModels)   X-Ref
Sets preferred models to evaluate in order.

return: void
param: string|ModelInterface|ProviderModelTuple ...$preferredModels The preferred models as model IDs,

setProvider(string $providerIdOrClassName)   X-Ref
Sets the provider to use for generation.

return: void
param: string $providerIdOrClassName The provider ID or class name.

setRequestOptions(RequestOptions $requestOptions)   X-Ref
Sets the request options for HTTP transport.

return: void
param: RequestOptions $requestOptions The request options.

resolve(ModelRequirements $requirements, ModelConfig $modelConfig, ?string $subject = null)   X-Ref
Resolves the model to use for the given requirements.

If a model has been explicitly set, updates its config, binds dependencies,
and returns it. Otherwise, finds a suitable model based on the requirements,
honoring any configured model preferences and provider constraint.

return: ModelInterface The model to use.
param: ModelRequirements $requirements The requirements the model must satisfy.
param: ModelConfig $modelConfig The model configuration to apply.
param: string|null $subject Optional caller-specific subject for failure messages.

isSupported(ModelRequirements $requirements)   X-Ref
Checks whether any model can satisfy the given requirements.

return: bool True if the set model or any registered model meets the requirements.
param: ModelRequirements $requirements The requirements to check support for.

bindModelRequestOptions(ModelInterface $model)   X-Ref
Binds configured request options to the model if present and supported.

Request options are only applicable to API-based models that make HTTP requests.

return: void
param: ModelInterface $model The model to bind request options to.

getCandidateModelsMap(ModelRequirements $requirements)   X-Ref
Builds a map of candidate models that satisfy the requirements for efficient lookup.

return: array<string, ProviderModelTuple> Map of preference keys to [providerId, modelId] tuples.
param: ModelRequirements $requirements The requirements derived from the prompt.

generateMapFromCandidates(string $providerId, array $modelsMetadata)   X-Ref
Generates a candidate map from model metadata with both provider-specific and model-only keys.

return: array<string, ProviderModelTuple> Map of preference keys to [providerId, modelId] tuples.
param: string $providerId The provider ID.
param: list<ModelMetadata> $modelsMetadata The models metadata to map.

normalizePreferenceIdentifier($value, string $emptyMessage = 'Model preference identifiers cannot be empty.')   X-Ref
Normalizes and validates a preference identifier string.

return: string The normalized identifier.
param: mixed $value The value to normalize.
param: string $emptyMessage The message for empty or invalid values.

createProviderModelPreferenceKey(string $providerId, string $modelId)   X-Ref
Creates a preference key for a provider/model combination.

return: string The generated preference key.
param: string $providerId The provider identifier.
param: string $modelId The model identifier.

createModelPreferenceKey(string $modelId)   X-Ref
Creates a preference key for a model identifier.

return: string The generated preference key.
param: string $modelId The model identifier.



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