Open mintomohan opened 5 months ago
Let me see.
I am having the same issue here :'/
its able to run llama2 server and model but having this same bug/error
CODE: %pip install --upgrade --quiet langchain langchain-community langchain-openai langchain-experimental neo4j json_repair
import os import json import types from langchain_community.graphs import Neo4jGraph from langchain_experimental.graph_transformers import LLMGraphTransformer from langchain_openai import ChatOpenAI from langchain_core.documents import Document from langchain_community.llms import Ollama
llm = Ollama(temperature=0, model="llama2") llm_transformer = LLMGraphTransformer(llm=llm)
os.environ["NEO4J_URI"] = "neo4j://localhost:7687" os.environ["NEO4J_USERNAME"] = "neo4j" os.environ["NEO4J_PASSWORD"] = "neo4jadmin"
graph = Neo4jGraph()
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)
AttributeError Traceback (most recent call last) Cell In[27], line 2 1 documents = [Document(page_content=text)] ----> 2 graph_documents = llm_transformer.convert_to_graph_documents(documents)
File C:\tools\Anaconda3\lib\site-packages\langchain_experimental\graph_transformers\llm.py:646, in LLMGraphTransformer.convert_to_graph_documents(self, documents) 634 def convert_to_graph_documents( 635 self, documents: Sequence[Document] 636 ) -> List[GraphDocument]: 637 """Convert a sequence of documents into graph documents. 638 639 Args: (...) 644 Sequence[GraphDocument]: The transformed documents as graphs. 645 """ --> 646 return [self.process_response(document) for document in documents]
File C:\tools\Anaconda3\lib\site-packages\langchain_experimental\graph_transformers\llm.py:646, in
File C:\tools\Anaconda3\lib\site-packages\langchain_experimental\graph_transformers\llm.py:595, in LLMGraphTransformer.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 598 nodes_set.add((rel["head"], rel["head_type"]))
AttributeError: 'str' object has no attribute 'content'
AttributeError Traceback (most recent call last)
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' I encountered the same problem
I'm also facing the same error.
Running the same "Marie Curie" use case (with AzureOpeAi) i always get empty nodes. On Langsmith I can that the model is able to extract the nodes, but i see on the PydanticToolsParser step:
[big json here] are not valid JSON. Received JSONDecodeError Expecting value: line 1 column 1 (char 0)
Updates on the original issue:
(1) I switched from Mistral to OpenAI (GPT 3.5 Turbo) and encountered a different error message.
ValueError: Could not use APOC procedures.
(2) I referred to the following issue and adjusted the settings in Neo4j as suggested: https://github.com/langchain-ai/langchain/issues/12901#issuecomment-1836657528
Currently, I am facing this error:
graph_documents = llm_transformer.convert_to_graph_documents(doc_chunks)
File "...\...\lib\site-packages\langchain_experimental\graph_transformers\llm.py", line 646, in convert_to_graph_documents
return [self.process_response(document) for document in documents]
File "...\...\lib\site-packages\langchain_experimental\graph_transformers\llm.py", line 646, in <listcomp>
return [self.process_response(document) for document in documents]
File "...\...\lib\site-packages\langchain_experimental\graph_transformers\llm.py", line 598, in process_response nodes_set.add((rel["head"], rel["head_type"]))
TypeError: string indices must be integers
Version Info:
langchain 0.1.20
langchain-aws 0.1.6
langchain-cohere 0.1.5
langchain-community 0.0.38
langchain-core 0.1.52
langchain-experimental 0.0.58
langchain-openai 0.0.5
langchain-text-splitters 0.0.1
neo4j 5.20.0
I also have met this kind of error
graph_documents = llm_transformer.convert_to_graph_documents(documents)
File "d:\Anaconda3_2019_10\envs\llm\lib\site-packages\langchain_experimental\graph_transformers\llm.py", line 762, in convert_to_graph_documents
return [self.process_response(document) for document in documents]
File "d:\Anaconda3_2019_10\envs\llm\lib\site-packages\langchain_experimental\graph_transformers\llm.py", line 762, in <listcomp>
return [self.process_response(document) for document in documents]
File "d:\Anaconda3_2019_10\envs\llm\lib\site-packages\langchain_experimental\graph_transformers\llm.py", line 714, in process_response
nodes_set.add((rel["head"], rel["head_type"]))
TypeError: string indices must be integers
Hello @TangJiamin I have also same issue when using llama3 witth llamacpp. Do you have any solution to fix it?
We've added a lot of fixes. Can you check noe
Looks like this code is moving to a different repository.
Hi!
I'm also facing AttributeError
AttributeError: 'dict' object has no attribute 'nodes'
When using the LLMGraphTransformer, i'm following the tuto from the langchain documentation and got an error either with gpt-4-turbo or gpt-4o-mini
here are my langchain version:
langchain==0.3.5 langchain-community==0.3.3 langchain-core==0.3.13 langchain-experimental==0.3.2 langchain-openai==0.1.17 langchain-text-splitters==0.3.1
AttributeError Traceback (most recent call last) Cell In[84], line 10 3 text = """ 4 Marie Curie, born in 1867, was a Polish and naturalised-French physicist and chemist who conducted pioneering research on radioactivity. 5 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. 6 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. 7 She was, in 1906, the first woman to become a professor at the University of Paris. 8 """ 9 documents = [Document(page_content=text)] ---> 10 graph_documents = llm_transformer.convert_to_graph_documents(documents)
File ~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:809, in LLMGraphTransformer.convert_to_graph_documents(self, documents, config) 797 def convert_to_graph_documents( 798 self, documents: Sequence[Document], config: Optional[RunnableConfig] = None 799 ) -> List[GraphDocument]: 800 """Convert a sequence of documents into graph documents. 801 802 Args: (...) 807 Sequence[GraphDocument]: The transformed documents as graphs. 808 """ --> 809 return [self.process_response(document, config) for document in documents]
File ~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:809, in
File ~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:742, in LLMGraphTransformer.process_response(self, document, config) 740 if self._function_call: 741 raw_schema = cast(Dict[Any, Any], raw_schema) --> 742 nodes, relationships = _convert_to_graph_document(raw_schema) 743 else: 744 nodes_set = set()
File ~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:609, in _convert_to_graph_document(raw_schema) 605 else: # If there are no validation errors use parsed pydantic object 606 parsed_schema: _Graph = raw_schema["parsed"] 607 nodes = ( 608 [map_to_base_node(node) for node in parsed_schema.nodes if node.id] --> 609 if parsed_schema.nodes 610 else [] 611 ) 613 relationships = ( 614 [ 615 map_to_base_relationship(rel) (...) 620 else [] 621 ) 622 # Title / Capitalize
AttributeError: 'dict' object has no attribute 'nodes'
Thats weird, I'll look into it
V sre., 30. okt. 2024, 23:38 je oseba JulienF @.***> napisala:
Hi! I'm also facing AttributeError AttributeError: 'dict' object has no attribute 'nodes'
When using the LLMGraphTransformer, i'm following the tuto from the langchain documentation and got an error either with gpt-4-turbo or gpt-4o-mini Error
AttributeError Traceback (most recent call last) Cell In[84], line 10 3 text = """ 4 Marie Curie, born in 1867, was a Polish and naturalised-French physicist and chemist who conducted pioneering research on radioactivity. 5 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. 6 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. 7 She was, in 1906, the first woman to become a professor at the University of Paris. 8 """ 9 documents = [Document(page_content=text)] ---> 10 graph_documents = llm_transformer.convert_to_graph_documents(documents)
File ~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:809, in LLMGraphTransformer.convert_to_graph_documents(self, documents, config) 797 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:797 def convert_to_graph_documents( 798 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:798 self, documents: Sequence[Document], config: Optional[RunnableConfig] = None 799 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:799 ) -> List[GraphDocument]: 800 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:800 """Convert a sequence of documents into graph documents. 801 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:801 802 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:802 Args: (...) 807 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:807 Sequence[GraphDocument]: The transformed documents as graphs. 808 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:808 """ --> 809 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:809 return [self.process_response(document, config) for document in documents]
File ~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:809, in (.0) 797 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:797 def convert_to_graph_documents( 798 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:798 self, documents: Sequence[Document], config: Optional[RunnableConfig] = None 799 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:799 ) -> List[GraphDocument]: 800 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:800 """Convert a sequence of documents into graph documents. 801 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:801 802 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:802 Args: (...) 807 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:807 Sequence[GraphDocument]: The transformed documents as graphs. 808 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:808 """ --> 809 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:809 return [self.process_response(document, config) for document in documents]
File ~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:742, in LLMGraphTransformer.process_response(self, document, config) 740 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:740 if self._function_call: 741 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:741 raw_schema = cast(Dict[Any, Any], raw_schema) --> 742 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:742 nodes, relationships = _convert_to_graph_document(raw_schema) 743 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:743 else: 744 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:744 nodes_set = set()
File ~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:609, in _convert_to_graph_document(raw_schema) 605 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:605 else: # If there are no validation errors use parsed pydantic object 606 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:606 parsed_schema: _Graph = raw_schema["parsed"] 607 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:607 nodes = ( 608 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:608 [map_to_base_node(node) for node in parsed_schema.nodes if node.id] --> 609 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:609 if parsed_schema.nodes 610 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:610 else [] 611 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:611 ) 613 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:613 relationships = ( 614 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:614 [ 615 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:615 map_to_base_relationship(rel) (...) 620 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:620 else [] 621 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:621 ) 622 https://file+.vscode-resource.vscode-cdn.net/Users/julienfresnel/Documents/modjo-ml/nlp/graphrag/~/miniconda3/envs/name_finder/lib/python3.9/site-packages/langchain_experimental/graph_transformers/llm.py:622
Title / Capitalize
AttributeError: 'dict' object has no attribute 'nodes'
— Reply to this email directly, view it on GitHub https://github.com/langchain-ai/langchain/issues/21482#issuecomment-2447756160, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEYGGTM3I6ZJIYI2R4N5UZTZ6EDSBAVCNFSM6AAAAABHOZ7KV6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINBXG42TMMJWGA . You are receiving this because you commented.Message ID: @.***>
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
Description
I am trying to load a page from Wikipedia, split it and load to Neo4j using langchain
Wikipedia --> WikipediaRetriever --> RecursiveCharacterTextSplitter --> LLMGraphTransformer --> Neo4jGraph
LLM used is Mistral 7B (using AWS Bedrock)
System Info
langchain==0.1.17 langchain-community==0.0.36 langchain-core==0.1.52 langchain-experimental==0.0.58 langchain-text-splitters==0.0.1 langsmith==0.1.52
platform : windows
Python 3.10.8