Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jonbesga/tests #2

Merged
merged 9 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*]
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = lf
charset = utf-8
max_line_length = 88
34 changes: 34 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: neo4j_genai PR
on: pull_request

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
- name: Install root project
run: poetry install --no-interaction
- name: Check format and linting
run: |
poetry run ruff format --check .
poetry run ruff check .
- name: Run tests and check coverage
run: |
poetry run coverage run -m pytest
poetry run coverage report --fail-under=85
72 changes: 72 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Publish Python 🐍 distribution 📦

on: push

jobs:
build:
name: Build distribution 📦
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.8"
- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: PyPI
if: startsWith(github.ref, 'refs/tags/')
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/neo4j-genai
permissions:
id-token: write
steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

publish-to-testpypi:
name: TestPyPI
needs:
- build
runs-on: ubuntu-latest

environment:
name: testpypi
url: https://test.pypi.org/p/neo4j-genai

permissions:
id-token: write

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
dist/
**/__pycache__/*
*.py[cod]
.mypy_cache/
.mypy_cache/
.coverage
htmlcov/
.idea/
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0 # Use the ref you want to point at
rev: v4.5.0
hooks:
- id: trailing-whitespace
# - id: ...
- id: end-of-file-fixer
13 changes: 6 additions & 7 deletions examples/similarity_search_for_text.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from typing import List
from neo4j import GraphDatabase
from neo4j.exceptions import DatabaseError
from neo4j_genai.client import GenAIClient

from random import random
from neo4j_genai.embeddings import Embeddings
from neo4j_genai.embedder import Embedder

URI = "neo4j://localhost:7687"
AUTH = ("neo4j", "password")
Expand All @@ -16,16 +15,16 @@
driver = GraphDatabase.driver(URI, auth=AUTH)


# Create Embeddings object
class CustomEmbeddings(Embeddings):
# Create Embedder object
class CustomEmbedder(Embedder):
def embed_query(self, text: str) -> List[float]:
return [random() for _ in range(DIMENSION)]


embeddings = CustomEmbeddings()
embedder = CustomEmbedder()

# Initialize the client
client = GenAIClient(driver, embeddings)
client = GenAIClient(driver, embedder)

# Creating the index
client.create_index(
Expand All @@ -47,7 +46,7 @@ def embed_query(self, text: str) -> List[float]:
parameters = {
"vector": vector,
}
client.database_query(insert_query, params=parameters)
driver.execute_query(insert_query, parameters)

# Perform the similarity search for a text query
query_text = "hello world"
Expand Down
3 changes: 2 additions & 1 deletion examples/similarity_search_for_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
parameters = {
"vector": vector,
}
client.database_query(insert_query, params=parameters)

driver.execute_query(insert_query, parameters)

# Perform the similarity search for a vector query
query_vector = [random() for _ in range(DIMENSION)]
Expand Down
Loading
Loading