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

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