Update README.md

This commit is contained in:
2025-12-27 05:07:01 -08:00
parent 64c45ee66c
commit 501c224540
4 changed files with 17 additions and 21 deletions

27
main.py
View File

@@ -14,23 +14,22 @@ neo4j = Neo4j(
)
class CypherFromText(dspy.Signature):
"""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.
class CypherFromQuestion(dspy.Signature):
"""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."
desc="Question to model using a cypher statement. Use only the provided relationship types and properties in the schema."
)
neo4j_schema = dspy.InputField(
desc="Current graph schema in Neo4j as a list of NODES and RELATIONSHIPS."
)
statement = dspy.OutputField(
desc="Cypher statement to merge nodes and relationships found in the text."
)
statement = dspy.OutputField(desc="Cypher statement to query the graph database.")
class GenerateCypherConfig(PrecompiledConfig):
@@ -47,11 +46,11 @@ class GenerateCypher(PrecompiledProgram):
model=config.model,
max_tokens=config.max_tokens,
)
self.generate_cypher = dspy.ChainOfThought(CypherFromText)
self.generate_cypher = dspy.ChainOfThought(CypherFromQuestion)
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)
def forward(self, question: str, neo4j_schema: list[str]):
return self.generate_cypher(question=question, neo4j_schema=neo4j_schema)
generate_cypher = GenerateCypher(GenerateCypherConfig())
@@ -77,6 +76,6 @@ if __name__ == "__main__":
generate_cypher.push_to_hub(
"farouk1/text-to-cypher",
with_code=True,
tag="v0.0.8",
tag="v0.0.9",
commit_message="Update README.md",
)