Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Developing LLM Applications with LangChain

Cursus bekijken

Oefeninstructies

  • Convert the template text provided into a standard (non-chat) prompt template.
  • Create a chain to pass the prompt template into the LLM.
  • Invoke the chain on the question variable provided.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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": ____}))
Code bewerken en uitvoeren