Skip to content

Commit

Permalink
Merge branch 'main' into test-add-sessions-service-ut
Browse files Browse the repository at this point in the history
  • Loading branch information
wanglam authored Dec 14, 2023
2 parents 1213d9c + 7695943 commit 1ebb9b1
Show file tree
Hide file tree
Showing 16 changed files with 735 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This should match the owning team set up in https://github.com/orgs/opensearch-project/teams
* @pjfitzgibbons @ps48 @kavithacm @derek-ho @joshuali925 @dai-chen @YANG-DB @rupal-bq @mengweieric @vamsi-amazon @swiddis @penghuo @seankao-az @anirudha
* @lezzago @joshuali925 @anirudha @ruanyl @SuZhou-Joe @xluo-aws @gaobinlong @Hailong-am @wanglam @raintygao
23 changes: 20 additions & 3 deletions .whitesource
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,28 @@
"projectToken": "",
"baseBranches": []
},
"scanSettingsSAST": {
"enableScan": false,
"scanPullRequests": false,
"incrementalScan": true,
"baseBranches": [],
"snippetSize": 10
},
"checkRunSettings": {
"vulnerableCheckRunConclusionLevel": "failure",
"displayMode": "diff"
"displayMode": "diff",
"useMendCheckNames": true
},
"checkRunSettingsSAST": {
"checkRunConclusionLevel": "failure",
"severityThreshold": "high"
},
"issueSettings": {
"minSeverityLevel": "LOW"
"minSeverityLevel": "LOW",
"issueType": "DEPENDENCY"
},
"remediateSettings": {
"workflowRules": {
"enabled": true
}
}
}
61 changes: 58 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,59 @@
## Contributing to this Project
# Contributing Guidelines

