Skip to content

Commit

Permalink
Updated opensearch-php to reflect the latest OpenSearch API spec (202…
Browse files Browse the repository at this point in the history
…5-02-06)

Signed-off-by: GitHub <[email protected]>
  • Loading branch information
dblock authored Feb 6, 2025
1 parent d35ea28 commit ff8bcf2
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
72 changes: 72 additions & 0 deletions src/OpenSearch/Endpoints/Ml/ExecuteAlgorithm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

declare(strict_types=1);

/**
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

namespace OpenSearch\Endpoints\Ml;

use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

/**
* NOTE: This file is autogenerated using util/GenerateEndpoints.php
*/
class ExecuteAlgorithm extends AbstractEndpoint
{
protected $algorithm_name;

public function getURI(): string
{
$algorithm_name = $this->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;
}
}
27 changes: 27 additions & 0 deletions src/OpenSearch/Namespaces/MlNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit ff8bcf2

Please sign in to comment.