Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with additional_instructions parameter with LLMGraphTransformer (not working) #36

Open
kakolla opened this issue Jan 24, 2025 · 0 comments

Comments

@kakolla
Copy link

kakolla commented Jan 24, 2025

Hi there,

In a project with Neo4J and Langchain, I'm unable to see any difference with the "additional_instructions" parameter to the LLMGraphTransformer as I want to pass in new info to the LLM when generating the graph documents for the Neo4J database. I tested it with simple instructions but it looks like it isn't doing anything.

I'm wondering if it's no longer supported or if I'm setting something up wrong.

Imports:

from langchain_experimental.graph_transformers import LLMGraphTransformer
from langchain_openai import ChatOpenAI

Simple instruction I want to add in

llm = ChatOpenAI(temperature=0, model_name="gpt-3.5-turbo")

graph_transformer_prompt = """
When creating nodes, capitalize the id.
For instance Apple becomes APPLE.
"""
llm_transformer = LLMGraphTransformer(llm=llm, additional_instructions=graph_transformer_prompt)

Converting a document into graph documents

from langchain_core.documents import Document
with open('apple_document.txt', 'r') as file:
    text = file.read()

doc = [Document(page_content=text)]
graph_doc = await llm_transformer.aconvert_to_graph_documents(doc)
graph.add_graph_documents(graph_doc, include_source=True, baseEntityLabel=True)
print(graph_doc)

Output:

[GraphDocument(nodes=[Node(id='Bananas', type='Fruit', properties={}), Node(id='Apples', type='Code word', properties={}), Node(id='Red Trucks', type='Code word', properties={})], relationships=[Relationship(source=Node(id='Bananas', type='Fruit', properties={}), target=Node(id='Apples', type='Code word', properties={}), type='CODE_WORD_FOR', properties={}), Relationship(source=Node(id='Apples', type='Code word', properties={}), target=Node(id='Red Trucks', type='Code word', properties={}), type='CODE_WORD_FOR', properties={})], source=Document(metadata={'id': '83b84d36a24f3f060e3107fa7bc0d748'}, page_content='Bananas are bright yellow fruits.\nApples in this context are a code word for Red trucks.'))]

As it is visible it isn't capitalizing the nodes.
I'm wondering if I'm setting it up wrong, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant