.from_template 사용 방식:
{question}, {topic} 등)를 나중에 입력 값으로 채워 넣을 수 있습니다..from_messages 사용 방식:
예시 코드:
.from_template 예시:
from langchain.prompts import PromptTemplate
prompt = PromptTemplate.from_template("Human: {question}\nAI:")
result = prompt.format(question="What is the capital of Germany?")
# result는 "Human: What is the capital of Germany?\nAI:"와 같은 문자열을 생성합니다.
.from_messages 예시:
from langchain.prompts.chat import ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate
chat_prompt = ChatPromptTemplate.from_messages([
SystemMessagePromptTemplate.from_template("You are a helpful assistant."),
HumanMessagePromptTemplate.from_template("Tell me about {topic}.")
])
result = chat_prompt.format(topic="Germany")
# result는 여러 메시지를 포함하는 채팅 대화 형식의 프롬프트를 생성합니다.
결론: