|
21 | 21 | "source": [
|
22 | 22 | "# AzureOpenAIEmbeddings\n",
|
23 | 23 | "\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", |
29 | 24 | "[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",
|
30 | 25 | "\n",
|
31 | 26 | "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",
|
32 | 27 | "\n",
|
33 | 28 | "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",
|
34 | 29 | "\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", |
35 | 33 | "```{=mdx}\n",
|
36 | 34 | "\n",
|
37 | 35 | ":::info\n",
|
|
44 | 42 | "\n",
|
45 | 43 | "```\n",
|
46 | 44 | "\n",
|
| 45 | + "## Overview\n", |
| 46 | + "### Integration details\n", |
47 | 47 | "\n",
|
48 | 48 | "| Class | Package | Local | [Py support](https://python.langchain.com/docs/integrations/text_embedding/azureopenai/) | Package downloads | Package latest |\n",
|
49 | 49 | "| :--- | :--- | :---: | :---: | :---: | :---: |\n",
|
50 | 50 | "| [AzureOpenAIEmbeddings](https://api.js.langchain.com/classes/langchain_openai.AzureOpenAIEmbeddings.html) | [@langchain/openai](https://api.js.langchain.com/modules/langchain_openai.html) | ❌ | ✅ |  |  |\n",
|
51 | 51 | "\n",
|
52 | 52 | "## Setup\n",
|
53 | 53 | "\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", |
55 | 55 | "\n",
|
56 | 56 | "### Credentials\n",
|
57 | 57 | "\n",
|
|
111 | 111 | "source": [
|
112 | 112 | "## Instantiation\n",
|
113 | 113 | "\n",
|
114 |
| - "Now we can instantiate our model object and generate chat completions:" |
| 114 | + "Now we can instantiate our model object and embed text:" |
115 | 115 | ]
|
116 | 116 | },
|
117 | 117 | {
|
|
368 | 368 | "source": [
|
369 | 369 | "import { AzureOpenAIEmbeddings } from \"@langchain/openai\";\n",
|
370 | 370 | "\n",
|
371 |
| - "const modelDifferentDomain = new AzureOpenAIEmbeddings({\n", |
| 371 | + "const embeddingsDifferentDomain = new AzureOpenAIEmbeddings({\n", |
372 | 372 | " azureOpenAIApiKey: \"<your_key>\", // In Node.js defaults to process.env.AZURE_OPENAI_API_KEY\n",
|
373 | 373 | " azureOpenAIApiEmbeddingsDeploymentName: \"<your_embedding_deployment_name>\", // In Node.js defaults to process.env.AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME\n",
|
374 | 374 | " azureOpenAIApiVersion: \"<api_version>\", // In Node.js defaults to process.env.AZURE_OPENAI_API_VERSION\n",
|
|
377 | 377 | "});\n"
|
378 | 378 | ]
|
379 | 379 | },
|
| 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 | + }, |
380 | 422 | {
|
381 | 423 | "cell_type": "markdown",
|
382 | 424 | "id": "7b2e885a",
|
|
0 commit comments