From fe61a192ecd9f30fb2e4be0754275a19e47aa002 Mon Sep 17 00:00:00 2001 From: Yaliang Wu Date: Mon, 6 Nov 2023 10:38:23 -0800 Subject: [PATCH] add openai embedding model blueprint (#1583) Signed-off-by: Yaliang Wu --- ...ck_connector_anthropic_claude_blueprint.md | 54 ++++-- ...ock_connector_titan_embedding_blueprint.md | 22 +-- .../openai_connector_embedding_blueprint.md | 161 ++++++++++++++++++ 3 files changed, 213 insertions(+), 24 deletions(-) create mode 100644 docs/remote_inference_blueprints/openai_connector_embedding_blueprint.md diff --git a/docs/remote_inference_blueprints/bedrock_connector_anthropic_claude_blueprint.md b/docs/remote_inference_blueprints/bedrock_connector_anthropic_claude_blueprint.md index 122afb5717..5e99440593 100644 --- a/docs/remote_inference_blueprints/bedrock_connector_anthropic_claude_blueprint.md +++ b/docs/remote_inference_blueprints/bedrock_connector_anthropic_claude_blueprint.md @@ -1,6 +1,8 @@ -### Bedrock connector blueprint example +# Bedrock connector blueprint example for Claude V2 model -1. Add connector endpoint to trusted URLs: +## 1. Add connector endpoint to trusted URLs: + +Note: no need to do this after 2.11.0 ```json PUT /_cluster/settings @@ -13,7 +15,7 @@ PUT /_cluster/settings } ``` -2. Create connector for Amazon Bedrock: +## 2. Create connector for Amazon Bedrock: If you are using self-managed Opensearch, you should supply AWS credentials: @@ -78,12 +80,14 @@ POST /_plugins/_ml/connectors/_create } ``` -Response: +Sample response: ```json -{"connector_id":"SHDj-ooB0wiuGR4S5sM4"} +{ + "connector_id": "SHDj-ooB0wiuGR4S5sM4" +} ``` -3. Create model group: +## 3. Create model group: ```json POST /_plugins/_ml/model_groups/_register @@ -93,12 +97,15 @@ POST /_plugins/_ml/model_groups/_register } ``` -Response: +Sample response: ```json -{"model_group_id":"SXDn-ooB0wiuGR4SrcNN","status":"CREATED"} +{ + "model_group_id": "SXDn-ooB0wiuGR4SrcNN", + "status": "CREATED" +} ``` -4. Register model to model group & deploy model: +## 4. Register model to model group & deploy model: ```json POST /_plugins/_ml/models/_register @@ -111,20 +118,25 @@ POST /_plugins/_ml/models/_register } ``` -Response: +Sample response: ```json -{"task_id":"SnDo-ooB0wiuGR4SfMNS","status":"CREATED"} +{ + "task_id": "SnDo-ooB0wiuGR4SfMNS", + "status": "CREATED" +} ``` +Get model id from task ```json GET /_plugins/_ml/tasks/SnDo-ooB0wiuGR4SfMNS ``` +Deploy model, in this demo the model id is `S3Do-ooB0wiuGR4SfcNv` ```json POST /_plugins/_ml/models/S3Do-ooB0wiuGR4SfcNv/_deploy ``` -5. Test model inference +## 5. Test model inference ```json POST /_plugins/_ml/models/S3Do-ooB0wiuGR4SfcNv/_predict @@ -135,7 +147,21 @@ POST /_plugins/_ml/models/S3Do-ooB0wiuGR4SfcNv/_predict } ``` -Response: +Sample response: ```json -{"inference_results":[{"output":[{"name":"response","dataAsMap":{"completion":" There is no single, universally agreed upon meaning of life. The meaning of life is subjective and personal. Some common perspectives include finding happiness, purpose, spiritual fulfillment, connecting with others, contributing value, and leaving a positive legacy. Ultimately, the meaning of life is what you make of it.","stop_reason":"stop_sequence"}}]}]} +{ + "inference_results": [ + { + "output": [ + { + "name": "response", + "dataAsMap": { + "completion": " There is no single, universally agreed upon meaning of life. The meaning of life is subjective and personal. Some common perspectives include finding happiness, purpose, spiritual fulfillment, connecting with others, contributing value, and leaving a positive legacy. Ultimately, the meaning of life is what you make of it.", + "stop_reason": "stop_sequence" + } + } + ] + } + ] +} ``` \ No newline at end of file diff --git a/docs/remote_inference_blueprints/bedrock_connector_titan_embedding_blueprint.md b/docs/remote_inference_blueprints/bedrock_connector_titan_embedding_blueprint.md index 8cf69a4d85..97002fb934 100644 --- a/docs/remote_inference_blueprints/bedrock_connector_titan_embedding_blueprint.md +++ b/docs/remote_inference_blueprints/bedrock_connector_titan_embedding_blueprint.md @@ -1,6 +1,8 @@ -### Bedrock connector blueprint example +# Bedrock connector blueprint example for Titan embedding model -1. Add connector endpoint to trusted URLs: +## 1. Add connector endpoint to trusted URLs: + +Note: no need to do this after 2.11.0 ```json PUT /_cluster/settings @@ -13,7 +15,7 @@ PUT /_cluster/settings } ``` -2. Create connector for Amazon Bedrock: +## 2. Create connector for Amazon Bedrock: If you are using self-managed Opensearch, you should supply AWS credentials: @@ -84,14 +86,14 @@ POST /_plugins/_ml/connectors/_create } ``` -Response: +Sample response: ```json { "connector_id": "nzh9PIsBnGXNcxYpPEcv" } ``` -3. Create model group: +## 3. Create model group: ```json POST /_plugins/_ml/model_groups/_register @@ -101,7 +103,7 @@ POST /_plugins/_ml/model_groups/_register } ``` -Response: +Sample response: ```json { "model_group_id": "rqR9PIsBQRofe4CScErR", @@ -109,7 +111,7 @@ Response: } ``` -4. Register model to model group & deploy model: +## 4. Register model to model group & deploy model: ```json POST /_plugins/_ml/models/_register @@ -122,7 +124,7 @@ POST /_plugins/_ml/models/_register } ``` -Response: +Sample response: ```json { "task_id": "r6R9PIsBQRofe4CSlUoG", @@ -138,7 +140,7 @@ Deploy model, in this demo the model id is `sKR9PIsBQRofe4CSlUov` POST /_plugins/_ml/models/sKR9PIsBQRofe4CSlUov/_deploy ``` -5. Test model inference +## 5. Test model inference ```json POST /_plugins/_ml/models/sKR9PIsBQRofe4CSlUov/_predict @@ -149,7 +151,7 @@ POST /_plugins/_ml/models/sKR9PIsBQRofe4CSlUov/_predict } ``` -Response: +Sample response: ```json { "inference_results": [ diff --git a/docs/remote_inference_blueprints/openai_connector_embedding_blueprint.md b/docs/remote_inference_blueprints/openai_connector_embedding_blueprint.md new file mode 100644 index 0000000000..0c61198210 --- /dev/null +++ b/docs/remote_inference_blueprints/openai_connector_embedding_blueprint.md @@ -0,0 +1,161 @@ +# OpenAI connector blueprint example for embedding model + +## 1. Create connector for OpenAI embedding model: + +Refer to OpenAI [official doc](https://platform.openai.com/docs/guides/embeddings). + +If you are using self-managed Opensearch, you should supply OpenAI API key: + +```json +POST /_plugins/_ml/connectors/_create +{ + "name": "", + "description": "", + "version": "", + "protocol": "http", + "parameters": { + "model": "text-embedding-ada-002" + }, + "credential": { + "openAI_key": "" + }, + "actions": [ + { + "action_type": "predict", + "method": "POST", + "url": "https://api.openai.com/v1/embeddings", + "headers": { + "Authorization": "Bearer ${credential.openAI_key}" + }, + "request_body": "{ \"input\": ${parameters.input}, \"model\": \"${parameters.model}\" }", + "pre_process_function": "connector.pre_process.openai.embedding", + "post_process_function": "connector.post_process.openai.embedding" + } + ] +} +``` + +If using the AWS Opensearch Service, you can provide Secret ARN and IAM role arn that allows access to the Secret ARN. +Refer to this [AWS doc](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/ml-external-connector.html) + +```json +POST /_plugins/_ml/connectors/_create +{ + "name": "", + "description": "", + "version": "", + "protocol": "http", + "parameters": { + "model": "text-embedding-ada-002" + }, + "credential": { + "secretArn": "", + "roleArn": "" + }, + "actions": [ + { + "action_type": "predict", + "method": "POST", + "url": "https://api.openai.com/v1/embeddings", + "headers": { + "Authorization": "Bearer ${credential.secretArn.}" + }, + "request_body": "{ \"input\": ${parameters.input}, \"model\": \"${parameters.model}\" }", + "pre_process_function": "connector.pre_process.openai.embedding", + "post_process_function": "connector.post_process.openai.embedding" + } + ] +} +``` + +Sample response: +```json +{ + "connector_id": "OyB0josB2yd36FqHy3lO" +} +``` + +## 2. 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": "TWR0josByE8GuSOJ629m", + "status": "CREATED" +} +``` + +## 3. Register model to model group & deploy model: + +```json +POST /_plugins/_ml/models/_register +{ + "name": "OpenAI embedding model", + "function_name": "remote", + "model_group_id": "TWR0josByE8GuSOJ629m", + "description": "test model", + "connector_id": "OyB0josB2yd36FqHy3lO" +} +``` + +Sample response: +```json +{ + "task_id": "PCB1josB2yd36FqHAXk9", + "status": "CREATED" +} +``` +Get model id from task +```json +GET /_plugins/_ml/tasks/PCB1josB2yd36FqHAXk9 +``` +Deploy model, in this demo the model id is `PSB1josB2yd36FqHAnl1` +```json +POST /_plugins/_ml/models/PSB1josB2yd36FqHAnl1/_deploy +``` + +## 4. Test model inference + +```json +POST /_plugins/_ml/models/PSB1josB2yd36FqHAnl1/_predict +{ + "parameters": { + "input": [ "What is the meaning of life?" ] + } +} +``` + +Response: +```json +{ + "inference_results": [ + { + "output": [ + { + "name": "sentence_embedding", + "data_type": "FLOAT32", + "shape": [ + 1536 + ], + "data": [ + -0.0043460787, + -0.029653417, + -0.008173223, + ... + ] + } + ], + "status_code": 200 + } + ] +} +``` +