Skip to content

Commit 6233e4c

Browse files
committed
Update embeddings template, add Azure custom header info
1 parent f6e16ea commit 6233e4c

File tree

4 files changed

+65
-25
lines changed

4 files changed

+65
-25
lines changed

docs/core_docs/docs/integrations/chat/azure.ipynb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,9 @@
363363
"id": "1a6b849d",
364364
"metadata": {},
365365
"source": [
366-
"The `configuration` field also accepts other `ClientOptions` parameters accepted by the official SDK."
366+
"The `configuration` field also accepts other `ClientOptions` parameters accepted by the official SDK.\n",
367+
"\n",
368+
"**Note:** The specific header `api-key` currently cannot be overridden in this manner and will pass through the value from `azureOpenAIApiKey`."
367369
]
368370
},
369371
{

docs/core_docs/docs/integrations/text_embedding/azure_openai.ipynb

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,15 @@
2121
"source": [
2222
"# AzureOpenAIEmbeddings\n",
2323
"\n",
24-
"This will help you get started with AzureOpenAIEmbeddings [embedding models](/docs/concepts#embedding-models) using LangChain. For detailed documentation on `AzureOpenAIEmbeddings` features and configuration options, please refer to the [API reference](https://api.js.langchain.com/classes/langchain_openai.AzureOpenAIEmbeddings.html).\n",
25-
"\n",
26-
"## Overview\n",
27-
"### Integration details\n",
28-
"\n",
2924
"[Azure OpenAI](https://azure.microsoft.com/products/ai-services/openai-service/) is a cloud service to help you quickly develop generative AI experiences with a diverse set of prebuilt and curated models from OpenAI, Meta and beyond.\n",
3025
"\n",
3126
"LangChain.js supports integration with [Azure OpenAI](https://azure.microsoft.com/products/ai-services/openai-service/) using the new Azure integration in the [OpenAI SDK](https://github.com/openai/openai-node).\n",
3227
"\n",
3328
"You can learn more about Azure OpenAI and its difference with the OpenAI API on [this page](https://learn.microsoft.com/azure/ai-services/openai/overview). If you don't have an Azure account, you can [create a free account](https://azure.microsoft.com/free/) to get started.\n",
3429
"\n",
30+
"This will help you get started with AzureOpenAIEmbeddings [embedding models](/docs/concepts#embedding-models) using LangChain. For detailed documentation on `AzureOpenAIEmbeddings` features and configuration options, please refer to the [API reference](https://api.js.langchain.com/classes/langchain_openai.AzureOpenAIEmbeddings.html).\n",
31+
"\n",
32+
"\n",
3533
"```{=mdx}\n",
3634
"\n",
3735
":::info\n",
@@ -44,14 +42,16 @@
4442
"\n",
4543
"```\n",
4644
"\n",
45+
"## Overview\n",
46+
"### Integration details\n",
4747
"\n",
4848
"| Class | Package | Local | [Py support](https://python.langchain.com/docs/integrations/text_embedding/azureopenai/) | Package downloads | Package latest |\n",
4949
"| :--- | :--- | :---: | :---: | :---: | :---: |\n",
5050
"| [AzureOpenAIEmbeddings](https://api.js.langchain.com/classes/langchain_openai.AzureOpenAIEmbeddings.html) | [@langchain/openai](https://api.js.langchain.com/modules/langchain_openai.html) | ❌ | ✅ | ![NPM - Downloads](https://img.shields.io/npm/dm/@langchain/openai?style=flat-square&label=%20&) | ![NPM - Version](https://img.shields.io/npm/v/@langchain/openai?style=flat-square&label=%20&) |\n",
5151
"\n",
5252
"## Setup\n",
5353
"\n",
54-
"To access AzureOpenAIEmbeddings embedding models you'll need to create an Azure account, get an API key, and install the `@langchain/openai` integration package.\n",
54+
"To access Azure OpenAI embedding models you'll need to create an Azure account, get an API key, and install the `@langchain/openai` integration package.\n",
5555
"\n",
5656
"### Credentials\n",
5757
"\n",
@@ -111,7 +111,7 @@
111111
"source": [
112112
"## Instantiation\n",
113113
"\n",
114-
"Now we can instantiate our model object and generate chat completions:"
114+
"Now we can instantiate our model object and embed text:"
115115
]
116116
},
117117
{
@@ -368,7 +368,7 @@
368368
"source": [
369369
"import { AzureOpenAIEmbeddings } from \"@langchain/openai\";\n",
370370
"\n",
371-
"const modelDifferentDomain = new AzureOpenAIEmbeddings({\n",
371+
"const embeddingsDifferentDomain = new AzureOpenAIEmbeddings({\n",
372372
" azureOpenAIApiKey: \"<your_key>\", // In Node.js defaults to process.env.AZURE_OPENAI_API_KEY\n",
373373
" azureOpenAIApiEmbeddingsDeploymentName: \"<your_embedding_deployment_name>\", // In Node.js defaults to process.env.AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME\n",
374374
" azureOpenAIApiVersion: \"<api_version>\", // In Node.js defaults to process.env.AZURE_OPENAI_API_VERSION\n",
@@ -377,6 +377,48 @@
377377
"});\n"
378378
]
379379
},
380+
{
381+
"cell_type": "markdown",
382+
"id": "77960c17",
383+
"metadata": {},
384+
"source": [
385+
"## Custom headers\n",
386+
"\n",
387+
"You can specify custom headers by passing in a `configuration` field:"
388+
]
389+
},
390+
{
391+
"cell_type": "code",
392+
"execution_count": null,
393+
"id": "a7aad2a2",
394+
"metadata": {},
395+
"outputs": [],
396+
"source": [
397+
"import { AzureOpenAIEmbeddings } from \"@langchain/openai\";\n",
398+
"\n",
399+
"const embeddings = new AzureOpenAIEmbeddings({\n",
400+
" azureOpenAIApiKey: \"<your_key>\",\n",
401+
" azureOpenAIApiInstanceName: \"<your_instance_name>\",\n",
402+
" azureOpenAIApiEmbeddingsDeploymentName: \"<your_embeddings_deployment_name>\",\n",
403+
" azureOpenAIApiVersion: \"<api_version>\",\n",
404+
" configuration: {\n",
405+
" defaultHeaders: {\n",
406+
" \"x-custom-header\": `SOME_VALUE`,\n",
407+
" },\n",
408+
" },\n",
409+
"});"
410+
]
411+
},
412+
{
413+
"cell_type": "markdown",
414+
"id": "225e191b",
415+
"metadata": {},
416+
"source": [
417+
"The `configuration` field also accepts other `ClientOptions` parameters accepted by the official SDK.\n",
418+
"\n",
419+
"**Note:** The specific header `api-key` currently cannot be overridden in this manner and will pass through the value from `azureOpenAIApiKey`."
420+
]
421+
},
380422
{
381423
"cell_type": "markdown",
382424
"id": "7b2e885a",

docs/core_docs/docs/integrations/text_embedding/bedrock.ipynb

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"source": [
1212
"---\n",
13-
"sidebar_label: Bedrock\n",
13+
"sidebar_label: Amazon Bedrock\n",
1414
"---"
1515
]
1616
},
@@ -21,30 +21,24 @@
2121
"source": [
2222
"# BedrockEmbeddings\n",
2323
"\n",
24-
"This will help you get started with Bedrock [embedding models](/docs/concepts#embedding-models) using LangChain. For detailed documentation on `Bedrock` features and configuration options, please refer to the [API reference](https://api.js.langchain.com/classes/langchain_aws.BedrockEmbeddings.html).\n",
24+
"[Amazon Bedrock](https://aws.amazon.com/bedrock/) is a fully managed service that offers a choice of high-performing foundation models (FMs) from leading AI companies like AI21 Labs, Anthropic, Cohere, Meta, Stability AI, and Amazon via a single API, along with a broad set of capabilities you need to build generative AI applications with security, privacy, and responsible AI.\n",
25+
"\n",
26+
"This will help you get started with Amazon Bedrock [embedding models](/docs/concepts#embedding-models) using LangChain. For detailed documentation on `Bedrock` features and configuration options, please refer to the [API reference](https://api.js.langchain.com/classes/langchain_aws.BedrockEmbeddings.html).\n",
2527
"\n",
2628
"## Overview\n",
2729
"### Integration details\n",
2830
"\n",
29-
"[Amazon Bedrock](https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-service.html) is a fully managed service that makes base models from Amazon and third-party model providers accessible through an API.\n",
30-
"\n",
3131
"| Class | Package | Local | [Py support](https://python.langchain.com/docs/integrations/text_embedding/bedrock/) | Package downloads | Package latest |\n",
3232
"| :--- | :--- | :---: | :---: | :---: | :---: |\n",
3333
"| [Bedrock](https://api.js.langchain.com/classes/langchain_aws.BedrockEmbeddings.html) | [@langchain/aws](https://api.js.langchain.com/modules/langchain_aws.html) | ❌ | ✅ | ![NPM - Downloads](https://img.shields.io/npm/dm/@langchain/aws?style=flat-square&label=%20&) | ![NPM - Version](https://img.shields.io/npm/v/@langchain/aws?style=flat-square&label=%20&) |\n",
3434
"\n",
3535
"## Setup\n",
3636
"\n",
37-
"To access Bedrock embedding models you'll need to create a/an Bedrock account, get an API key, and install the `@langchain/aws` integration package.\n",
38-
"\n",
39-
"### Credentials\n",
37+
"To access Bedrock embedding models you'll need to create an AWS account, get an API key, and install the `@langchain/aws` integration package.\n",
4038
"\n",
41-
"Head to [aws.amazon.com](https://aws.amazon.com) to sign up to `Bedrock` and generate your credentials. Once you've done this set the environment variables:\n",
39+
"Head to the [AWS docs](https://docs.aws.amazon.com/bedrock/latest/userguide/getting-started.html) to sign up for AWS and setup your credentials. You'll also need to turn on model access for your account, which you can do by [following these instructions](https://docs.aws.amazon.com/bedrock/latest/userguide/model-access.html).\n",
4240
"\n",
43-
"```bash\n",
44-
"export BEDROCK_AWS_REGION=\n",
45-
"export BEDROCK_AWS_ACCESS_KEY_ID=\n",
46-
"export BEDROCK_AWS_SECRET_ACCESS_KEY=\n",
47-
"```\n",
41+
"### Credentials\n",
4842
"\n",
4943
"If you want to get automated tracing of your model calls you can also set your [LangSmith](https://docs.smith.langchain.com/) API key by uncommenting below:\n",
5044
"\n",
@@ -76,7 +70,9 @@
7670
"source": [
7771
"## Instantiation\n",
7872
"\n",
79-
"Now we can instantiate our model object and generate chat completions:"
73+
"Now we can instantiate our model object and embed text.\n",
74+
"\n",
75+
"There are a few different ways to authenticate with AWS - the below examples rely on an access key, secret access key and region set in your environment variables:"
8076
]
8177
},
8278
{
@@ -94,7 +90,7 @@
9490
" accessKeyId: process.env.BEDROCK_AWS_ACCESS_KEY_ID!,\n",
9591
" secretAccessKey: process.env.BEDROCK_AWS_SECRET_ACCESS_KEY!,\n",
9692
" },\n",
97-
" model: \"amazon.titan-embed-text-v1\", // Default value\n",
93+
" model: \"amazon.titan-embed-text-v1\",\n",
9894
"});"
9995
]
10096
},

libs/langchain-scripts/src/cli/docs/templates/text_embedding.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"source": [
8383
"## Instantiation\n",
8484
"\n",
85-
"Now we can instantiate our model object and generate chat completions:\n",
85+
"Now we can instantiate our model object and embed text:\n",
8686
"\n",
8787
"- TODO: Update model instantiation with relevant params."
8888
]

0 commit comments

Comments
 (0)