diff --git a/CHANGELOG.md b/CHANGELOG.md index 885ac600..5539362a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,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@d8e4583](https://github.com/opensearch-project/opensearch-api-specification/commit/d8e45836afad678ab02f7e729e43b850443b90fb) - Updated opensearch-php APIs to reflect [opensearch-api-specification@1422af3](https://github.com/opensearch-project/opensearch-api-specification/commit/1422af3cddc8140fe9c3d59ee0205b278e193bb9) - Updated opensearch-php APIs to reflect [opensearch-api-specification@2395cb4](https://github.com/opensearch-project/opensearch-api-specification/commit/2395cb472ec5581656aac184f7b20548cd5b06ac) - Updated opensearch-php APIs to reflect [opensearch-api-specification@ebe0f8a](https://github.com/opensearch-project/opensearch-api-specification/commit/ebe0f8a885f7db7e882d160c101055a5aa70a707) diff --git a/src/OpenSearch/Endpoints/Ml/ExecuteAgent.php b/src/OpenSearch/Endpoints/Ml/ExecuteAgent.php new file mode 100644 index 00000000..f41687ba --- /dev/null +++ b/src/OpenSearch/Endpoints/Ml/ExecuteAgent.php @@ -0,0 +1,72 @@ +agent_id ?? null; + if (isset($agent_id)) { + return "/_plugins/_ml/agents/$agent_id/_execute"; + } + throw new RuntimeException('Missing parameter for the endpoint ml.execute_agent'); + } + + 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 setAgentId($agent_id): static + { + if (is_null($agent_id)) { + return $this; + } + $this->agent_id = $agent_id; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Ml/GetAgent.php b/src/OpenSearch/Endpoints/Ml/GetAgent.php new file mode 100644 index 00000000..6d3d16c1 --- /dev/null +++ b/src/OpenSearch/Endpoints/Ml/GetAgent.php @@ -0,0 +1,62 @@ +agent_id ?? null; + if (isset($agent_id)) { + return "/_plugins/_ml/agents/$agent_id"; + } + throw new RuntimeException('Missing parameter for the endpoint ml.get_agent'); + } + + public function getParamWhitelist(): array + { + return [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ]; + } + + public function getMethod(): string + { + return 'GET'; + } + + public function setAgentId($agent_id): static + { + if (is_null($agent_id)) { + return $this; + } + $this->agent_id = $agent_id; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Ml/GetAllTools.php b/src/OpenSearch/Endpoints/Ml/GetAllTools.php new file mode 100644 index 00000000..19ef499c --- /dev/null +++ b/src/OpenSearch/Endpoints/Ml/GetAllTools.php @@ -0,0 +1,45 @@ +tool_name ?? null; + if (isset($tool_name)) { + return "/_plugins/_ml/tools/$tool_name"; + } + throw new RuntimeException('Missing parameter for the endpoint ml.get_tool'); + } + + public function getParamWhitelist(): array + { + return [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ]; + } + + public function getMethod(): string + { + return 'GET'; + } + + public function setToolName($tool_name): static + { + if (is_null($tool_name)) { + return $this; + } + $this->tool_name = $tool_name; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Ml/SearchAgents.php b/src/OpenSearch/Endpoints/Ml/SearchAgents.php new file mode 100644 index 00000000..b236cd93 --- /dev/null +++ b/src/OpenSearch/Endpoints/Ml/SearchAgents.php @@ -0,0 +1,55 @@ +body) ? 'POST' : 'GET'; + } + + public function setBody($body): static + { + if (is_null($body)) { + return $this; + } + $this->body = $body; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Ml/SearchTasks.php b/src/OpenSearch/Endpoints/Ml/SearchTasks.php new file mode 100644 index 00000000..75bb1119 --- /dev/null +++ b/src/OpenSearch/Endpoints/Ml/SearchTasks.php @@ -0,0 +1,55 @@ +body) ? 'POST' : 'GET'; + } + + public function setBody($body): static + { + if (is_null($body)) { + return $this; + } + $this->body = $body; + + return $this; + } +} diff --git a/src/OpenSearch/Namespaces/MlNamespace.php b/src/OpenSearch/Namespaces/MlNamespace.php index 4b3961bc..c578de47 100644 --- a/src/OpenSearch/Namespaces/MlNamespace.php +++ b/src/OpenSearch/Namespaces/MlNamespace.php @@ -293,6 +293,56 @@ public function deleteTask(array $params = []) return $this->performRequest($endpoint); } + /** + * Execute an agent. + * + * $params['agent_id'] = (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 executeAgent(array $params = []) + { + $agent_id = $this->extractArgument($params, 'agent_id'); + $body = $this->extractArgument($params, 'body'); + + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\ExecuteAgent::class); + $endpoint->setParams($params); + $endpoint->setAgentId($agent_id); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } + + /** + * Get an agent. + * + * $params['agent_id'] = (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 getAgent(array $params = []) + { + $agent_id = $this->extractArgument($params, 'agent_id'); + + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\GetAgent::class); + $endpoint->setParams($params); + $endpoint->setAgentId($agent_id); + + return $this->performRequest($endpoint); + } + /** * Get all memories. * @@ -341,6 +391,26 @@ public function getAllMessages(array $params = []) return $this->performRequest($endpoint); } + /** + * Get tools. + * + * $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 getAllTools(array $params = []) + { + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\GetAllTools::class); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + /** * Retrieves a controller. * @@ -589,6 +659,30 @@ public function getTask(array $params = []) return $this->performRequest($endpoint); } + /** + * Get tools. + * + * $params['tool_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 getTool(array $params = []) + { + $tool_name = $this->extractArgument($params, 'tool_name'); + + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\GetTool::class); + $endpoint->setParams($params); + $endpoint->setToolName($tool_name); + + return $this->performRequest($endpoint); + } + /** * Deploys a model. * @@ -731,6 +825,29 @@ public function registerModelMeta(array $params = []) return $this->performRequest($endpoint); } + /** + * Search agents. + * + * $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 searchAgents(array $params = []) + { + $body = $this->extractArgument($params, 'body'); + + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\SearchAgents::class); + $endpoint->setParams($params); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } + /** * Searches for standalone connectors. * @@ -849,6 +966,29 @@ public function searchModels(array $params = []) return $this->performRequest($endpoint); } + /** + * Searches for tasks. + * + * $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 searchTasks(array $params = []) + { + $body = $this->extractArgument($params, 'body'); + + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\SearchTasks::class); + $endpoint->setParams($params); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } + /** * Trains a model synchronously. *