From ff8bcf24f08f764a33a9ac45a64489f82e2be6ef Mon Sep 17 00:00:00 2001 From: dblock Date: Thu, 6 Feb 2025 03:36:57 +0000 Subject: [PATCH] Updated opensearch-php to reflect the latest OpenSearch API spec (2025-02-06) Signed-off-by: GitHub --- CHANGELOG.md | 2 + .../Endpoints/Ml/ExecuteAlgorithm.php | 72 +++++++++++++++++++ src/OpenSearch/Namespaces/MlNamespace.php | 27 +++++++ 3 files changed, 101 insertions(+) create mode 100644 src/OpenSearch/Endpoints/Ml/ExecuteAlgorithm.php diff --git a/CHANGELOG.md b/CHANGELOG.md index d154844d..dc2e2902 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Security ### Dependencies ### Updated APIs +- Updated opensearch-php APIs to reflect [opensearch-api-specification@5644cab](https://github.com/opensearch-project/opensearch-api-specification/commit/5644cabe471da4d98c4019c3712d2aad054cbd00) ## [2.4.0] ### Added @@ -42,6 +43,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Fixed PHP 8.4 deprecations - Fixed outdated tests ### Updated APIs +- Updated opensearch-php APIs to reflect [opensearch-api-specification@5644cab](https://github.com/opensearch-project/opensearch-api-specification/commit/5644cabe471da4d98c4019c3712d2aad054cbd00) - Updated opensearch-php APIs to reflect [opensearch-api-specification@b9dcb25](https://github.com/opensearch-project/opensearch-api-specification/commit/b9dcb251d551e90ecfc416ba134efe83cbcbc1b3) - Updated opensearch-php APIs to reflect [opensearch-api-specification@9df46f8](https://github.com/opensearch-project/opensearch-api-specification/commit/9df46f8134641ae5b429e3e9269858c7cb27e4f0) - Updated opensearch-php APIs to reflect [opensearch-api-specification@592336a](https://github.com/opensearch-project/opensearch-api-specification/commit/592336afb88844f0c5785ba4b085dba3884ac580) diff --git a/src/OpenSearch/Endpoints/Ml/ExecuteAlgorithm.php b/src/OpenSearch/Endpoints/Ml/ExecuteAlgorithm.php new file mode 100644 index 00000000..a04bb980 --- /dev/null +++ b/src/OpenSearch/Endpoints/Ml/ExecuteAlgorithm.php @@ -0,0 +1,72 @@ +algorithm_name ?? null; + if (isset($algorithm_name)) { + return "/_plugins/_ml/_execute/$algorithm_name"; + } + throw new RuntimeException('Missing parameter for the endpoint ml.execute_algorithm'); + } + + public function getParamWhitelist(): array + { + return [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ]; + } + + public function getMethod(): string + { + return 'POST'; + } + + public function setBody($body): static + { + if (is_null($body)) { + return $this; + } + $this->body = $body; + + return $this; + } + + public function setAlgorithmName($algorithm_name): static + { + if (is_null($algorithm_name)) { + return $this; + } + $this->algorithm_name = $algorithm_name; + + return $this; + } +} diff --git a/src/OpenSearch/Namespaces/MlNamespace.php b/src/OpenSearch/Namespaces/MlNamespace.php index 8a334d94..243404f9 100644 --- a/src/OpenSearch/Namespaces/MlNamespace.php +++ b/src/OpenSearch/Namespaces/MlNamespace.php @@ -30,6 +30,7 @@ use OpenSearch\Endpoints\Ml\DeleteTask; use OpenSearch\Endpoints\Ml\DeployModel; use OpenSearch\Endpoints\Ml\ExecuteAgent; +use OpenSearch\Endpoints\Ml\ExecuteAlgorithm; use OpenSearch\Endpoints\Ml\GetAgent; use OpenSearch\Endpoints\Ml\GetAllMemories; use OpenSearch\Endpoints\Ml\GetAllMessages; @@ -380,6 +381,32 @@ public function executeAgent(array $params = []) return $this->performRequest($endpoint); } + /** + * Execute an algorithm. + * + * $params['algorithm_name'] = (string) + * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) + * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) + * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) + * $params['source'] = (string) The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests. + * $params['filter_path'] = (any) Used to reduce the response. This parameter takes a comma-separated list of filters. It supports using wildcards to match any field or part of a field’s name. You can also exclude fields with "-". + * + * @param array $params Associative array of parameters + * @return array + */ + public function executeAlgorithm(array $params = []) + { + $algorithm_name = $this->extractArgument($params, 'algorithm_name'); + $body = $this->extractArgument($params, 'body'); + + $endpoint = $this->endpointFactory->getEndpoint(ExecuteAlgorithm::class); + $endpoint->setParams($params); + $endpoint->setAlgorithmName($algorithm_name); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } + /** * Get an agent. *