02. FewShotPromptTemplate

from dotenv import load_dotenv

load_dotenv()

Copy

True 

Copy

# 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")

Copy

Start tracking LangSmith. 
[Project name] 
CH02-Prompt

FewShotPromptTemplate

Copy

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)

Copy

Copy

Copy

Copy

Copy

Copy

Copy

Copy

Copy

Copy

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.

Copy

Copy

Copy

Copy

This time, use ExampleSelector to generate FewShotPromptTemplate.

Copy

Copy

Copy

FewShotChatMessagePromptTemplate

Copy

Copy

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

Copy

Copy

Copy

Copy

Copy

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.

Copy

Copy

Copy

Copy

Copy

Copy

Copy

Copy

Copy

Copy

Copy

Copy

Copy

Copy

Last updated