Skip to content

Commit

Permalink
Updated imports
Browse files Browse the repository at this point in the history
  • Loading branch information
alexthomas93 committed Nov 5, 2024
1 parent d24b334 commit de53c1f
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 30 deletions.
10 changes: 5 additions & 5 deletions libs/neo4j/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The `Neo4jGraph` class is a wrapper around Neo4j's Python driver.
It provides a simple interface for interacting with a Neo4j database.

```python
from langchain_neo4j import Neo4jGraph
from langchain_neo4j.graphs import Neo4jGraph

graph = Neo4jGraph(url="bolt://localhost:7687", username="neo4j", password="password")
graph.query("MATCH (n) RETURN n LIMIT 1;")
Expand All @@ -28,7 +28,7 @@ The `Neo4jChatMessageHistory` class is used to store chat message history in a N
It stores messages as nodes and creates relationships between them, allowing for easy querying of the conversation history.

```python
from langchain_neo4j import Neo4jChatMessageHistory
from langchain_neo4j.chat_message_histories import Neo4jChatMessageHistory

history = Neo4jChatMessageHistory(
url="bolt://localhost:7687",
Expand All @@ -50,7 +50,7 @@ It enables you to create new vector indexes, add vectors to existing indexes, an
from langchain.docstore.document import Document
from langchain_openai import OpenAIEmbeddings

from langchain_neo4j import Neo4jVector
from langchain_neo4j.vectorstores import Neo4jVector

# Create a vector store from some documents and embeddings
docs = [
Expand Down Expand Up @@ -83,10 +83,10 @@ It uses an LLM and the database's schema to translate a user's question into a C
The resulting data is then sent along with the user's question to the LLM to generate a natural language response.

```python
from langchain_neo4j.chains import GraphCypherQAChain
from langchain_neo4j.graphs import Neo4jGraph
from langchain_openai import ChatOpenAI

from langchain_neo4j import GraphCypherQAChain, Neo4jGraph

llm = ChatOpenAI(
temperature=0,
api_key="sk-...", # Replace with your OpenAI API key
Expand Down
9 changes: 0 additions & 9 deletions libs/neo4j/langchain_neo4j/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
from importlib import metadata

from langchain_neo4j.chains.graph_qa.cypher import GraphCypherQAChain
from langchain_neo4j.chat_message_histories.neo4j import Neo4jChatMessageHistory
from langchain_neo4j.graphs.neo4j_graph import Neo4jGraph
from langchain_neo4j.vectorstores.neo4j_vector import Neo4jVector

try:
__version__ = metadata.version(__package__)
except metadata.PackageNotFoundError:
Expand All @@ -13,9 +8,5 @@
del metadata # optional, avoids polluting the results of dir(__package__)

__all__ = [
"GraphCypherQAChain",
"Neo4jChatMessageHistory",
"Neo4jGraph",
"Neo4jVector",
"__version__",
]
3 changes: 3 additions & 0 deletions libs/neo4j/langchain_neo4j/chains/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from langchain_neo4j.chains.graph_qa.cypher import GraphCypherQAChain

__all__ = ["GraphCypherQAChain"]
3 changes: 3 additions & 0 deletions libs/neo4j/langchain_neo4j/chat_message_histories/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from langchain_neo4j.chat_message_histories.neo4j import Neo4jChatMessageHistory

__all__ = ["Neo4jChatMessageHistory"]
3 changes: 3 additions & 0 deletions libs/neo4j/langchain_neo4j/graphs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from langchain_neo4j.graphs.neo4j_graph import Neo4jGraph

__all__ = ["Neo4jGraph"]
3 changes: 3 additions & 0 deletions libs/neo4j/langchain_neo4j/query_constructors/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from langchain_neo4j.query_constructors.neo4j import Neo4jTranslator

__all__ = ["Neo4jTranslator"]
3 changes: 3 additions & 0 deletions libs/neo4j/langchain_neo4j/vectorstores/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from langchain_neo4j.vectorstores.neo4j_vector import Neo4jVector

__all__ = ["Neo4jVector"]
9 changes: 4 additions & 5 deletions libs/neo4j/langchain_neo4j/vectorstores/neo4j_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ class Neo4jVector(VectorStore):
Example:
.. code-block:: python
from langchain_neo4j import Neo4jVector
from langchain_neo4j.vectorstores import Neo4jVector
from langchain_community.embeddings.openai import OpenAIEmbeddings
url="bolt://localhost:7687"
Expand All @@ -477,7 +477,6 @@ class Neo4jVector(VectorStore):
password=password,
)
"""

def __init__(
Expand Down Expand Up @@ -1233,13 +1232,13 @@ def from_embeddings(
Example:
.. code-block:: python
from langchain_neo4j import Neo4jVector
from langchain_community.embeddings import OpenAIEmbeddings
from langchain_neo4j.vectorstores import Neo4jVector
embeddings = OpenAIEmbeddings()
text_embeddings = embeddings.embed_documents(texts)
text_embedding_pairs = list(zip(texts, text_embeddings))
vectorstore = Neo4jVector.from_embeddings(
text_embedding_pairs, embeddings)
vectorstore = Neo4jVector.from_embeddings(text_embedding_pairs, embeddings)

Check failure on line 1241 in libs/neo4j/langchain_neo4j/vectorstores/neo4j_vector.py

View workflow job for this annotation

GitHub Actions / cd libs/neo4j / make lint #3.9

Ruff (E501)

langchain_neo4j/vectorstores/neo4j_vector.py:1241:89: E501 Line too long (91 > 88)
"""
texts = [t[0] for t in text_embeddings]
embeddings = [t[1] for t in text_embeddings]
Expand Down
2 changes: 1 addition & 1 deletion libs/neo4j/tests/integration_tests/graphs/test_neo4j.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from langchain_community.graphs.graph_document import GraphDocument, Node, Relationship
from langchain_core.documents import Document

from langchain_neo4j import Neo4jGraph
from langchain_neo4j.graphs.neo4j_graph import (
BASE_ENTITY_LABEL,
Neo4jGraph,
node_properties_query,
rel_properties_query,
rel_query,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from langchain_core.documents import Document
from yaml import safe_load

from langchain_neo4j import Neo4jGraph
from langchain_neo4j.graphs.neo4j_graph import Neo4jGraph
from langchain_neo4j.vectorstores.neo4j_vector import (
Neo4jVector,
SearchType,
Expand Down
57 changes: 48 additions & 9 deletions libs/neo4j/tests/unit_tests/test_imports.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,52 @@
from langchain_neo4j import __all__
def test_all_imports() -> None:
from langchain_neo4j import __all__

EXPECTED_ALL = [
"GraphCypherQAChain",
"Neo4jChatMessageHistory",
"Neo4jGraph",
"Neo4jVector",
"__version__",
]
EXPECTED_ALL = [
"__version__",
]
assert sorted(EXPECTED_ALL) == sorted(__all__)


def test_all_imports() -> None:
def test_chains_imports() -> None:
from langchain_neo4j.chains import __all__

EXPECTED_ALL = [
"GraphCypherQAChain",
]
assert sorted(EXPECTED_ALL) == sorted(__all__)


def test_chat_message_histories_imports() -> None:
from langchain_neo4j.chat_message_histories import __all__

EXPECTED_ALL = [
"Neo4jChatMessageHistory",
]
assert sorted(EXPECTED_ALL) == sorted(__all__)


def test_graphs_imports() -> None:
from langchain_neo4j.graphs import __all__

EXPECTED_ALL = [
"Neo4jGraph",
]
assert sorted(EXPECTED_ALL) == sorted(__all__)


def test_query_constructors_imports() -> None:
from langchain_neo4j.query_constructors import __all__

EXPECTED_ALL = [
"Neo4jTranslator",
]
assert sorted(EXPECTED_ALL) == sorted(__all__)


def test_vectorstores_imports() -> None:
from langchain_neo4j.vectorstores import __all__

EXPECTED_ALL = [
"Neo4jVector",
]
assert sorted(EXPECTED_ALL) == sorted(__all__)

0 comments on commit de53c1f

Please sign in to comment.