From 64c45ee66c84d1dd489111a0e4e7d468db8b47d1 Mon Sep 17 00:00:00 2001 From: Farouk Adeleke Date: Sat, 27 Dec 2025 04:33:07 -0800 Subject: [PATCH] Update README.md --- main.py | 35 ++++++++++++++++++++++------------- program.json | 6 +++--- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/main.py b/main.py index 0868cac..f74259f 100644 --- a/main.py +++ b/main.py @@ -13,13 +13,17 @@ neo4j = Neo4j( password=os.getenv("NEO4J_PASSWORD"), ) + class CypherFromText(dspy.Signature): - """Instructions: - Create a Cypher MERGE statement to model all entities and relationships found in the text following these guidelines: - - Refer to the provided schema and use existing or similar nodes, properties or relationships before creating new ones. - - Use generic categories for node and relationship labels.""" - text = dspy.InputField( - desc="Text to model using nodes, properties and relationships." + """Task: Generate Cypher statement to query a graph database. + Instructions: Use only the provided relationship types and properties in the schema. + Do not use any other relationship types or properties that are not provided in the schema. + Do not include any explanations or apologies in your responses. + Do not respond to any questions that might ask anything else than for you to construct a Cypher statement. + Do not include any text except the generated Cypher statement. + """ + question = dspy.InputField( + desc="Question to model using a cypher statement." ) neo4j_schema = dspy.InputField( desc="Current graph schema in Neo4j as a list of NODES and RELATIONSHIPS." @@ -28,10 +32,11 @@ class CypherFromText(dspy.Signature): desc="Cypher statement to merge nodes and relationships found in the text." ) + class GenerateCypherConfig(PrecompiledConfig): model: str = "openai/gpt-4o" max_tokens: int = 1024 - + class GenerateCypher(PrecompiledProgram): config: GenerateCypherConfig @@ -44,16 +49,18 @@ class GenerateCypher(PrecompiledProgram): ) self.generate_cypher = dspy.ChainOfThought(CypherFromText) self.generate_cypher.set_lm(self.lm) - + def forward(self, text: str, neo4j_schema: list[str]): return self.generate_cypher(text=text, neo4j_schema=neo4j_schema) + generate_cypher = GenerateCypher(GenerateCypherConfig()) if __name__ == "__main__": + """ from pathlib import Path import json - """ + examples_path = Path(__file__).parent / "examples" / "wikipedia-abstracts-v0_0_1.ndjson" with open(examples_path, "r") as f: for line in f: @@ -67,7 +74,9 @@ if __name__ == "__main__": schema = neo4j.fmt_schema() print("SCHEMA:\n", schema) """ - generate_cypher.push_to_hub("farouk1/text-to-cypher", with_code=True, tag="v0.0.7", commit_message="Update README.md") - - - + generate_cypher.push_to_hub( + "farouk1/text-to-cypher", + with_code=True, + tag="v0.0.8", + commit_message="Update README.md", + ) diff --git a/program.json b/program.json index 996d24e..4746505 100644 --- a/program.json +++ b/program.json @@ -4,11 +4,11 @@ "train": [], "demos": [], "signature": { - "instructions": "Instructions:\nCreate a Cypher MERGE statement to model all entities and relationships found in the text following these guidelines:\n- Refer to the provided schema and use existing or similar nodes, properties or relationships before creating new ones.\n- Use generic categories for node and relationship labels.", + "instructions": "Task: Generate Cypher statement to query a graph database. \nInstructions: Use only the provided relationship types and properties in the schema. \nDo not use any other relationship types or properties that are not provided in the schema. \nDo not include any explanations or apologies in your responses. \nDo not respond to any questions that might ask anything else than for you to construct a Cypher statement. \nDo not include any text except the generated Cypher statement.", "fields": [ { - "prefix": "Text:", - "description": "Text to model using nodes, properties and relationships." + "prefix": "Question:", + "description": "Question to model using a cypher statement." }, { "prefix": "Neo 4 J Schema:",