From 5cdedc3403bd20c07ad0a6bc7b6e26a5ab32606d Mon Sep 17 00:00:00 2001 From: Farouk Adeleke Date: Sat, 27 Dec 2025 02:59:43 -0800 Subject: [PATCH] Syntax fix --- config.json | 1 - main.py | 24 +++++++++++++++++++----- program.json | 37 +++++++++++++++++++++++++++++++++++++ src/neo4j.py | 3 +++ 4 files changed, 59 insertions(+), 6 deletions(-) diff --git a/config.json b/config.json index b5ae9f4..5af9f7d 100644 --- a/config.json +++ b/config.json @@ -1,5 +1,4 @@ { "model": "openai/gpt-4o", - "neo4j_schema": [], "max_tokens": 1024 } \ No newline at end of file diff --git a/main.py b/main.py index aa9ba51..1387180 100644 --- a/main.py +++ b/main.py @@ -29,7 +29,6 @@ class CypherFromText(dspy.Signature): ) class GenerateCypherConfig(PrecompiledConfig): - neo4j_schema: list[str] = [] model: str = "openai/gpt-4o" max_tokens: int = 1024 @@ -37,8 +36,8 @@ class GenerateCypherConfig(PrecompiledConfig): class GenerateCypher(PrecompiledProgram): config: GenerateCypherConfig - def _init_(self, config: GenerateCypherConfig, **kwargs): - super()._init_(**kwargs) + def __init__(self, config: GenerateCypherConfig, **kwargs): + super().__init__(config=config, **kwargs) self.lm = dspy.LM( model=config.model, max_tokens=config.max_tokens, @@ -49,9 +48,24 @@ class GenerateCypher(PrecompiledProgram): 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__": - generate_cypher = GenerateCypher(GenerateCypherConfig()) - generate_cypher.push_to_hub("farouk1/text-to-cypher", with_code=True, tag="v0.0.3", commit_message="set LM") + """ + 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: + data = json.loads(line) + text = data["text"] + print(text[:50]) + cypher = generate_cypher(text=text, neo4j_schema=neo4j.fmt_schema()) + neo4j.query(cypher.statement.replace('```', '')) + """ + schema = neo4j.fmt_schema() + print(schema) + generate_cypher.push_to_hub("farouk1/text-to-cypher", with_code=True, tag="v0.0.4", commit_message="Syntax fix") diff --git a/program.json b/program.json index ac56cba..996d24e 100644 --- a/program.json +++ b/program.json @@ -1,4 +1,41 @@ { + "generate_cypher.predict": { + "traces": [], + "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.", + "fields": [ + { + "prefix": "Text:", + "description": "Text to model using nodes, properties and relationships." + }, + { + "prefix": "Neo 4 J Schema:", + "description": "Current graph schema in Neo4j as a list of NODES and RELATIONSHIPS." + }, + { + "prefix": "Reasoning: Let's think step by step in order to", + "description": "${reasoning}" + }, + { + "prefix": "Statement:", + "description": "Cypher statement to merge nodes and relationships found in the text." + } + ] + }, + "lm": { + "model": "openai/gpt-4o", + "model_type": "chat", + "cache": true, + "num_retries": 3, + "finetuning_model": null, + "launch_kwargs": {}, + "train_kwargs": {}, + "temperature": null, + "max_tokens": 1024 + } + }, "metadata": { "dependency_versions": { "python": "3.13", diff --git a/src/neo4j.py b/src/neo4j.py index 894933a..20953e6 100644 --- a/src/neo4j.py +++ b/src/neo4j.py @@ -113,13 +113,16 @@ class Neo4j: ) self._verify_connection() + print("CONNECTION ESTABLISHED") def close(self): self._driver.close() + print("CONNECTION CLOSED") def _verify_connection(self): with self._driver as driver: driver.verify_connectivity() + print("CONNECTION VERIFIED") def query(self, query, parameters=None, db=None): assert db is None, (