728x90
Messages Placeholder
- Messages Placeholder를 통해서 이미 존재하는 메시지를 전달할 수 있다.
- 특정 key를 통해서 맵핑 시킨다.
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
prompt = ChatPromptTemplate.from_messages(
[
("system", "You are a helpful assistant."),
MessagesPlaceholder("history"),
("human", "{question}")
]
)
prompt.invoke(
{
"history": [("human", "what's 5 + 2"), ("ai", "5 + 2 is 7")],
"question": "now multiply that by 4"
}
)
위 경우 invoke
시에 "history"라는 key에 메시지의 리스트가 value로 들어가있는 걸 확인할 수 있다.
prompt Template을 찍어보면 그 값은 아래와 같다
ChatPromptValue(messages=[
SystemMessage(content="You are a helpful assistant."),
HumanMessage(content="what's 5 + 2"),
AIMessage(content="5 + 2 is 7"),
HumanMessage(content="now multiply that by 4"),
])
Reference
'인공지능 > RAG' 카테고리의 다른 글
Langchain - Hybrid Search 구현 (0) | 2024.05.31 |
---|---|
MongoDB와 Gemma를 사용한 RAG 실습(LangChain X) (0) | 2024.05.28 |
Langchain - ChatPromptTemplate (0) | 2024.05.23 |
LangChain (9) Retrieval - Retriever (0) | 2024.04.08 |
LangChain (8) Retrieval - Vectorstores (0) | 2024.04.08 |