langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications

Home Page:https://python.langchain.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AttributeError on calling LLMGraphTransformer.convert_to_graph_documents

mintomohan opened this issue · comments

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

from langchain_experimental.graph_transformers.llm import LLMGraphTransformer
from langchain.llms.bedrock import Bedrock
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain_community.retrievers import WikipediaRetriever
from langchain_community.graphs.neo4j_graph import Neo4jGraph

bedrock=boto3.client(service_name='bedrock-runtime')

def prepare_graph(wiki_keyword):
    wiki_retriever = WikipediaRetriever(doc_content_chars_max=2000, top_k_results=1)
    docs = wiki_retriever.invoke(wiki_keyword)
    
    text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50)
    doc_chunks = text_splitter.split_documents(docs)
    
    llm=Bedrock(model_id='mistral.mistral-7b-instruct-v0:2', client=bedrock)
    llm_transformer = LLMGraphTransformer(llm=llm)    
    
    graph_documents = llm_transformer.convert_to_graph_documents(doc_chunks)
    graph = Neo4jGraph()
    graph.add_graph_documents(graph_documents)

Error Message and Stack Trace (if applicable)

Traceback (most recent call last):
  File "...\...\load_data_graph.py", line 46, in <module>
    prepare_graph('Paris')
  File "...\...\load_data_graph.py", line 38, in prepare_graph
    graph_documents = llm_transformer.convert_to_graph_documents(doc_chunks)
  File "...\...\venv\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 "...\...\venv\lib\site-packages\langchain_experimental\graph_transformers\llm.py", line 646, in <listcomp>
    return [self.process_response(document) for document in documents]
  File "...\...\venv\lib\site-packages\langchain_experimental\graph_transformers\llm.py", line 595, in process_response
    parsed_json = self.json_repair.loads(raw_schema.content)
AttributeError: 'str' object has no attribute 'content'

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

Let me see.