05. LangChain Expression Language (LCEL)
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 langchain_teddynote.messages import stream_response # Streaming Output
from langchain_core.prompts import PromptTemplatefrom_template() Create PromptTemplate objects using methods
# template definition
template = "{country}What is the capital of?"
# from_template Using the method PromptTemplate Object creation
prompt_template = PromptTemplate.from_template(template)
prompt_template PromptTemplate (input_variables=['country'], template='{country}) 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