Prompt templates and chaining
In this exercise, you'll begin using two of the core components in LangChain: prompt templates and chains!
The classes necessary for completing this exercise, including ChatOpenAI, have been pre-loaded for you.
Bu egzersiz
Developing LLM Applications with LangChain
kursunun bir parçasıdırEgzersiz talimatları
- Convert the
templatetext provided into a standard (non-chat) prompt template. - Create a chain to pass the prompt template into the LLM.
- Invoke the chain on the
questionvariable provided.
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
# Create a prompt template from the template string
template = "You are an artificial intelligence assistant, answer the question. {question}"
prompt = PromptTemplate.____(
template=____
)
llm = ChatOpenAI(model="gpt-4o-mini", api_key='')
# Create a chain to integrate the prompt template and LLM
llm_chain = ____ | ____
# Invoke the chain on the question
question = "How does LangChain make LLM application development easier?"
print(llm_chain.invoke({"question": ____}))