OpenSearch is a community project that is built and maintained by people just like **you**.
[This document](https://github.com/opensearch-project/.github/blob/main/CONTRIBUTING.md) explains how you can contribute to this and related projects.
Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional
documentation, we greatly value feedback and contributions from our community.

Please read through this document before submitting any issues or pull requests to ensure we have all the necessary
information to effectively respond to your bug report or contribution.


## Reporting Bugs/Feature Requests

We welcome you to use the GitHub issue tracker to report bugs or suggest features.

When filing an issue, please check existing open, or recently closed, issues to make sure somebody else hasn't already
reported the issue. Please try to include as much information as you can. Details like these are incredibly useful:

* A reproducible test case or series of steps
* The version of our code being used
* Any modifications you've made relevant to the bug
* Anything unusual about your environment or deployment


## Contributing via Pull Requests
Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that:

1. You are working against the latest source on the *main* branch.
2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already.
3. You open an issue to discuss any significant work - we would hate for your time to be wasted.

To send us a pull request, please:

1. Fork the repository.
2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change.
3. Ensure local tests pass.
4. Commit to your fork using clear commit messages.
5. Send us a pull request, answering any default questions in the pull request interface.
6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation.

GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and
[creating a pull request](https://help.github.com/articles/creating-a-pull-request/).


## Finding contributions to work on
Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any 'help wanted' issues is a great place to start.


## Code of Conduct
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
[email protected] with any additional questions or comments.


## Security issue notifications
If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue.


## Licensing

See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution.
83 changes: 58 additions & 25 deletions DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
## Developer Guide
- [Developer guide](#developer-guide)
- [Forking and Cloning](#forking-and-cloning)
- [Install Prerequisites](#install-prerequisites)
- [Environment Setup](#environment-setup)
- [Build](#build)
- [Run](#run)
- [Test](#test)

## Developer guide

So you want to contribute code to this project? Excellent! We're glad you're here. Here's what you need to do.

### Setup
### Forking and Cloning

1. Download OpenSearch for the version that matches the [OpenSearch Dashboards version specified in opensearch_dashboards.json](./opensearch_dashboards.json#L4) from [opensearch.org](https://opensearch.org/downloads.html).
1. Download the OpenSearch Dashboards source code for the [version specified in opensearch_dashboards.json](./opensearch_dashboards.json#L4) you want to set up.
1. Change your node version to the version specified in `.node-version` inside the OpenSearch Dashboards root directory.
1. cd into `OpenSearch-Dashboards` and remove the `plugins` directory.
1. Check out this package from version control as the `plugins/dashboards-assistant` directory.
```bash
git clone https://github.com/opensearch-project/dashboards-assistant plugins
git checkout main
```
6. Run `yarn osd bootstrap` inside `OpenSearch-Dashboards`.
Fork this repository on GitHub, and clone locally with `git clone`.

### Install Prerequisites

You will need to install [node.js](https://nodejs.org/en/), [nvm](https://github.com/nvm-sh/nvm/blob/master/README.md), and [yarn](https://yarnpkg.com/) in your environment to properly pull down dependencies to build and bootstrap the plugin.

### Environment Setup

1. Download OpenSearch for the version that matches the [OpenSearch Dashboard version specified in package.json](./package.json#L9).
1. Download and install the appropriate [OpenSearch ML Commons plugin](https://github.com/opensearch-project/ml-commons).
1. Download the OpenSearch-Dashboards source code for the [version specified in package.json](./package.json#L9) you want to set up.

See the [OpenSearch Dashboards developer guide](https://github.com/opensearch-project/OpenSearch-Dashboards/blob/main/DEVELOPER_GUIDE.md) for more instructions on setting up your development environment.

1. Change your node version to the version specified in `.node-version` inside the OpenSearch-Dashboards root directory.
1. cd into the `plugins` directory of the OpenSearch-Dashboards source code directory.
1. Check out this package from version control into the `plugins` directory.
1. Set `assistant.chat.enabled` to `true` in `opensearch_dashboards.yml` if you want to enable the chat feature.
1. Run `yarn osd bootstrap` inside `Opensearch-Dashboards/plugins/dashboards-assistant`.

Ultimately, your directory structure should look like this:

Expand All @@ -24,24 +41,40 @@ Ultimately, your directory structure should look like this:
│ └── dashboards-assistant
```

### Build

To build the plugin's distributable zip simply run `yarn build` in the plugin's directory.
## Build

To build the plugin's distributable zip simply run `yarn build`.

Example output: `./build/assistantDashboards-2.11.0.zip`

Example output: `./build/assistant*.zip`

### Run
## Run

cd back to `OpenSearch-Dashboards` directory and run `yarn start` to start OpenSearch Dashboards including this plugin. OpenSearch Dashboards will be available on `localhost:5601`.
- `yarn start`

### Submitting Changes
- Starts OpenSearch-Dashboards and includes this plugin. OpenSearch-Dashboards will be available on `localhost:5601`.
- Please run in the OpenSearch-Dashboards root directory
- You must have OpenSearch running with the ML Commons plugin

## Test

There are unit/stubbed integration tests.

- `yarn test`

- Runs the plugin unit tests.

### Formatting

This codebase uses Prettier as our code formatter. All new code that is added has to be reformatted using the Prettier version listed in `package.json`. In order to keep consistent formatting across the project developers should only use the prettier CLI to reformat their code using the following command:

```
yarn lint --fix
```

See [CONTRIBUTING](CONTRIBUTING.md).
> NOTE: There also exists prettier plugins on several editors that allow for automatic reformatting on saving the file. However using this is discouraged as you must ensure that the plugin uses the correct version of prettier (listed in `package.json`) before using such a plugin.
### Backports
### Backport

The Github workflow in [`backport.yml`](.github/workflows/backport.yml) creates backport PRs automatically when the original PR
with an appropriate label `backport <backport-branch-name>` is merged to main with the backport workflow run successfully on the
PR. For example, if a PR on main needs to be backported to `1.x` branch, add a label `backport 1.x` to the PR and make sure the
backport workflow runs on the PR along with other checks. Once this PR is merged to main, the workflow will create a backport PR
to the `1.x` branch.
- [Link to backport documentation](https://github.com/opensearch-project/opensearch-plugins/blob/main/BACKPORT.md)
153 changes: 153 additions & 0 deletions GETTING_STARTED_GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
## Getting started guide

### How to run assistant on your own machine
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.
**Note** that the `feature/langchain` is the branch used in this guide.

1. Follow steps here to setup docker for OpenSearch: https://opensearch.org/docs/latest/install-and-configure/install-opensearch/docker/
1. Note: When running docker pull, use this command instead: `docker pull public.ecr.aws/w1m7p7g2/opensearch-reinvent2023:latest`
2. Note: This docker image may get incrementally updated over time.


2. Follow steps here to setup docker to OpenSearch Dashboards: https://opensearch.org/docs/latest/install-and-configure/install-dashboards/docker/
1. Note: When running docker pull, use this command instead for OSD: `docker pull public.ecr.aws/w1m7p7g2/opensearch-dashboards-reinvent2023:latest`
2. Note: This docker image may get incrementally updated over time.
3. If you want to enable the chat assistant feature, set `assistant.chat.enabled` to `true` in the `opensearch_dashboards.yml` file.
3. After OpenSearch and OpenSearch Dashboards are running, we will setup ML Commons to connect to the LLM model
4. Run ML commons on Data node
```
PUT _cluster/settings
{
"persistent" : {
"plugins.ml_commons.only_run_on_ml_node":"false"
}
}
```
5. Add Trusted Endpoints ([reference doc](https://opensearch.org/docs/latest/ml-commons-plugin/remote-models/index/))
```
PUT _cluster/settings
{
"persistent" : {
"plugins.ml_commons.trusted_connector_endpoints_regex":
[ "^https://runtime\\.sagemaker\\..*[a-z0-9-]\\.amazonaws\\.com/.*$",
"^https://api\\.openai\\.com/.*$",
"^https://api\\.cohere\\.ai/.*$",
"^https://bedrock-runtime\\.us-east-1\\.amazonaws\\.com/.*$"
]
}
}
```
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)
```
POST /_plugins/_ml/connectors/_create
{
"name": "BedRock test claude Connector",
"description": "The connector to BedRock service for claude model",
"version": 1,
"protocol": "aws_sigv4",
"parameters": {
"region": "us-east-1",
"service_name": "bedrock",
"anthropic_version": "bedrock-2023-05-31",
"endpoint": "bedrock.us-east-1.amazonaws.com",
"auth": "Sig_V4",
"content_type": "application/json",
"max_tokens_to_sample": 8000,
"temperature": 0.0001,
"response_filter": "$.completion"
},
"credential": {
"access_key": "<IAM access key>",
"secret_key": "<IAM secret key"
},
"actions": [
{
"action_type": "predict",
"method": "POST",
"url": "https://bedrock-runtime.us-east-1.amazonaws.com/model/anthropic.claude-instant-v1/invoke",
"headers": {
"content-type": "application/json",
"x-amz-content-sha256": "required"
},
"request_body": "{\"prompt\":\"${parameters.prompt}\", \"max_tokens_to_sample\":${parameters.max_tokens_to_sample}, \"temperature\":${parameters.temperature}, \"anthropic_version\":\"${parameters.anthropic_version}\" }"
}
]
}
```
1. If you are using AWS Bedrock, ensure the IAM user or IAM role used have these policy permissions. Feel free to restrict the resources to the specific endpoints you want ML Commons to connect to.
```
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1688544995813",
"Action": [
"bedrock:ListBuiltInModels",
"bedrock:ListFoundationModels",
"bedrock:InvokeModel"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
```
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.
```
POST /_plugins/_ml/model_groups/_register
{
"name": "test_model_group_bedrock",
"description": "This is a public model group"
}
```
8. Create a model and note the model id
```
POST /_plugins/_ml/models/_register
{
"name": "Bedrock Claude instant model",
"function_name": "remote",
"model_group_id": "<model group id from previous API call>",
"description": "test model",
"connector_id": "<connector id from previous API call>"
}
```
9. Create Embedding Model and note the model id from the get tasks API call
```
POST /_plugins/_ml/models/_register
{
"name": "huggingface/sentence-transformers/all-mpnet-base-v2",
"version": "1.0.1",
"model_group_id": "<model group id from previous API call>",
"model_format": "TORCH_SCRIPT"
}
GET /_plugins/_ml/tasks/<task id from above model register call>
```
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
```
POST /_plugins/_ml/models/<llm_model_id>/_deploy
POST /_plugins/_ml/models/<embedding_model_id>/_deploy

GET /_plugins/_ml/tasks/<task id from above deploy model calls>
```
11. Test connection with calling the Predict API
```
POST /_plugins/_ml/models/<llm_model_id>/_predict
{
"parameters": {
"prompt": "\n\nHuman:hello\n\nnAssistant:"
}
}
```
12. Connect OS Assistant to the deployed models
```
POST /.chat-assistant-config/_doc/model-config
{
"model_type":"claude_bedrock",
"model_id":"<model-id>",
"embeddings_model_id":"<embedding-model-id>"
}
```
### How to create your own skill
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.
1. To power the skill to get alerts, we must build a tool to search alerts.
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.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,4 @@
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
Loading

0 comments on commit 1ebb9b1

Please sign in to comment.