02. FewShotPromptTemplate

from dotenv import load_dotenv

load_dotenv()
True 
# LangSmith Set up tracking. https://smith.langchain.com
# !pip install -qU langchain-teddynote
from langchain_teddynote import logging

# Enter a project name.
logging.langsmith("CH02-Prompt")
Start tracking LangSmith. 
[Project name] 
CH02-Prompt

FewShotPromptTemplate

from langchain_openai import ChatOpenAI
from langchain_teddynote.messages import stream_response

# Object creation
llm = ChatOpenAI(
    temperature=0,  # creativity
    model_name="gpt-4-turbo",  # model name
)

# Inquiry content
question = "What is the capital of South Korea?"

# 질의
answer = llm.stream(question)
stream_response(answer)

Example Selector

If there are many examples, you may need to choose an example to include at the prompt. Example Selector is the class responsible for this task.

This time, use ExampleSelector to generate FewShotPromptTemplate.

FewShotChatMessagePromptTemplate

Select 1 similar example using the faceshot example and the example selector.

Solving similarity search problems for Example Selector

When calculating similarity instruction and input I am using. But, instruction Proper similarity results are not obtained when searching using only.

To solve this, we define the class above the calculation of custom similarity. Below is an example of the wrongly searched results.

Last updated