Syntax fix

This commit is contained in:
2025-12-27 02:59:43 -08:00
parent 194597adbc
commit 5cdedc3403
4 changed files with 59 additions and 6 deletions

View File

@@ -1,5 +1,4 @@
{
"model": "openai/gpt-4o",
"neo4j_schema": [],
"max_tokens": 1024
}

24
main.py
View File

@@ -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")

View File

@@ -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",

View File

@@ -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, (