from langchain_core.documents import Document
text = """
Marie Curie, born in 1867, was a Polish and naturalised-French physicist and chemist who conducted pioneering research on radioactivity.
She was the first woman to win a Nobel Prize, the first person to win a Nobel Prize twice, and the only person to win a Nobel Prize in two scientific fields.
Her husband, Pierre Curie, was a co-winner of her first Nobel Prize, making them the first-ever married couple to win the Nobel Prize and launching the Curie family legacy of five Nobel Prizes.
She was, in 1906, the first woman to become a professor at the University of Paris.
"""
documents = [Document(page_content=text)]
graph_documents = llm_transformer.convert_to_graph_documents(documents)
print(f"Nodes:{graph_documents[0].nodes}")
print(f"Relationships:{graph_documents[0].relationships}")---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-38-0a6a66b2d25f> in <cell line: 10>()
8 """
9 documents = [Document(page_content=text)]
---> 10 graph_documents = llm_transformer.convert_to_graph_documents(documents)
11 print(f"Nodes:{graph_documents[0].nodes}")
12 print(f"Relationships:{graph_documents[0].relationships}")
2 frames
/usr/local/lib/python3.10/dist-packages/langchain_experimental/graph_transformers/llm.py in process_response(self, document)
593 nodes_set = set()
594 relationships = []
--> 595 parsed_json = self.json_repair.loads(raw_schema.content)
596 for rel in parsed_json:
597 # Nodes need to be deduplicated using a set
AttributeError: 'str' object has no attribute 'content'
我使用的是Colab Notebooks环境,Llm使用HuggingFaceH4/starchat2-15b-v0.1 API
我在GitHub上发现了类似的问题--https://github.com/langchain-ai/langchain/issues/21482
在此代码中,库在这里开发:https://api.python.langchain.com/en/latest/_modules/langchain_experimental/graph_transformers/llm.html
您正在使用langchain_experimental,所以也许他们正在修复错误,我们需要等待。我认为他们应该在 process_response() 方法中更改以下行
parsed_json = self.json_repair.loads(raw_schema.content)
parsed_json = self.json_repair.loads(raw_schema) 一切都很好。