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

Question : how to insert CypherQueryCorrector for chaining #5

Open
vishnu1729 opened this issue Nov 7, 2024 · 0 comments
Open

Question : how to insert CypherQueryCorrector for chaining #5

vishnu1729 opened this issue Nov 7, 2024 · 0 comments

Comments

@vishnu1729
Copy link

vishnu1729 commented Nov 7, 2024

Hi ,

In one of my projects, I am intending to convert user's Natural Language questions into Cypher queries. I found this example to be really useful and mostly following the same structure - https://github.com/neo4j-labs/text2cypher/blob/main/evaluations/evaluating_cypher_jaccard.ipynb.

My LLM model is deployed in Azure Open AI and this is how I have set things up

token_provider = get_bearer_token_provider(DefaultAzureCredential(exclude_interactive_browser_credential=False), "https://cognitiveservices.azure.com/.default")
 
llm = AzureChatOpenAI(
    api_version='<api_version>',
    azure_endpoint="<azure_deployment_endpoint>",
    azure_ad_token_provider=token_provider,
    verbose = True
)

# Generate Cypher statement based on natural language input
cypher_template = """Based on the Neo4j graph schema below,
write a Cypher query that would answer the user's question.
Return only Cypher statement, no backticks, nothing else.
{schema}

Question: {question}
Cypher query:"""  # noqa: E501

cypher_prompt = ChatPromptTemplate.from_messages(
    [
        (
            "system",
            "Given an input question, convert it to a Cypher query. No pre-amble.",
        ),
        ("human", cypher_template),
    ]
)

# https://python.langchain.com/docs/how_to/sequence/
cypher_chain = (
    RunnablePassthrough.assign(
        schema=lambda _: graph.get_schema,
    )
    | cypher_prompt
    | llm.bind(stop=["\nCypherResult:"])
    | StrOutputParser()
)

As you can see I am mostly following the notebook's structure for my work as i am new to Neo4j and using LLMs.
In the linked notebook, i see that CypherQueryCorrector is imported but not used. I need this now as some of my prompts are generating Cyphers with wrong syntax.
Can you advise how this can be inserted in the chain structure above?

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