==> {'source': 'https://python.langchain.com/docs/how_to/chatbots_memory/', 'title': 'How to add memory to chatbots | \uf8ffü¶úÔ∏è\uf8ffüîó LangChain', 'description': 'A key feature of chatbots is their ability to use content of previous conversation turns as context. This state management can take several forms, including:', 'language': 'en'}
How to add memory to chatbots | ü¶úÔ∏èüîó LangChain
Skip to main contentShare your thoughts on AI agents. Take the 3-min survey.IntegrationsAPI ReferenceMoreContributingPeopleLangSmithLangGraphLangChain HubLangChain JS/TSv0.3v0.3v0.2v0.
这基本上是页面 HTML 中文本的转储。它可能包含多余的信息,如标题和导航栏。如果您熟悉预期的 HTML,您可以通过 BeautifulSoup 指定所需的 <div> 类和其他参数。下面我们仅解析文章的主体文本:
How to add memory to chatbots | A key feature of chatbots is their ability to use content of previous conversation turns as context. This state management can take several forms, including:
# This is a large nested json object and will be loaded as a python dict json_data = requests.get("https://api.smith.langchain.com/openapi.json").json()
%pip install -qU langchain-text-splitters from langchain_text_splitters import RecursiveCharacterTextSplitter
# Load example document withopen("state_of_the_union.txt") as f: state_of_the_union = f.read()
text_splitter = RecursiveCharacterTextSplitter( # Set a really small chunk size, just to show. chunk_size=100, chunk_overlap=20, length_function=len, is_separator_regex=False, ) texts = text_splitter.create_documents([state_of_the_union]) print(texts[0]) print(texts[1]) text_splitter.split_text(state_of_the_union)[:2]
from langchain_community.document_loaders import WebBaseLoader from langchain_text_splitters import RecursiveCharacterTextSplitter from langchain_openai import OpenAIEmbeddings from langchain_community.vectorstores import Chroma from langchain.chains import RetrievalQA