[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/php-ai-client/src/Providers/Models/Enums/ -> OptionEnum.php (source)

   1  <?php
   2  
   3  declare (strict_types=1);
   4  namespace WordPress\AiClient\Providers\Models\Enums;
   5  
   6  use ReflectionClass;
   7  use WordPress\AiClient\Common\AbstractEnum;
   8  use WordPress\AiClient\Providers\Models\DTO\ModelConfig;
   9  /**
  10   * Enum for model options.
  11   *
  12   * This enum dynamically includes all options from ModelConfig KEY_* constants
  13   * in addition to the explicitly defined constants below.
  14   *
  15   * Explicitly defined option (not in ModelConfig):
  16   * @method static self inputModalities() Creates an instance for INPUT_MODALITIES option.
  17   * @method bool isInputModalities() Checks if the option is INPUT_MODALITIES.
  18   *
  19   * Dynamically loaded from ModelConfig KEY_* constants:
  20   * @method static self candidateCount() Creates an instance for CANDIDATE_COUNT option.
  21   * @method static self customOptions() Creates an instance for CUSTOM_OPTIONS option.
  22   * @method static self frequencyPenalty() Creates an instance for FREQUENCY_PENALTY option.
  23   * @method static self functionDeclarations() Creates an instance for FUNCTION_DECLARATIONS option.
  24   * @method static self logprobs() Creates an instance for LOGPROBS option.
  25   * @method static self maxTokens() Creates an instance for MAX_TOKENS option.
  26   * @method static self outputFileType() Creates an instance for OUTPUT_FILE_TYPE option.
  27   * @method static self outputMediaAspectRatio() Creates an instance for OUTPUT_MEDIA_ASPECT_RATIO option.
  28   * @method static self outputMediaOrientation() Creates an instance for OUTPUT_MEDIA_ORIENTATION option.
  29   * @method static self outputMimeType() Creates an instance for OUTPUT_MIME_TYPE option.
  30   * @method static self outputModalities() Creates an instance for OUTPUT_MODALITIES option.
  31   * @method static self outputSchema() Creates an instance for OUTPUT_SCHEMA option.
  32   * @method static self outputSpeechVoice() Creates an instance for OUTPUT_SPEECH_VOICE option.
  33   * @method static self presencePenalty() Creates an instance for PRESENCE_PENALTY option.
  34   * @method static self stopSequences() Creates an instance for STOP_SEQUENCES option.
  35   * @method static self systemInstruction() Creates an instance for SYSTEM_INSTRUCTION option.
  36   * @method static self temperature() Creates an instance for TEMPERATURE option.
  37   * @method static self topK() Creates an instance for TOP_K option.
  38   * @method static self topLogprobs() Creates an instance for TOP_LOGPROBS option.
  39   * @method static self topP() Creates an instance for TOP_P option.
  40   * @method static self webSearch() Creates an instance for WEB_SEARCH option.
  41   * @method bool isCandidateCount() Checks if the option is CANDIDATE_COUNT.
  42   * @method bool isCustomOptions() Checks if the option is CUSTOM_OPTIONS.
  43   * @method bool isFrequencyPenalty() Checks if the option is FREQUENCY_PENALTY.
  44   * @method bool isFunctionDeclarations() Checks if the option is FUNCTION_DECLARATIONS.
  45   * @method bool isLogprobs() Checks if the option is LOGPROBS.
  46   * @method bool isMaxTokens() Checks if the option is MAX_TOKENS.
  47   * @method bool isOutputFileType() Checks if the option is OUTPUT_FILE_TYPE.
  48   * @method bool isOutputMediaAspectRatio() Checks if the option is OUTPUT_MEDIA_ASPECT_RATIO.
  49   * @method bool isOutputMediaOrientation() Checks if the option is OUTPUT_MEDIA_ORIENTATION.
  50   * @method bool isOutputMimeType() Checks if the option is OUTPUT_MIME_TYPE.
  51   * @method bool isOutputModalities() Checks if the option is OUTPUT_MODALITIES.
  52   * @method bool isOutputSchema() Checks if the option is OUTPUT_SCHEMA.
  53   * @method bool isOutputSpeechVoice() Checks if the option is OUTPUT_SPEECH_VOICE.
  54   * @method bool isPresencePenalty() Checks if the option is PRESENCE_PENALTY.
  55   * @method bool isStopSequences() Checks if the option is STOP_SEQUENCES.
  56   * @method bool isSystemInstruction() Checks if the option is SYSTEM_INSTRUCTION.
  57   * @method bool isTemperature() Checks if the option is TEMPERATURE.
  58   * @method bool isTopK() Checks if the option is TOP_K.
  59   * @method bool isTopLogprobs() Checks if the option is TOP_LOGPROBS.
  60   * @method bool isTopP() Checks if the option is TOP_P.
  61   * @method bool isWebSearch() Checks if the option is WEB_SEARCH.
  62   *
  63   * @since 0.1.0
  64   */
  65  class OptionEnum extends AbstractEnum
  66  {
  67      /**
  68       * Input modalities option.
  69       *
  70       * This constant is not in ModelConfig as it's derived from message content,
  71       * not configured directly.
  72       */
  73      public const INPUT_MODALITIES = 'input_modalities';
  74      /**
  75       * Determines the class enumerations by reflecting on class constants.
  76       *
  77       * Overrides the parent method to dynamically add constants from ModelConfig
  78       * that are prefixed with KEY_. These are transformed to remove the KEY_ prefix
  79       * and converted to snake_case values.
  80       *
  81       * @since 0.1.0
  82       *
  83       * @param class-string $className The fully qualified class name.
  84       * @return array<string, string> The enum constants.
  85       */
  86      protected static function determineClassEnumerations(string $className): array
  87      {
  88          // Start with the constants defined in this class using parent method
  89          $constants = parent::determineClassEnumerations($className);
  90          // Use reflection to get all constants from ModelConfig
  91          $modelConfigReflection = new ReflectionClass(ModelConfig::class);
  92          $modelConfigConstants = $modelConfigReflection->getConstants();
  93          // Add ModelConfig constants that start with KEY_
  94          foreach ($modelConfigConstants as $constantName => $constantValue) {
  95              if (str_starts_with($constantName, 'KEY_')) {
  96                  // Remove KEY_ prefix to get the enum constant name
  97                  $enumConstantName = substr($constantName, 4);
  98                  // The value is the snake_case version stored in ModelConfig
  99                  // ModelConfig already stores these as snake_case strings
 100                  if (is_string($constantValue)) {
 101                      $constants[$enumConstantName] = $constantValue;
 102                  }
 103              }
 104          }
 105          return $constants;
 106      }
 107  }


Generated : Sat Jun 13 09:38:55 2026 Cross-referenced by PHPXref