Skip to content

Commit 87a643f

Browse files
committed
final touchups
1 parent 3018bb8 commit 87a643f

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

articles/machine-learning/prompt-flow/how-to-integrate-with-langchain.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ms.topic: how-to
1212
author: lgayhardt
1313
ms.author: lagayhar
1414
ms.reviewer: chenlujiao
15-
ms.date: 10/22/2024
15+
ms.date: 10/23/2024
1616
---
1717

1818
# Integrate LangChain in prompt flows
@@ -36,9 +36,14 @@ Use the following process to convert your local LangChain code to a runnable Azu
3636

3737
### Convert credentials to a prompt flow connection
3838

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.
4040

41-
:::image type="content" source="./media/how-to-integrate-with-langchain/langchain-env-variables.png" alt-text="Screenshot of Azure OpenAI example in LangChain.":::
41+
```python
42+
os.environ["OPENAI_API_TYPE"] = "azure"
43+
os.environ["OPENAI_API_VERSION"] = "2023-05-15"
44+
os.environ["OPENAI_API_BASE"] = "https://contosobamiopenai.openai.azure.com/"
45+
os.environ["OPENAI_API_KEY"] = "abc123abc123abc123abc123abc123ab"
46+
```
4247

4348
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.
4449

@@ -67,17 +72,17 @@ All your LangChain code can directly run in Python nodes in your flow, as long a
6772

6873
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.
6974

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 Python 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 helps you easily tune prompts by running variants and lets you choose optimal prompts based on evaluation results.
7176

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:
7378

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":::
7580

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.
7782

78-
The following example shows a flow that uses Python nodes only:
83+
The following example shows a flow that uses Python nodes only:
7984

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":::
8186

8287
### Configure connection
8388

@@ -92,13 +97,13 @@ After you structure your flow and move your code to specific tool nodes, you nee
9297

9398
:::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":::
9499

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.
96101

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.
98103

99104
:::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":::
100105

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.
102107

103108
### Configure inputs and outputs
104109

-24.8 KB
Loading

0 commit comments

Comments
 (0)