Skip to content

Commit

Permalink
add bedrock/sagemaker region
Browse files Browse the repository at this point in the history
Signed-off-by: Yaliang Wu <[email protected]>
  • Loading branch information
ylwu-amzn committed Mar 12, 2024
1 parent cfc822d commit 4bb2a50
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions docs/tutorials/aws/AIConnectorHelper.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -586,20 +586,21 @@
"connector_role_name = 'my_test_bedrock_connector_role'\n",
"create_connector_role_name = 'my_test_create_bedrock_connector_role'\n",
"\n",
"bedrock_region = 'us-west-2' # bedrock region could be different with OpenSearch domain region\n",
"create_connector_input = {\n",
" \"name\": \"Amazon Bedrock Connector: titan embedding v1\",\n",
" \"description\": \"The connector to bedrock Titan embedding model\",\n",
" \"version\": 1,\n",
" \"protocol\": \"aws_sigv4\",\n",
" \"parameters\": {\n",
" \"region\": region,\n",
" \"region\": bedrock_region,\n",
" \"service_name\": \"bedrock\"\n",
" },\n",
" \"actions\": [\n",
" {\n",
" \"action_type\": \"predict\",\n",
" \"method\": \"POST\",\n",
" \"url\": f\"https://bedrock-runtime.{region}.amazonaws.com/model/amazon.titan-embed-text-v1/invoke\",\n",
" \"url\": f\"https://bedrock-runtime.{bedrock_region}.amazonaws.com/model/amazon.titan-embed-text-v1/invoke\",\n",
" \"headers\": {\n",
" \"content-type\": \"application/json\",\n",
" \"x-amz-content-sha256\": \"required\"\n",
Expand Down Expand Up @@ -722,13 +723,14 @@
"create_connector_role_name = 'my_test_create_sagemaker_connector_role'\n",
"sagemaker_inference_endpoint_url = '...' # set your SageMaker inference endpoint URL\n",
"\n",
"sagemaker_endpoint_region = 'us-west-2' # SageMaker endpoint region could be different with OpenSearch domain region\n",
"create_connector_input = {\n",
" \"name\": \"Sagemaker embedding model connector\",\n",
" \"description\": \"Connector for my Sagemaker embedding model\",\n",
" \"version\": \"1.0\",\n",
" \"protocol\": \"aws_sigv4\",\n",
" \"parameters\": {\n",
" \"region\": region,\n",
" \"region\": sagemaker_endpoint_region,\n",
" \"service_name\": \"sagemaker\"\n",
" },\n",
" \"actions\": [\n",
Expand Down Expand Up @@ -839,7 +841,9 @@
],
"source": [
"secret_name = 'my_test_cohere_secret'\n",
"secret_value = {\"my_cohere_key\": \"...\"} # set your Cohere API key\n",
"secret_key = 'my_cohere_key'\n",
"secret_value = '...' # set your Cohere API key\n",
"secret_value = { secret_key: secret_value }\n",
"# You can use existing role if the role permission and trust relationship are correct. \n",
"# To quick start, you can specify new role names. AIConnectorHelper will create role automatically.\n",
"connector_role_name = 'my_test_cohere_connector_role'\n",
Expand All @@ -861,7 +865,7 @@
" \"method\": \"POST\",\n",
" \"url\": \"https://api.cohere.ai/v1/embed\",\n",
" \"headers\": {\n",
" \"Authorization\": \"Bearer ${credential.secretArn.my_cohere_key}\",\n",
" \"Authorization\": f\"Bearer ${{credential.secretArn.{secret_key}}}\",\n",
" \"Request-Source\": \"unspecified:opensearch\"\n",
" },\n",
" \"request_body\": \"{ \\\"texts\\\": ${parameters.texts}, \\\"truncate\\\": \\\"${parameters.truncate}\\\", \\\"model\\\": \\\"${parameters.model}\\\", \\\"input_type\\\": \\\"${parameters.input_type}\\\" }\",\n",
Expand Down Expand Up @@ -965,7 +969,9 @@
],
"source": [
"secret_name = 'my_test_openai_secret'\n",
"secret_value = {\"my_openai_key\": \"...\"} # set your OpenAI API key\n",
"secret_key = 'my_openai_key'\n",
"secret_value = '...' # set your OpenAI API key\n",
"secret_value = { secret_key : secret_value }\n",
"# You can use existing role if the role permission and trust relationship are correct. \n",
"# To quick start, you can specify new role names. AIConnectorHelper will create role automatically.\n",
"connector_role_name = 'my_test_openai_connector_role'\n",
Expand All @@ -985,7 +991,7 @@
" \"method\": \"POST\",\n",
" \"url\": \"https://api.openai.com/v1/embeddings\",\n",
" \"headers\": {\n",
" \"Authorization\": \"Bearer ${credential.secretArn.my_openai_key}\"\n",
" \"Authorization\": f\"Bearer ${{credential.secretArn.{secret_key}}}\",\n",
" },\n",
" \"request_body\": \"{ \\\"input\\\": ${parameters.input}, \\\"model\\\": \\\"${parameters.model}\\\" }\",\n",
" \"pre_process_function\": \"connector.pre_process.openai.embedding\",\n",
Expand Down

0 comments on commit 4bb2a50

Please sign in to comment.