> Entering new LLMChain chain...    Prompt after formatting:    You are a chatbot having a conversation with a human.        Human: Hi there my friend    AI:  Hi there! How can I help you today?    Human: Not too bad - how are you?    Chatbot:        > Finished chain.    " I'm doing great, thanks for asking! How are you doing?"Adding Memory to a chat model-based LLMChain‚ÄãThe above works for completion-style LLMs, but if you are using a chat model, you will likely get better performance using structured chat messages. Below is an example.from langchain.chat_models import ChatOpenAIfrom langchain.schema import SystemMessagefrom langchain.prompts import ChatPromptTemplate, HumanMessagePromptTemplate, MessagesPlaceholderWe will use the ChatPromptTemplate class to set up the chat prompt.The from_messages method creates a ChatPromptTemplate from a list of messages (e.g., SystemMessage, HumanMessage, AIMessage, ChatMessage, etc.) or message templates, such as the MessagesPlaceholder below.The configuration below makes it so the memory will be injected to the middle of the chat prompt, in the chat_history key, and the user's inputs will be added in a human/user message to the end of the chat prompt.prompt = ChatPromptTemplate.from_messages([    SystemMessage(content="You are a chatbot having a conversation with a human."), # The persistent system prompt    MessagesPlaceholder(variable_name="chat_history"), # Where the memory will be stored.    HumanMessagePromptTemplate.from_template("{human_input}"), # Where the human input will injected])    memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)llm = ChatOpenAI()chat_llm_chain = LLMChain(    llm=llm,    prompt=prompt,    verbose=True,    memory=memory,)chat_llm_chain.predict(human_input="Hi there my friend")            > Entering new LLMChain chain...    Prompt after formatting:    System: You are a chatbot having a conversation with a human.    Human: Hi there my friend        >
This notebook goes over how to use the Memory class with an LLMChain.
This notebook goes over how to use the Memory class with an LLMChain. ->: > Entering new LLMChain chain...    Prompt after formatting:    You are a chatbot having a conversation with a human.        Human: Hi there my friend    AI:  Hi there! How can I help you today?    Human: Not too bad - how are you?    Chatbot:        > Finished chain.    " I'm doing great, thanks for asking! How are you doing?"Adding Memory to a chat model-based LLMChain‚ÄãThe above works for completion-style LLMs, but if you are using a chat model, you will likely get better performance using structured chat messages. Below is an example.from langchain.chat_models import ChatOpenAIfrom langchain.schema import SystemMessagefrom langchain.prompts import ChatPromptTemplate, HumanMessagePromptTemplate, MessagesPlaceholderWe will use the ChatPromptTemplate class to set up the chat prompt.The from_messages method creates a ChatPromptTemplate from a list of messages (e.g., SystemMessage, HumanMessage, AIMessage, ChatMessage, etc.) or message templates, such as the MessagesPlaceholder below.The configuration below makes it so the memory will be injected to the middle of the chat prompt, in the chat_history key, and the user's inputs will be added in a human/user message to the end of the chat prompt.prompt = ChatPromptTemplate.from_messages([    SystemMessage(content="You are a chatbot having a conversation with a human."), # The persistent system prompt    MessagesPlaceholder(variable_name="chat_history"), # Where the memory will be stored.    HumanMessagePromptTemplate.from_template("{human_input}"), # Where the human input will injected])    memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)llm = ChatOpenAI()chat_llm_chain = LLMChain(    llm=llm,    prompt=prompt,    verbose=True,    memory=memory,)chat_llm_chain.predict(human_input="Hi there my friend")            > Entering new LLMChain chain...    Prompt after formatting:    System: You are a chatbot having a conversation with a human.    Human: Hi there my friend        >