Update README.md
This commit is contained in:
@@ -5,9 +5,6 @@ LLM-driven automated knowledge graph construction from text using DSPy and Neo4j
|
|||||||
```sh
|
```sh
|
||||||
text-to-cypher/
|
text-to-cypher/
|
||||||
├── README.md
|
├── README.md
|
||||||
├── examples/
|
|
||||||
│ └── wikipedia-abstracts-v0_0_1.ndjson
|
|
||||||
├── img/
|
|
||||||
├── main.py
|
├── main.py
|
||||||
├── pyproject.toml
|
├── pyproject.toml
|
||||||
├── uv.lock
|
├── uv.lock
|
||||||
|
|||||||
17
main.py
17
main.py
@@ -14,7 +14,7 @@ neo4j = Neo4j(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class CypherFromText(dspy.Signature):
|
class CypherFromQuestion(dspy.Signature):
|
||||||
"""Task: Generate Cypher statement to query a graph database.
|
"""Task: Generate Cypher statement to query a graph database.
|
||||||
Instructions: Use only the provided relationship types and properties in the schema.
|
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 use any other relationship types or properties that are not provided in the schema.
|
||||||
@@ -22,15 +22,14 @@ class CypherFromText(dspy.Signature):
|
|||||||
Do not respond to any questions that might ask anything else than for you to construct a Cypher statement.
|
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.
|
Do not include any text except the generated Cypher statement.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
question = dspy.InputField(
|
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(
|
neo4j_schema = dspy.InputField(
|
||||||
desc="Current graph schema in Neo4j as a list of NODES and RELATIONSHIPS."
|
desc="Current graph schema in Neo4j as a list of NODES and RELATIONSHIPS."
|
||||||
)
|
)
|
||||||
statement = dspy.OutputField(
|
statement = dspy.OutputField(desc="Cypher statement to query the graph database.")
|
||||||
desc="Cypher statement to merge nodes and relationships found in the text."
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class GenerateCypherConfig(PrecompiledConfig):
|
class GenerateCypherConfig(PrecompiledConfig):
|
||||||
@@ -47,11 +46,11 @@ class GenerateCypher(PrecompiledProgram):
|
|||||||
model=config.model,
|
model=config.model,
|
||||||
max_tokens=config.max_tokens,
|
max_tokens=config.max_tokens,
|
||||||
)
|
)
|
||||||
self.generate_cypher = dspy.ChainOfThought(CypherFromText)
|
self.generate_cypher = dspy.ChainOfThought(CypherFromQuestion)
|
||||||
self.generate_cypher.set_lm(self.lm)
|
self.generate_cypher.set_lm(self.lm)
|
||||||
|
|
||||||
def forward(self, text: str, neo4j_schema: list[str]):
|
def forward(self, question: str, neo4j_schema: list[str]):
|
||||||
return self.generate_cypher(text=text, neo4j_schema=neo4j_schema)
|
return self.generate_cypher(question=question, neo4j_schema=neo4j_schema)
|
||||||
|
|
||||||
|
|
||||||
generate_cypher = GenerateCypher(GenerateCypherConfig())
|
generate_cypher = GenerateCypher(GenerateCypherConfig())
|
||||||
@@ -77,6 +76,6 @@ if __name__ == "__main__":
|
|||||||
generate_cypher.push_to_hub(
|
generate_cypher.push_to_hub(
|
||||||
"farouk1/text-to-cypher",
|
"farouk1/text-to-cypher",
|
||||||
with_code=True,
|
with_code=True,
|
||||||
tag="v0.0.8",
|
tag="v0.0.9",
|
||||||
commit_message="Update README.md",
|
commit_message="Update README.md",
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"prefix": "Question:",
|
"prefix": "Question:",
|
||||||
"description": "Question to model using a cypher statement."
|
"description": "Question to model using a cypher statement. Use only the provided relationship types and properties in the schema."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"prefix": "Neo 4 J Schema:",
|
"prefix": "Neo 4 J Schema:",
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"prefix": "Statement:",
|
"prefix": "Statement:",
|
||||||
"description": "Cypher statement to merge nodes and relationships found in the text."
|
"description": "Cypher statement to query the graph database."
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -4,4 +4,4 @@ version = "0.1.0"
|
|||||||
description = "Add your description here"
|
description = "Add your description here"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.13"
|
requires-python = ">=3.13"
|
||||||
dependencies = ["datasets>=4.4.2", "dspy>=3.0.4", "modaic>=0.8.2", "neo4j~=5.18.0", "python-dotenv~=1.0.1"]
|
dependencies = ["datasets>=4.4.2", "dspy>=3.0.4", "modaic>=0.8.2", "neo4j~=5.18.0", "python-dotenv~=1.0.1", "sacrebleu>=2.5.1"]
|
||||||
|
|||||||
Reference in New Issue
Block a user