from langchain_core.output_parsers import JsonOutputParser
country_detail_prompt = PromptTemplate(
template="""Give following infomation about {country}:
- Capital
- Population
- Language
- Currency
return it in JSON format. and return the JSON dictionary only
""",
input_variables=["country"],
)
country_detail_prompt.invoke({"country": "France"})
# output_parser = JsonOutputParser()
json_ai_message = structured_llm.invoke(country_detail_prompt.invoke({"country": "France"}))
# output_parser.invoke(llm.invoke(country_detail_prompt.invoke({"country": "France"})))
Python
복사
결과형식도, llm 답변도, 프롬프트도, 도구도 모두 invoke 하고있다.
왜?
•
class를 따라 가다보면 Runnable 이라는 class를 모두 상속하고 있다.
•
그리고 모든 llm model이 BaseChatModel을 상속받는다. 그리고! BaseChatModel은 Runnable을 상속받는다.
•
Runnable 안에는 invoke라는 메서드가 존재한다. 고로 모두 invoke 하는 것이다.
LangChain은 모든게 Runaable이다.


