|
| 1 | +## Getting started guide |
| 2 | + |
| 3 | +### How to run assistant on your own machine |
| 4 | +Below are the set of steps to run OpenSearch and OpenSearch dashboards with the OpenSearch assistant and the query generation functionality in the Observability Log Explorer page correctly on the cluster. |
| 5 | +**Note** that the `feature/langchain` is the branch used in this guide. |
| 6 | + |
| 7 | +1. Follow steps here to setup docker for OpenSearch: https://opensearch.org/docs/latest/install-and-configure/install-opensearch/docker/ |
| 8 | + 1. Note: When running docker pull, use this command instead: `docker pull public.ecr.aws/w1m7p7g2/opensearch-reinvent2023:latest` |
| 9 | + |
| 10 | + |
| 11 | +2. Follow steps here to setup docker to OpenSearch Dashboards: https://opensearch.org/docs/latest/install-and-configure/install-dashboards/docker/ |
| 12 | + 1. Note: When running docker pull, use this command instead for OSD: `docker pull public.ecr.aws/w1m7p7g2/opensearch-dashboards-reinvent2023:latest` |
| 13 | + 2. If you want to enable the chat assistant feature, set `assistant.chat.enabled` to `true` in the `opensearch_dashboards.yml` file. |
| 14 | +3. After OpenSearch and OpenSearch Dashboards are running, we will setup ML Commons to connect to the LLM model |
| 15 | +4. Run ML commons on Data node |
| 16 | + ``` |
| 17 | + PUT _cluster/settings |
| 18 | + { |
| 19 | + "persistent" : { |
| 20 | + "plugins.ml_commons.only_run_on_ml_node":"false" |
| 21 | + } |
| 22 | + } |
| 23 | + ``` |
| 24 | +5. Add Trusted Endpoints ([reference doc](https://opensearch.org/docs/latest/ml-commons-plugin/remote-models/index/)) |
| 25 | + ``` |
| 26 | + PUT _cluster/settings |
| 27 | + { |
| 28 | + "persistent" : { |
| 29 | + "plugins.ml_commons.trusted_connector_endpoints_regex": |
| 30 | + [ "^https://runtime\\.sagemaker\\..*[a-z0-9-]\\.amazonaws\\.com/.*$", |
| 31 | + "^https://api\\.openai\\.com/.*$", |
| 32 | + "^https://api\\.cohere\\.ai/.*$", |
| 33 | + "^https://bedrock-runtime\\.us-east-1\\.amazonaws\\.com/.*$" |
| 34 | + ] |
| 35 | + } |
| 36 | + } |
| 37 | + ``` |
| 38 | +6. Create a connector ([reference doc](https://opensearch.org/docs/latest/ml-commons-plugin/remote-models/index/)). The below example is for connecting to the AWS Bedrock Claude model. Keep note of the connector id from the API response. (Ensure the credentials passed should have access to call the LLM model) |
| 39 | + ``` |
| 40 | + POST /_plugins/_ml/connectors/_create |
| 41 | + { |
| 42 | + "name": "BedRock test claude Connector", |
| 43 | + "description": "The connector to BedRock service for claude model", |
| 44 | + "version": 1, |
| 45 | + "protocol": "aws_sigv4", |
| 46 | + "parameters": { |
| 47 | + "region": "us-east-1", |
| 48 | + "service_name": "bedrock", |
| 49 | + "anthropic_version": "bedrock-2023-05-31", |
| 50 | + "endpoint": "bedrock.us-east-1.amazonaws.com", |
| 51 | + "auth": "Sig_V4", |
| 52 | + "content_type": "application/json", |
| 53 | + "max_tokens_to_sample": 8000, |
| 54 | + "temperature": 0.0001, |
| 55 | + "response_filter": "$.completion" |
| 56 | + }, |
| 57 | + "credential": { |
| 58 | + "access_key": "<IAM access key>", |
| 59 | + "secret_key": "<IAM secret key" |
| 60 | + }, |
| 61 | + "actions": [ |
| 62 | + { |
| 63 | + "action_type": "predict", |
| 64 | + "method": "POST", |
| 65 | + "url": "https://bedrock-runtime.us-east-1.amazonaws.com/model/anthropic.claude-instant-v1/invoke", |
| 66 | + "headers": { |
| 67 | + "content-type": "application/json", |
| 68 | + "x-amz-content-sha256": "required" |
| 69 | + }, |
| 70 | + "request_body": "{\"prompt\":\"${parameters.prompt}\", \"max_tokens_to_sample\":${parameters.max_tokens_to_sample}, \"temperature\":${parameters.temperature}, \"anthropic_version\":\"${parameters.anthropic_version}\" }" |
| 71 | + } |
| 72 | + ] |
| 73 | + } |
| 74 | + ``` |
| 75 | +7. Create a model group with an example below ([reference doc](https://opensearch.org/docs/latest/ml-commons-plugin/remote-models/index/)) and note the model group id. |
| 76 | + ``` |
| 77 | + POST /_plugins/_ml/model_groups/_register |
| 78 | + { |
| 79 | + "name": "test_model_group_bedrock", |
| 80 | + "description": "This is a public model group" |
| 81 | + } |
| 82 | + ``` |
| 83 | +8. Create a model and note the model id |
| 84 | + ``` |
| 85 | + POST /_plugins/_ml/models/_register |
| 86 | + { |
| 87 | + "name": "Bedrock Claude instant model", |
| 88 | + "function_name": "remote", |
| 89 | + "model_group_id": "<model group id from previous API call>", |
| 90 | + "description": "test model", |
| 91 | + "connector_id": "<connector id from previous API call>" |
| 92 | + } |
| 93 | + ``` |
| 94 | +9. Create Embedding Model and note the model id from the get tasks API call |
| 95 | + ``` |
| 96 | + POST /_plugins/_ml/models/_register |
| 97 | + { |
| 98 | + "name": "huggingface/sentence-transformers/all-mpnet-base-v2", |
| 99 | + "version": "1.0.1", |
| 100 | + "model_group_id": "<model group id from previous API call>", |
| 101 | + "model_format": "TORCH_SCRIPT" |
| 102 | + } |
| 103 | + GET /_plugins/_ml/tasks/<task id from above model register call> |
| 104 | + ``` |
| 105 | +10. Deploy the LLM and embedding models. Confirm the model has been deployed with the task id from the response with the get tasks API call |
| 106 | + ``` |
| 107 | + POST /_plugins/_ml/models/<llm_model_id>/_deploy |
| 108 | + POST /_plugins/_ml/models/<embedding_model_id>/_deploy |
| 109 | + |
| 110 | + GET /_plugins/_ml/tasks/<task id from above deploy model calls> |
| 111 | + ``` |
| 112 | +11. Test connection with calling the Predict API |
| 113 | + ``` |
| 114 | + POST /_plugins/_ml/models/<llm_model_id>/_predict |
| 115 | + { |
| 116 | + "parameters": { |
| 117 | + "prompt": "\n\nHuman:hello\n\nnAssistant:" |
| 118 | + } |
| 119 | + } |
| 120 | + ``` |
| 121 | +12. Connect OS Assistant to the deployed models |
| 122 | + ``` |
| 123 | + POST /.chat-assistant-config/_doc/model-config |
| 124 | + { |
| 125 | + "model_type":"claude_bedrock", |
| 126 | + "model_id":"<model-id>", |
| 127 | + "embeddings_model_id":"<embedding-model-id>" |
| 128 | + } |
| 129 | + ``` |
| 130 | +### How to create your own skill |
| 131 | +1. To create your skill, you need to work backwards to see how that skill can be achieved by accessing different OpenSearch APIs/functions. For example, a skill to find the alerts related to a question would need to use the Alerting plugin APIs to get this info. |
| 132 | +1. To power the skill to get alerts, we must build a tool to search alerts. |
| 133 | +1. To create a tool, you must extend this [class](https://github.com/opensearch-project/ml-commons/blob/feature/agent_framework_dev/spi/src/main/java/org/opensearch/ml/common/spi/tools/Tool.java) and implement the specific tool. [This is an example tool](https://github.com/opensearch-project/ml-commons/pull/1629) that search alerts. |
0 commit comments