You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/machine-learning/prompt-flow/how-to-integrate-with-langchain.md
+14-14Lines changed: 14 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,20 +17,20 @@ ms.date: 10/22/2024
17
17
18
18
# Integrate LangChain in prompt flows
19
19
20
-
The [LangChain](https://python.langchain.com) Python library is a framework for developing applications powered by large language models (LLMs), agents, and dependency tools. You can use LangChain in Azure Machine Learning prompt flows. This article shows you how to supercharge your LangChain development with prompt flow.
20
+
The [LangChain](https://python.langchain.com) Python library is a framework for developing applications powered by large language models (LLMs), agents, and dependency tools. This article shows you how to supercharge your LangChain development with Azure Machine Learning prompt flow.
21
21
22
-
The integration of LangChain with prompt flow is a powerful combination that can help you build and test your custom language models with ease. You can use LangChain modules to initially build the flow, and then use the prompt flow process to scale experiments for bulk testing, evaluation, and eventual deployment. For example, you can conduct large scale experiments based on larger datasets.
22
+
The integration of LangChain with prompt flow is a powerful combination that can help you build and test your custom language models with ease. You can use LangChain modules to build the flow, then use the prompt flow process to scale experiments for bulk testing, evaluation, and eventual deployment. For example, you can conduct large scale experiments based on larger datasets.
23
23
24
-
If you already have a local prompt flow based on LangChain code, you can use streamlined prompt flow integration to easily convert it into an Azure Machine Learning prompt flow for further experimentation. Or, if you prefer to use LangChain SDK classes and functions directly, you can easily build Azure Machine Learning flows with Python nodes that contain your custom LangChain code.
24
+
If you already have a local prompt flow based on LangChain code, you can easily convert it into an Azure Machine Learning prompt flow for further experimentation. Or if you prefer to use LangChain SDK classes and functions directly, you can easily build Azure Machine Learning flows with Python nodes that use your custom LangChain code.
25
25
26
26
## Prerequisites
27
27
28
28
- A local LangChain flow that's properly tested and ready for deployment.
29
29
- A compute session that can run the Machine Learning prompt flow by adding packages listed in the *requirements.txt* file, including `langchain`. For more information, see [Manage prompt flow compute session](how-to-manage-compute-session.md).
30
30
31
-
## Convert LangChain code into prompt flows
31
+
## Convert LangChain code into a prompt flow
32
32
33
-
The rest of the article describes how to convert your local LangChain code to a runnable Azure Machine Learning prompt flow.
33
+
Use the following process to convert your local LangChain code to a runnable Azure Machine Learning prompt flow.
34
34
35
35
### Convert credentials to a prompt flow connection
When you run an Azure Machine Learning prompt flow in the cloud, it's better not to expose credentials as environment variables. To securely store and manage credentials separately from your code, you should convert the environmental variables into a prompt flow connection.
42
42
43
-
To create a connection that securely stores credentials such as your LLM API key or other required keys, follow these instructions:
43
+
To create a connection that securely stores custom credentials such as your LLM API key or other required keys, follow these instructions:
44
44
45
45
1. On the **Prompt flow** page in your Azure Machine Learning workspace, select the **Connections** tab, and then select **Create**.
46
46
1. Select a connection type from the dropdown list. For this example, select **Custom**.
@@ -51,23 +51,23 @@ To create a connection that securely stores credentials such as your LLM API key
51
51
52
52
:::image type="content" source="./media/how-to-integrate-with-langchain/custom-connection-2.png" alt-text="Screenshot of adding custom connection key-value pairs.":::
53
53
54
-
1. To store an encrypted value for a key, select the **is secret** checkbox next to one or more key-value pairs. At least one value must be set as secret for custom connection creation to succeed.
54
+
1. To store an encrypted value for a key, select the **is secret** checkbox next to one or more key-value pairs. You must set at least one value as secret to successfully create a custom connection.
55
55
56
56
1. Select **Save**.
57
57
58
-
The custom connection can replace the keys and credentials or corresponding environmental variables explicitly defined in your LangChain code. To use the custom connection in the flow, see [Configure connection](#configure-connection).
58
+
The custom connection can replace keys and credentials or corresponding environmental variables explicitly defined in your LangChain code. To use the custom connection in the flow, see [Configure connection](#configure-connection).
59
59
60
60
### Convert LangChain code to a runnable flow
61
61
62
-
To create a flow, select **Create** on the **Prompt flow** page in Azure Machine Learning studio, and choose a flow type. On the flow authoring page, start your compute session before you author the flow. Select tool types at the top of the pane to insert corresponding nodes into the flow. For detailed flow authoring instructions, see [Develop prompt flow](how-to-develop-a-standard-flow.md).
62
+
To create a flow, select **Create** on the **Prompt flow** page in Azure Machine Learning studio, and choose a flow type. On the flow authoring page, start your compute session before you author the flow. Select tool types at the top of the page to insert corresponding nodes into the flow. For detailed flow authoring instructions, see [Develop prompt flow](how-to-develop-a-standard-flow.md).
63
63
64
64
All your LangChain code can directly run in Python nodes in your flow, as long as your compute session contains the `langchain` package dependency.
65
65
66
66
There are two ways to convert your LangChain code into an Azure Machine Learning prompt flow. The type of flow to implement depends on your use case.
67
67
68
-
- For better experiment management, you can convert your code to use Azure Machine Learning Python, LLM, and prompt tools in the flow. You extract the prompt template from your code into a prompt node, and put the remaining code in single or multiple Python nodes or tools. This option allows easy prompt tuning by running flow variants, and lets you choose the optimal prompt based on evaluation results.
68
+
- For better experiment management, you can convert your code to use Azure Machine Learning Python, LLM, and prompt tools in the flow. You extract the prompt template from your code into a prompt node, and put the remaining code in single or multiple Python nodes or tools. This option lets you easily tune prompts by running variants and choose optimal prompts based on evaluation results.
69
69
70
-
- For a simpler conversion process, you can call the LangChain LLM library directly from within your Python nodes. All your code runs in Python nodes, including prompt definitions. This option permits faster batch testing based on larger scale datasets.
70
+
- For a simpler conversion process, you can call the LangChain LLM library directly from within Python nodes. All your code runs in Python nodes, including prompt definitions. This option supports faster batch testing based on larger datasets or other configurations.
71
71
72
72
The following example shows a flow that uses both prompt nodes and Python nodes:
73
73
@@ -90,15 +90,15 @@ After you structure your flow and move your code to specific tool nodes, you nee
90
90
91
91
:::image type="content" source="./media/how-to-integrate-with-langchain/custom-connection-python-node-1.png" alt-text="Screenshot of doc search chain node highlighting the custom connection. " lightbox = "./media/how-to-integrate-with-langchain/custom-connection-python-node-1.png":::
92
92
93
-
1. Replace the environment variables that originally defined the key and credential with the corresponding key added in the connection.
93
+
1. Replace the environment variables that originally defined the key or credential with the corresponding key added in the connection.
94
94
95
95
1. Parse the input to the input section of the node UI, and then select your custom connection in the **Value** dropdown.
96
96
97
97
:::image type="content" source="./media/how-to-integrate-with-langchain/custom-connection-python-node-2.png" alt-text="Screenshot of the chain node highlighting the connection. " lightbox = "./media/how-to-integrate-with-langchain/custom-connection-python-node-2.png":::
98
98
99
-
1.Save, return to the authoring page, and also configure the connection parameter in the node input.
99
+
1.Be sure to also configure the connection parameters in any other nodes that require it, such as LLM nodes.
100
100
101
-
### Configure input and output
101
+
### Configure inputs and outputs
102
102
103
103
Before you run the flow, configure the node inputs and outputs and the overall flow inputs and outputs. This step is crucial to ensure that all the required data passes properly through the flow and produces desired results. For more information, see [Flow inputs and outputs](how-to-develop-flow.md#flow-input-and-output).
0 commit comments