작성
·
9
0
안녕하세요.
강의에서 정의하신 아래의 함수에서 final_answer에 입력값을 넣는것이 결국 리스트 형태의 데이터고, 리스트는 HumanMessage와 AIMessage가 번갈아가면서 저장되어 있을텐데
llm모델에 이렇게 리스트 형태로 HumanMessage, AIMessage의 객체들을 상관없이 대입해도 괜찮은가요?
langchain에서 사용하는 invoke라는 매서드가 내부적으로 이런 타입들을 처리하는 로직을 실행하나요?
감사합니다.
def answer_invoke(message, history):
history_langchain_format = []
for human, ai in history:
history_langchain_format.append(HumanMessage(content=human))
history_langchain_format.append(AIMessage(content=ai))
history_langchain_format.append(HumanMessage(content=message))
# 현재 메시지에 대해 RAG 체인 실행
rag_response = run_route_rag_chain(message)
# 답변 생성 모델에게 현재 메시지에 대한 답변 요청
final_answer = answer_llm.invoke(
history_langchain_format[:-1] + [AIMessage(content=rag_response)] + [HumanMessage(content=message)]
)
return final_answer.content
답변