summ의 블로그

[Langchain] fewshot prompting 본문

langchain

[Langchain] fewshot prompting

summ._ 2024. 7. 15. 22:51
프롬프트 

 

프롬프트?

사용자의 대화 주제나 방향을 설정하는 데 도움이 되거나

시나리오에서 모델이 어떻게 반응하는지 평가하고 개선하는 데 사용이 됨.

 

구성 요소로 

지시, 질문, 문맥, 입력, 예제, 답변 등이 들어감

 

주어진 context만 이용하여 대답하도록 설정함. 

prompt = """ Answer the ~~~. 
             Context: ~~~. 
             Question: ~~~. 
             Answer: 
         """

 

1) langchain에 PromptTemplate 사용 

 

from langchain import PromptTemplate

 

위에 만든 prompt를 이용하여 사용  

prompt_template = PromptTemplate(
    input_variables = ["question"],
    template = template
)

 

2) ChatPromptTemplate 사용 

대화목록을 프롬프트에 넣을 때 사용한다. 

from langchain_core.prompts import ChatPromptTemplate

chat_prompt_template = ChatPromptTemplate.from_template("{country}의 수도는 어디인가요?")
chat_prompt_template

 

 

in-context learning 

주어진 상황, 프롬프트에 예시를 넣어 학습을 함. 

 

zero shot 예제 없음 

one shot 예제 1개 

few shot 예제 여러개 

 

 

'langchain' 카테고리의 다른 글

[Langchain] AI agent  (0) 2024.09.04
[Langchain] Retrieval Agents  (0) 2024.08.21
[Langchain] chain  (0) 2024.07.15
[Langchain] langchain  (0) 2024.07.11
[Langchain] OpenAI api key 발급받기  (0) 2024.07.08