From eabd4d20083f2007d00d2e341fbba611fea71685 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Fri, 10 Nov 2023 16:48:32 -0800 Subject: [PATCH] Added Connector Blueprint for AI21 Labs Jurassic-2 Mid (#1613) (#1617) * Connector blueprint for AI21 Labs Jurassic-2 Mid * Removed all \r\n (cherry picked from commit 568bc7ec76e87de0b865835b031f99935cf5f4c2) Co-authored-by: Ricardo Ferreira --- ...k_connector_ai21labs_jurassic_blueprint.md | 171 ++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 docs/remote_inference_blueprints/bedrock_connector_ai21labs_jurassic_blueprint.md diff --git a/docs/remote_inference_blueprints/bedrock_connector_ai21labs_jurassic_blueprint.md b/docs/remote_inference_blueprints/bedrock_connector_ai21labs_jurassic_blueprint.md new file mode 100644 index 0000000000..0f9a1d8949 --- /dev/null +++ b/docs/remote_inference_blueprints/bedrock_connector_ai21labs_jurassic_blueprint.md @@ -0,0 +1,171 @@ +# Bedrock connector blueprint example for AI21 Labs Jurassic-2 Mid model + +## 1. Add connector endpoint to trusted URLs: + +Note: no need to do this after 2.11.0 + +```json +PUT /_cluster/settings +{ + "persistent": { + "plugins.ml_commons.trusted_connector_endpoints_regex": [ + "^https://bedrock-runtime\\..*[a-z0-9-]\\.amazonaws\\.com/.*$" + ] + } +} +``` + +## 2. Create connector for Amazon Bedrock: + +If you are using self-managed Opensearch, you should supply AWS credentials: + +```json +POST /_plugins/_ml/connectors/_create +{ + "name": "Amazon Bedrock", + "description": "Test connector for Amazon Bedrock", + "version": 1, + "protocol": "aws_sigv4", + "credential": { + "access_key": "", + "secret_key": "" + }, + "parameters": { + "region": "", + "service_name": "bedrock", + "model_name": "ai21.j2-mid-v1" + }, + "actions": [ + { + "action_type": "predict", + "method": "POST", + "headers": { + "content-type": "application/json" + }, + "url": "https://bedrock-runtime.${parameters.region}.amazonaws.com/model/${parameters.model_name}/invoke", + "request_body": "{\"prompt\":\"${parameters.inputs}\",\"maxTokens\":200,\"temperature\":0.7,\"topP\":1,\"stopSequences\":[],\"countPenalty\":{\"scale\":0},\"presencePenalty\":{\"scale\":0},\"frequencyPenalty\":{\"scale\":0}}", + "post_process_function": "\n return params['completions'][0].data.text; \n" + } + ] +} +``` + +If using the AWS Opensearch Service, you can provide an IAM role arn that allows access to the bedrock service. +Refer to this [AWS doc](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/ml-amazon-connector.html) + +```json +POST /_plugins/_ml/connectors/_create +{ + "name": "Amazon Bedrock", + "description": "Test connector for Amazon Bedrock", + "version": 1, + "protocol": "aws_sigv4", + "credential": { + "roleArn": "" + }, + "parameters": { + "region": "", + "service_name": "bedrock", + "model_name": "ai21.j2-mid-v1" + }, + "actions": [ + { + "action_type": "predict", + "method": "POST", + "headers": { + "content-type": "application/json" + }, + "url": "https://bedrock-runtime.${parameters.region}.amazonaws.com/model/${parameters.model_name}/invoke", + "request_body": "{\"prompt\":\"${parameters.inputs}\",\"maxTokens\":200,\"temperature\":0.7,\"topP\":1,\"stopSequences\":[],\"countPenalty\":{\"scale\":0},\"presencePenalty\":{\"scale\":0},\"frequencyPenalty\":{\"scale\":0}}", + "post_process_function": "\n return params['completions'][0].data.text; \n" + } + ] +} +``` + +Sample response: +```json +{ + "connector_id": "ya7VtYsB7ksezaHUlnwc" +} +``` + +## 3. Create model group: + +```json +POST /_plugins/_ml/model_groups/_register +{ + "name": "remote_model_group", + "description": "This is an example description" +} +``` + +Sample response: +```json +{ + "model_group_id": "yK7UtYsB7ksezaHU_nyt", + "status": "CREATED" +} +``` + +## 4. Register model to model group & deploy model: + +```json +POST /_plugins/_ml/models/_register +{ + "name": "anthropic.claude-v2", + "function_name": "remote", + "model_group_id": "yK7UtYsB7ksezaHU_nyt", + "description": "test model", + "connector_id": "ya7VtYsB7ksezaHUlnwc" +} +``` + +Sample response: +```json +{ + "task_id": "yq7WtYsB7ksezaHUSHyZ", + "status": "CREATED", + "model_id": "y67WtYsB7ksezaHUSHzq" +}``` + +Get model id from task +```json +GET /_plugins/_ml/tasks/yq7WtYsB7ksezaHUSHyZ +``` +Deploy model, in this demo the model id is `y67WtYsB7ksezaHUSHzq` + +```json +POST /_plugins/_ml/models/y67WtYsB7ksezaHUSHzq/_deploy +``` + +## 5. Test model inference + +```json +POST /_plugins/_ml/models/y67WtYsB7ksezaHUSHzq/_predict +{ + "parameters": { + "inputs": "What is the meaning of life?" + } +} +``` + +Sample response: +```json +{ + "inference_results": [ + { + "output": [ + { + "name": "response", + "dataAsMap": { + "response": """ +The meaning of life is a question that has puzzled philosophers and theologians for centuries. There is no single, definitive answer, as different people may have different meanings in life. However, some common themes include the quest for happiness, the desire for personal growth and fulfillment, and the quest to find purpose and meaning in one's existence. Ultimately, the meaning of life is a personal and subjective matter, and each individual must determine their own sense of purpose and fulfillment.""" + } + } + ], + "status_code": 200 + } + ] +} +``` \ No newline at end of file