Metadata-Version: 2.1
Name: cypher-ai-helper
Version: 0.1.5
Summary: A simple helper to create and execute Cypher queries for Neo4j
License: MIT
Author: Trayan Azarov
Author-email: trayan.azarov@amikos.tech
Requires-Python: >=3.10,<4.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Requires-Dist: neo4j (>=5.9.0,<6.0.0)
Requires-Dist: openai (>=0.27.8,<0.28.0)
Requires-Dist: pydantic (>=1.10.9,<2.0.0)
Project-URL: Bug Tracker, https://github.com/amikos-tech/cypher-ai-helper/issues
Project-URL: Homepage, https://github.com/amikos-tech/cypher-ai-helper/
Project-URL: Source, https://github.com/amikos-tech/cypher-ai-helper/
Description-Content-Type: text/markdown

# Cypher AI Helper

A helper library for creating Cypher queries with OpenAI API.

## Installation

```bash
pip install cypher-ai-helper
```

## Usage

Start a local neo4j database:

```bash
sh infra/start_neo4j.sh
```

or

```bash
docker run \
    --name neo4j \
    -p 27474:7474 -p 27687:7687 \
    -d \
    -e NEO4J_AUTH=neo4j/pleaseletmein \
    -e NEO4J_PLUGINS=\[\"apoc\"\]  \
    neo4j:latest
```

Then you can run the following:

> Note: You need to set the `OPENAI_API_KEY` environment variable to your OpenAI API key.

```python
import functools

from neo4j import GraphDatabase
from pydantic import BaseModel, Field

from cypher_ai_helper.main import cypher_query, execute_query
from cypher_ai_helper.utils import pydantic_models_to_str


class User(BaseModel):
    """
    A User class
    """
    id: int = Field(..., description="The id of the user")
    name: str = Field(..., description="The name of the user")
    email: str = Field(..., description="The email of the user")


class Post(BaseModel):
    """
    A Post class
    """
    id: int = Field(..., description="The id of the post")
    title: str = Field(..., description="The title of the post")
    body: str = Field(..., description="The body of the post")
    user_name: str = Field(..., description="The name of the user who created the post")


_q = cypher_query("del-all", pydantic_models_to_str([User, Post]),
                  "Delete all nodes and relations",
                  input_vars=[],
                  func=functools.partial(execute_query, driver=GraphDatabase.driver("bolt://localhost:27687",
                                                                                    auth=("neo4j",
                                                                                          "pleaseletmein")),
                                         database="neo4j"))

_q = cypher_query("new-user", pydantic_models_to_str([User, Post]),
                  "Create a new user and return the created user",
                  input_vars=["id", "name", "email"],
                  func=functools.partial(execute_query, driver=GraphDatabase.driver("bolt://localhost:27687",
                                                                                    auth=("neo4j",
                                                                                          "pleaseletmein")),
                                         database="neo4j", params={"id": 2, "name": "post_user", "email": "test"}))
```
