Skip to content

Commit f57fadd

Browse files
committed
changes
1 parent 15c5095 commit f57fadd

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

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

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The [LangChain](https://python.langchain.com) Python library is a framework for
2121

2222
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.
2323

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 flows that use Python nodes containing your custom LangChain code.
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 flows with Python nodes that contain your custom LangChain code.
2525

2626
## Prerequisites
2727

@@ -63,17 +63,11 @@ To create a flow, select **Create** on the **Prompt flow** page in Azure Machine
6363

6464
All your LangChain code can directly run in Python nodes in your flow, as long as your compute session contains the `langchain` package dependency.
6565

66-
There are two ways to convert your LangChain code into a flow:
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.
6767

68-
- For a simple conversion process, you can initialize and invoke the LLM model within a Python node by using the integrated LangChain LLM library.
69-
- For better experiment management, you can convert the LLM model to use Azure Machine Learning Python LLM tools in the flow.
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. You can choose the optimal prompt based on evaluation results.
7069

71-
The type of flow to implement depends on your use case.
72-
73-
| Flow type | Implementation | Use case |
74-
|-------| -------- | -------- | -------- |
75-
| A flow that includes both prompt nodes and Python nodes | Extract your prompt template into a prompt node, and combine the remaining code in single or multiple Python nodes or tools. | Easy prompt tuning by running flow variants, to choose the optimal prompt based on evaluation results.|
76-
| A flow that includes Python nodes only| Create a new flow with Python nodes only. All code runs in Python nodes, including prompt definitions. | Faster batch testing based on larger scale datasets. |
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.
7771

7872
The following example shows a flow that uses both prompt nodes and Python nodes:
7973

@@ -90,23 +84,20 @@ After you structure your flow and move your code to specific tool nodes, you nee
9084
1. In your Python code, import the custom connection library by entering `from promptflow.connections import CustomConnection`.
9185

9286
>[!NOTE]
93-
>For an Azure OpenAI connection, use `from promptflow.connections import AzureOpenAIConnection`.
87+
>To import an Azure OpenAI connection, use `from promptflow.connections import AzureOpenAIConnection`.
9488
9589
1. In your tool function, define an input parameter of the type `CustomConnection`.
9690

91+
1. Replace the environment variables that originally defined the key and credential with the corresponding key added in the connection.
92+
9793
:::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":::
9894

99-
1. Parse the input to the input section, and then select your custom connection in the value dropdown.
95+
1. Parse the input to the input section of the node UI, and then select your custom connection in the **Value** dropdown.
10096

10197
:::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":::
10298

103-
1. In your code, replace the environment variables that originally defined the key and credential with the corresponding key added in the connection.
10499
1. Save, return to the authoring page, and also configure the connection parameter in the node input.
105100

106-
If you have a LangChain code that consumes an AzureOpenAI model, import the library by entering `from promptflow.connections import AzureOpenAIConnection`. Replace the environment variables with the corresponding keys from the Azure OpenAI connection.
107-
108-
:::image type="content" source="./media/how-to-integrate-with-langchain/code-consume-aoai.png" alt-text="Screenshot of LangChain code in prompt flow. " lightbox = "./media/how-to-integrate-with-langchain/code-consume-aoai.png":::
109-
110101
### Configure input and output
111102

112103
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

Comments
 (0)