Title: ModelConfig::fromArray
Published: May 20, 2026

---

# ModelConfig::fromArray( $array )

## In this article

 * [Source](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-models-dto-modelconfig/fromarray/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-models-dto-modelconfig/fromarray/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-models-dto-modelconfig/fromarray/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-models-dto-modelconfig/fromarray/?output_format=md#wp--skip-link--target)

{@inheritDoc}

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-models-dto-modelconfig/fromarray/?output_format=md#source)󠁿

    ```php
    public static function fromArray(array $array): self
    {
        $config = new self();
        if (isset($array[self::KEY_OUTPUT_MODALITIES])) {
            $config->setOutputModalities(array_map(static fn(string $modality): ModalityEnum => ModalityEnum::from($modality), $array[self::KEY_OUTPUT_MODALITIES]));
        }
        if (isset($array[self::KEY_SYSTEM_INSTRUCTION])) {
            $config->setSystemInstruction($array[self::KEY_SYSTEM_INSTRUCTION]);
        }
        if (isset($array[self::KEY_CANDIDATE_COUNT])) {
            $config->setCandidateCount($array[self::KEY_CANDIDATE_COUNT]);
        }
        if (isset($array[self::KEY_MAX_TOKENS])) {
            $config->setMaxTokens($array[self::KEY_MAX_TOKENS]);
        }
        if (isset($array[self::KEY_TEMPERATURE])) {
            $config->setTemperature($array[self::KEY_TEMPERATURE]);
        }
        if (isset($array[self::KEY_TOP_P])) {
            $config->setTopP($array[self::KEY_TOP_P]);
        }
        if (isset($array[self::KEY_TOP_K])) {
            $config->setTopK($array[self::KEY_TOP_K]);
        }
        if (isset($array[self::KEY_STOP_SEQUENCES])) {
            $config->setStopSequences($array[self::KEY_STOP_SEQUENCES]);
        }
        if (isset($array[self::KEY_PRESENCE_PENALTY])) {
            $config->setPresencePenalty($array[self::KEY_PRESENCE_PENALTY]);
        }
        if (isset($array[self::KEY_FREQUENCY_PENALTY])) {
            $config->setFrequencyPenalty($array[self::KEY_FREQUENCY_PENALTY]);
        }
        if (isset($array[self::KEY_LOGPROBS])) {
            $config->setLogprobs($array[self::KEY_LOGPROBS]);
        }
        if (isset($array[self::KEY_TOP_LOGPROBS])) {
            $config->setTopLogprobs($array[self::KEY_TOP_LOGPROBS]);
        }
        if (isset($array[self::KEY_FUNCTION_DECLARATIONS])) {
            $config->setFunctionDeclarations(array_map(static function (array $functionDeclarationData): FunctionDeclaration {
                return FunctionDeclaration::fromArray($functionDeclarationData);
            }, $array[self::KEY_FUNCTION_DECLARATIONS]));
        }
        if (isset($array[self::KEY_WEB_SEARCH])) {
            $config->setWebSearch(WebSearch::fromArray($array[self::KEY_WEB_SEARCH]));
        }
        if (isset($array[self::KEY_OUTPUT_FILE_TYPE])) {
            $config->setOutputFileType(FileTypeEnum::from($array[self::KEY_OUTPUT_FILE_TYPE]));
        }
        if (isset($array[self::KEY_OUTPUT_MIME_TYPE])) {
            $config->setOutputMimeType($array[self::KEY_OUTPUT_MIME_TYPE]);
        }
        if (isset($array[self::KEY_OUTPUT_SCHEMA])) {
            $config->setOutputSchema($array[self::KEY_OUTPUT_SCHEMA]);
        }
        if (isset($array[self::KEY_OUTPUT_MEDIA_ORIENTATION])) {
            $config->setOutputMediaOrientation(MediaOrientationEnum::from($array[self::KEY_OUTPUT_MEDIA_ORIENTATION]));
        }
        if (isset($array[self::KEY_OUTPUT_MEDIA_ASPECT_RATIO])) {
            $config->setOutputMediaAspectRatio($array[self::KEY_OUTPUT_MEDIA_ASPECT_RATIO]);
        }
        if (isset($array[self::KEY_OUTPUT_SPEECH_VOICE])) {
            $config->setOutputSpeechVoice($array[self::KEY_OUTPUT_SPEECH_VOICE]);
        }
        if (isset($array[self::KEY_CUSTOM_OPTIONS])) {
            $config->setCustomOptions($array[self::KEY_CUSTOM_OPTIONS]);
        }
        return $config;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/php-ai-client/src/providers/models/dto/modelconfig.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/php-ai-client/src/Providers/Models/DTO/ModelConfig.php#L812)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/php-ai-client/src/Providers/Models/DTO/ModelConfig.php#L812-L881)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-models-dto-modelconfig/fromarray/?output_format=md#related)󠁿

| Uses | Description | 
| [WebSearch::fromArray()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-tools-dto-websearch/fromarray/)`wp-includes/php-ai-client/src/Tools/DTO/WebSearch.php` |

{@inheritDoc}

  | 
| [FunctionDeclaration::fromArray()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-tools-dto-functiondeclaration/fromarray/)`wp-includes/php-ai-client/src/Tools/DTO/FunctionDeclaration.php` |

{@inheritDoc}

  |

| Used by | Description | 
| [AbstractApiBasedModel::__construct()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-apibasedimplementation-abstractapibasedmodel/__construct/)`wp-includes/php-ai-client/src/Providers/ApiBasedImplementation/AbstractApiBasedModel.php` |

Constructor.

  | 
| [PromptBuilder::usingModel()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-builders-promptbuilder/usingmodel/)`wp-includes/php-ai-client/src/Builders/PromptBuilder.php` |

Sets the model to use for generation.

  | 
| [PromptBuilder::usingModelConfig()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-builders-promptbuilder/usingmodelconfig/)`wp-includes/php-ai-client/src/Builders/PromptBuilder.php` |

Sets the model configuration.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-models-dto-modelconfig/fromarray/?output_format=md#changelog)󠁿

| Version | Description | 
| [0.1.0](https://developer.wordpress.org/reference/since/0.1.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwordpress-aiclient-providers-models-dto-modelconfig%2Ffromarray%2F)
before being able to contribute a note or feedback.