Zack Saadioui
8/24/2024
1
2
3
bash
dotenv install
pip install -U langchain-anthropic
1
2
3
4
python
from langchain.anthropic import ChatAnthropic
from langchain.prompts import ChatPromptTemplate
from langchain.memory import ConversationBufferMemory
1
2
python
llm = ChatAnthropic(model='claude-3-opus-20240229', temperature=0)
1
temperature
1
2
3
4
5
6
7
python
prompt = ChatPromptTemplate.from_template(
"""
You are a helpful assistant. Translate the following sentence into French:
{input}
"""
)
1
2
python
memory = ConversationBufferMemory(return_messages=True)
1
2
3
4
5
6
7
8
python
def chat_with_assistant(user_input):
messages = [
("system", "You are a helpful assistant. Translate into French."),
("human", user_input),
]
response = llm.invoke(messages)
return response.content
1
2
3
python
user_input = "I love programming."
print(chat_with_assistant(user_input)) # Expected Output: "J'adore la programmation."
Copyright © Arsturn 2024