langchain.schema import (    AIMessage,    HumanMessage,    SystemMessage)from langchain.chat_models import ChatOpenAIchat = ChatOpenAI()chat([HumanMessage(content="Translate this sentence from English to French: I love programming.")])    AIMessage(content="J'adore la programmation.", additional_kwargs={}, example=False)And if we pass in a list of messages:messages = [    SystemMessage(content="You are a helpful assistant that translates English to French."),    HumanMessage(content="I love programming.")]chat(messages)    AIMessage(content="J'adore la programmation.", additional_kwargs={}, example=False)We can then wrap our chat model in a ConversationChain, which has built-in memory for remembering past user inputs and model outputs.from langchain.chains import ConversationChain    conversation = ConversationChain(llm=chat)  conversation.run("Translate this sentence from English to French: I love programming.")    'Je adore la programmation.'conversation.run("Translate it to German.")    'Ich liebe Programmieren.'Memory‚ÄãAs we mentioned above, the core component of chatbots is the memory system. One of the simplest and most commonly used forms of memory is ConversationBufferMemory:This memory allows for storing of messages in a bufferWhen called in a chain, it returns all of the messages it has storedLangChain comes with many other types of memory, too. See here for in-depth documentation on memory types.For now let's take a quick look at ConversationBufferMemory. We can manually add a few chat messages to the memory like so:from langchain.memory import ConversationBufferMemorymemory = ConversationBufferMemory()memory.chat_memory.add_user_message("hi!")memory.chat_memory.add_ai_message("whats up?")And now we can load from our memory. The key method exposed by all Memory classes is load_memory_variables. This takes in any initial chain input and returns a list of memory variables which are added to the chain input. Since this simple memory type doesn't actually
Open In Colab
Open In Colab ->: langchain.schema import (    AIMessage,    HumanMessage,    SystemMessage)from langchain.chat_models import ChatOpenAIchat = ChatOpenAI()chat([HumanMessage(content="Translate this sentence from English to French: I love programming.")])    AIMessage(content="J'adore la programmation.", additional_kwargs={}, example=False)And if we pass in a list of messages:messages = [    SystemMessage(content="You are a helpful assistant that translates English to French."),    HumanMessage(content="I love programming.")]chat(messages)    AIMessage(content="J'adore la programmation.", additional_kwargs={}, example=False)We can then wrap our chat model in a ConversationChain, which has built-in memory for remembering past user inputs and model outputs.from langchain.chains import ConversationChain    conversation = ConversationChain(llm=chat)  conversation.run("Translate this sentence from English to French: I love programming.")    'Je adore la programmation.'conversation.run("Translate it to German.")    'Ich liebe Programmieren.'Memory‚ÄãAs we mentioned above, the core component of chatbots is the memory system. One of the simplest and most commonly used forms of memory is ConversationBufferMemory:This memory allows for storing of messages in a bufferWhen called in a chain, it returns all of the messages it has storedLangChain comes with many other types of memory, too. See here for in-depth documentation on memory types.For now let's take a quick look at ConversationBufferMemory. We can manually add a few chat messages to the memory like so:from langchain.memory import ConversationBufferMemorymemory = ConversationBufferMemory()memory.chat_memory.add_user_message("hi!")memory.chat_memory.add_ai_message("whats up?")And now we can load from our memory. The key method exposed by all Memory classes is load_memory_variables. This takes in any initial chain input and returns a list of memory variables which are added to the chain input. Since this simple memory type doesn't actually