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
+17-12Lines changed: 17 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ ms.topic: how-to
12
12
author: lgayhardt
13
13
ms.author: lagayhar
14
14
ms.reviewer: chenlujiao
15
-
ms.date: 10/22/2024
15
+
ms.date: 10/23/2024
16
16
---
17
17
18
18
# Integrate LangChain in prompt flows
@@ -36,9 +36,14 @@ Use the following process to convert your local LangChain code to a runnable Azu
36
36
37
37
### Convert credentials to a prompt flow connection
38
38
39
-
Your LangChain code might [define environment variables](https://python.langchain.com/docs/integrations/platforms/microsoft) to store credentials, such as the AzureOpenAI API key necessary for invoking AzureOpenAI models. For example, the following image shows environmental variables being set for OpenAI API type, key, base, and version.
39
+
Your LangChain code might [define environment variables](https://python.langchain.com/docs/integrations/platforms/microsoft) to store credentials, such as the AzureOpenAI API key necessary for invoking AzureOpenAI models. For example, the following code shows environmental variables being set for OpenAI API type, key, base, and version.
40
40
41
-
:::image type="content" source="./media/how-to-integrate-with-langchain/langchain-env-variables.png" alt-text="Screenshot of Azure OpenAI example in LangChain.":::
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.
44
49
@@ -67,17 +72,17 @@ All your LangChain code can directly run in Python nodes in your flow, as long a
67
72
68
73
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.
69
74
70
-
- 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.
75
+
- For better experiment management, you can convert your code to use Azure Machine Learning Pythonand 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 helps you easily tune prompts by running variants and lets you choose optimal prompts based on evaluation results.
71
76
72
-
- 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.
77
+
The following example shows a flow that uses both prompt nodes and Python nodes:
73
78
74
-
The following example shows a flow that uses both prompt nodes and Python nodes:
79
+
:::image type="content" source="./media/how-to-integrate-with-langchain/flow-node-a-1.png" alt-text="Screenshot of flows highlighting the prompt button and system template. " lightbox = "./media/how-to-integrate-with-langchain/flow-node-a-1.png":::
75
80
76
-
:::image type="content" source="./media/how-to-integrate-with-langchain/flow-node-a-1.png" alt-text="Screenshot of flows highlighting the prompt button and system template. " lightbox = "./media/how-to-integrate-with-langchain/flow-node-a-1.png":::
81
+
- 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.
77
82
78
-
The following example shows a flow that uses Python nodes only:
83
+
The following example shows a flow that uses Python nodes only:
79
84
80
-
:::image type="content" source="./media/how-to-integrate-with-langchain/flow-node-b.png" alt-text="Screenshot of flows showing the LangChain code node and graph. " lightbox = "./media/how-to-integrate-with-langchain/flow-node-b.png":::
85
+
:::image type="content" source="./media/how-to-integrate-with-langchain/flow-node-b.png" alt-text="Screenshot of flows showing the LangChain code node and graph. " lightbox = "./media/how-to-integrate-with-langchain/flow-node-b.png":::
81
86
82
87
### Configure connection
83
88
@@ -92,13 +97,13 @@ After you structure your flow and move your code to specific tool nodes, you nee
92
97
93
98
:::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":::
94
99
95
-
1. Replace the environment variables that originally defined the key or credential with the corresponding key added in the connection.
100
+
1. Replace the environment variables that originally defined the key or credential with the corresponding key from the connection.
96
101
97
-
1. Parse the input to the input section of the node UI, and then select your custom connection in the **Value** dropdown.
102
+
1. Parse the input to the input section of the node UI, and then select your custom connection from the **Value** dropdown list in the UI.
98
103
99
104
:::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":::
100
105
101
-
1. Be sure to also configure the connection parameters in any other nodes that require it, such as LLM nodes.
106
+
1. Be sure to also configure the connection parameters in any other nodes that require them, such as LLM nodes.
0 commit comments