Get startedGet started for free

Implementing few-shot prompting

Time to combine your components together into a chain! The few-shot prompt you created in the previous exercise is still available for you to use, along with examples and example_prompt.

All of the LangChain classes necessary for completing this exercise have been pre-loaded for you.

This exercise is part of the course

Developing LLM Applications with LangChain

View Course

Exercise instructions

  • Instantiate an OpenAI chat LLM.
  • Create a chain from the LLM and prompt template, and invoke it on the input provided.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

prompt_template = FewShotPromptTemplate(
    examples=examples,
    example_prompt=example_prompt,
    suffix="Question: {input}",
    input_variables=["input"],
)

# Create an OpenAI chat LLM
llm = ____(model="gpt-4o-mini", api_key='')

# Create and invoke the chain
llm_chain = ____
print(____({"input": "What is Jack's favorite technology on DataCamp?"}))
Edit and Run Code