I ve searched all over langchain documentation on their official website but I didn t find how to create a langchain doc from a str variable in python so I searched in their GitHub code and I found this :
doc=Document(
page_content="text",
metadata={"source": "local"}
)
PS: I added the metadata attribute
then I tried using that doc with my chain:
Memory and Chain:
memory = ConversationBufferMemory(memory_key="chat_history", input_key="human_input")
chain = load_qa_chain(
llm, chain_type="stuff", memory=memory, prompt=prompt
)
电话方法:
chain({"input_documents": doc, "human_input": query})
即时模板:
template = """You are a senior financial analyst analyzing the below document and having a conversation with a human.
{context}
{chat_history}
Human: {human_input}
senior financial analyst:"""
prompt = PromptTemplate(
input_variables=["chat_history", "human_input", "context"], template=template
)
but I am getting the following error:
AttributeError: tuple object has no attribute page_content
当我试图在使用文件链条之前检查文件物体的类型和页数时,我就这样做。
print(type(doc))
<class langchain.schema.Document >
print(doc.page_content)
"text"