from langchain_ollama import ChatOllama
llm = ChatOllama(model="llama3.2:1b")
llm.invoke("What is the capital of France?")
Python
복사
from langchain_core.prompts import PromptTemplate
prompt_template = PromptTemplate(
template="What is the capital of {country}?",
input_variables=["country"],
)
prompt = prompt_template.invoke({"country": "France"})
print(prompt)
llm.invoke(prompt)
Python
복사
from langchain_core.messages import HumanMessage, SystemMessage, AIMessage
message_list = [
SystemMessage(content="You are a helpful assistant."),
HumanMessage(content="What is the capital of France?"),
AIMessage(content="The capital of France is Paris."),
HumanMessage(content="What is the population of Paris?"),
]
llm.invoke(message_list)
Python
복사
HumanMessage는 BaseMessage를 상속받는다.
•
BaseMessage를 상속받는 4가지 : System Prompt, Human (User), AI (LLM), Tool (도구의 실행결과)
•
AIMessage를 넣어줌으로써 우리가 대화 이력이 있었던 것처럼 속일 수 있다. > 답변 유도, 답변 형식 제시
◦
few shot learning paper(논문) : 답변에 예시를 제시하면 정확도가 높아진다는 결과


