opensearch-docs-cn/_ml-commons-plugin/agents-tools/tools/ml-model-tool.md

170 lines
4.7 KiB
Markdown
Raw Normal View History

Add agent framework/throttling/hidden model/OS assistant and update conversational search documentation (#6354) * Add agent framework documentation Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> * Add hidden model and API updates Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> * Vale error Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> * Updated field names Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> * Add updating credentials Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> * Added tools table Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> * Add OpenSearch forum thread for OS Assistant Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> * Add tech review for conv search Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> * Fix links Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> * Add tools Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> * Add links to tools Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> * More info about tools Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> * Tool parameters Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> * Update cat-index-tool.md Signed-off-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> * Parameter clarification Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> * Tech review feedback Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> * Typo fix Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> * More tech review feedback: RAG tool Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> * Tech review feedback: memory APis Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> * Update _ml-commons-plugin/agents-tools/index.md Co-authored-by: Melissa Vagi <vagimeli@amazon.com> Signed-off-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> * Update _ml-commons-plugin/agents-tools/tools/neural-sparse-tool.md Co-authored-by: Melissa Vagi <vagimeli@amazon.com> Signed-off-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> * Update _ml-commons-plugin/agents-tools/tools/neural-sparse-tool.md Co-authored-by: Melissa Vagi <vagimeli@amazon.com> Signed-off-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> * Update _ml-commons-plugin/agents-tools/tools/neural-sparse-tool.md Co-authored-by: Melissa Vagi <vagimeli@amazon.com> Signed-off-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> * Update _ml-commons-plugin/opensearch-assistant.md Co-authored-by: Melissa Vagi <vagimeli@amazon.com> Signed-off-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> * Update _ml-commons-plugin/agents-tools/tools/ppl-tool.md Co-authored-by: Melissa Vagi <vagimeli@amazon.com> Signed-off-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Melissa Vagi <vagimeli@amazon.com> Signed-off-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> * Separated search and get APIs and add conversational flow agent Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> * More parameters for PPL tool Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> * Added more parameters Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> * Tech review feedback: PPL tool Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> * Apply suggestions from code review Co-authored-by: Nathan Bower <nbower@amazon.com> Signed-off-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> * Rename to automating configurations Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> * Editorial comments on the new text Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> * Add parameter to PPl tool Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> * Changed link to configurations Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> * Rate limiter feedback and added warning Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> --------- Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> Signed-off-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> Co-authored-by: Melissa Vagi <vagimeli@amazon.com> Co-authored-by: Nathan Bower <nbower@amazon.com>
2024-02-20 12:09:31 -05:00
---
layout: default
title: ML Model tool
has_children: false
has_toc: false
nav_order: 40
parent: Tools
grand_parent: Agents and tools
---
<!-- vale off -->
# ML Model tool
**Introduced 2.12**
{: .label .label-purple }
<!-- vale on -->
This is an experimental feature and is not recommended for use in a production environment. For updates on the progress of the feature or if you want to leave feedback, see the associated [GitHub issue](https://github.com/opensearch-project/ml-commons/issues/1161).
{: .warning}
The `MLModelTool` runs a machine learning (ML) model and returns inference results.
## Step 1: Create a connector for a model
The following example request creates a connector for a model hosted on [Amazon SageMaker](https://aws.amazon.com/pm/sagemaker/):
```json
POST /_plugins/_ml/connectors/_create
{
"name": "sagemaker model",
"description": "Test connector for Sagemaker model",
"version": 1,
"protocol": "aws_sigv4",
"credential": {
"access_key": "<YOUR ACCESS KEY>",
"secret_key": "<YOUR SECRET KEY>"
},
"parameters": {
"region": "us-east-1",
"service_name": "sagemaker"
},
"actions": [
{
"action_type": "predict",
"method": "POST",
"headers": {
"content-type": "application/json"
},
"url": "<YOUR SAGEMAKER ENDPOINT>",
"request_body": """{"prompt":"${parameters.prompt}"}"""
}
]
}
```
{% include copy-curl.html %}
OpenSearch responds with a connector ID:
```json
{
"connector_id": "eJATWo0BkIylWTeYToTn"
}
```
## Step 2: Register and deploy the model
To register and deploy the model to OpenSearch, send the following request, providing the connector ID from the previous step:
```json
POST /_plugins/_ml/models/_register?deploy=true
{
"name": "remote-inferene",
"function_name": "remote",
"description": "test model",
"connector_id": "eJATWo0BkIylWTeYToTn"
}
```
{% include copy-curl.html %}
OpenSearch responds with a model ID:
```json
{
"task_id": "7X7pWI0Bpc3sThaJ4I8R",
"status": "CREATED",
"model_id": "h5AUWo0BkIylWTeYT4SU"
}
```
## Step 3: Register a flow agent that will run the MLModelTool
A flow agent runs a sequence of tools in order and returns the last tool's output. To create a flow agent, send the following register agent request, providing the model ID in the `model_id` parameter:
```json
POST /_plugins/_ml/agents/_register
{
"name": "Test agent for embedding model",
"type": "flow",
"description": "this is a test agent",
"tools": [
{
"type": "MLModelTool",
"description": "A general tool to answer any question",
"parameters": {
"model_id": "h5AUWo0BkIylWTeYT4SU",
"prompt": "\n\nHuman:You are a professional data analyst. You will always answer question based on the given context first. If the answer is not directly shown in the context, you will analyze the data and find the answer. If you don't know the answer, just say don't know. \n\nHuman:${parameters.question}\n\nAssistant:"
}
}
]
}
```
{% include copy-curl.html %}
For parameter descriptions, see [Register parameters](#register-parameters).
OpenSearch responds with an agent ID:
```json
{
"agent_id": "9X7xWI0Bpc3sThaJdY9i"
}
```
## Step 4: Run the agent
Run the agent by sending the following request:
```json
POST /_plugins/_ml/agents/9X7xWI0Bpc3sThaJdY9i/_execute
{
"parameters": {
"question": "what's the population increase of Seattle from 2021 to 2023"
}
}
```
{% include copy-curl.html %}
OpenSearch returns the inference results:
```json
{
"inference_results": [
{
"output": [
{
"name": "response",
"result": " I do not have direct data on the population increase of Seattle from 2021 to 2023 in the context provided. As a data analyst, I would need to research population statistics from credible sources like the US Census Bureau to analyze population trends and make an informed estimate. Without looking up actual data, I don't have enough information to provide a specific answer to the question."
}
]
}
]
}
```
## Register parameters
The following table lists all tool parameters that are available when registering an agent.
Parameter | Type | Required/Optional | Description
:--- | :--- | :--- | :---
`model_id` | String | Required | The model ID of the large language model (LLM) to use for generating the response.
`prompt` | String | Optional | The prompt to provide to the LLM.
`response_field` | String | Optional | The name of the response field. Default is `response`.
## Execute parameters
The following table lists all tool parameters that are available when running the agent.
Parameter | Type | Required/Optional | Description
:--- | :--- | :--- | :---
`question` | String | Required | The natural language question to send to the LLM.