시작하기무료로 시작하기

Few-shot 프롬프트 구현하기

이제 구성 요소를 체인으로 결합해 볼 차례예요! 이전 연습 문제에서 만든 few-shot 프롬프트와 examples, example_prompt를 계속 사용할 수 있어요.

이 연습 문제를 완료하는 데 필요한 LangChain 클래스는 모두 미리 로드되어 있습니다.

이 연습은 강의의 일부입니다

LangChain으로 LLM 애플리케이션 개발하기

강의 보기

연습 안내

  • ChatOpenAI 클래스를 사용해 OpenAI 채팅 LLM을 인스턴스화하세요.
  • | 연산자를 사용해 프롬프트 템플릿과 LLM으로 체인을 만든 뒤, .invoke() 메서드로 실행하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

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?"}))
코드 편집 및 실행