05. LangChain Expression Language (LCEL)
Basic example: Prompt + Model + Output parser
The most basic and common use example is linking prompt templates and models together. To see how this works, let's create a Chain that asks for each country's capital.
# API KEY A configuration file for managing environment variables
from dotenv import load_dotenv
# API KEY Load information
load_dotenv() True # LangSmith Set up tracking. https://smith.langchain.com
# !pip install -qU langchain-teddynote
from langchain_teddynote import logging
# Enter a project name.
logging.langsmith("CH01-Basic") Start tracking LangSmith.
[Project name]
CH01-Basic Use of prompt templates
PromptTemplate
Template used to create a complete prompt string using the user's input variable
Usage
template: Template string. Braces within this string{}Indicates a variable.input_variables: Defines the name of the variable to be in braces as a list.
input_variables
input_variables is a list that defines the name of a variable used in PromptTemplate.
from_template() Create PromptTemplate objects using methods
Chain creation
LCEL (LangChain Expression Language)

Here we use LCEL to combine various components into a single chain
| The symbol unix pipe operator Similar to, it connects different components and passes the output of one component to the input of the next component.
In this chain, user input is passed to the prompt template, then the prompt template output is passed to the model. If you look at each component individually, you can understand what is going on.
invoke() call
Pass the input in the form of a python dictionary (Key: value)
When invoke() function is called, it passes the input value.
Below is an example of outputting streaming.
Output Parser
Add an output parser to Chain.
Apply by changing the template
Anything below the prompt change You can test it.
model_nameYou can also change it to test it.
Last updated