LLMGraphTransformer.convert_to_graph_documents(文档)AttributeError:“str”对象没有属性“content”

问题描述 投票:0回答:1
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

python python-3.x langchain
1个回答
0
投票

在此代码中,库在这里开发: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) 一切都很好。

© www.soinside.com 2019 - 2024. All rights reserved.