diff --git a/poetry.lock b/poetry.lock index 314f710..c913df2 100644 --- a/poetry.lock +++ b/poetry.lock @@ -819,25 +819,6 @@ files = [ {file = "distlib-0.3.7.tar.gz", hash = "sha256:9dafe54b34a028eafd95039d5e5d4851a13734540f1331060d31c9916e7147a8"}, ] -[[package]] -name = "dnspython" -version = "2.4.2" -description = "DNS toolkit" -optional = false -python-versions = ">=3.8,<4.0" -files = [ - {file = "dnspython-2.4.2-py3-none-any.whl", hash = "sha256:57c6fbaaeaaf39c891292012060beb141791735dbb4004798328fc2c467402d8"}, - {file = "dnspython-2.4.2.tar.gz", hash = "sha256:8dcfae8c7460a2f84b4072e26f1c9f4101ca20c071649cb7c34e8b6a93d58984"}, -] - -[package.extras] -dnssec = ["cryptography (>=2.6,<42.0)"] -doh = ["h2 (>=4.1.0)", "httpcore (>=0.17.3)", "httpx (>=0.24.1)"] -doq = ["aioquic (>=0.9.20)"] -idna = ["idna (>=2.1,<4.0)"] -trio = ["trio (>=0.14,<0.23)"] -wmi = ["wmi (>=1.5.1,<2.0.0)"] - [[package]] name = "exceptiongroup" version = "1.2.0" @@ -1616,24 +1597,6 @@ files = [ {file = "kiwisolver-1.4.5.tar.gz", hash = "sha256:e57e563a57fb22a142da34f38acc2fc1a5c864bc29ca1517a88abc963e60d6ec"}, ] -[[package]] -name = "loguru" -version = "0.7.2" -description = "Python logging made (stupidly) simple" -optional = false -python-versions = ">=3.5" -files = [ - {file = "loguru-0.7.2-py3-none-any.whl", hash = "sha256:003d71e3d3ed35f0f8984898359d65b79e5b21943f78af86aa5491210429b8eb"}, - {file = "loguru-0.7.2.tar.gz", hash = "sha256:e671a53522515f34fd406340ee968cb9ecafbc4b36c679da03c18fd8d0bd51ac"}, -] - -[package.dependencies] -colorama = {version = ">=0.3.4", markers = "sys_platform == \"win32\""} -win32-setctime = {version = ">=1.0.0", markers = "sys_platform == \"win32\""} - -[package.extras] -dev = ["Sphinx (==7.2.5)", "colorama (==0.4.5)", "colorama (==0.4.6)", "exceptiongroup (==1.1.3)", "freezegun (==1.1.0)", "freezegun (==1.2.2)", "mypy (==v0.910)", "mypy (==v0.971)", "mypy (==v1.4.1)", "mypy (==v1.5.1)", "pre-commit (==3.4.0)", "pytest (==6.1.2)", "pytest (==7.4.0)", "pytest-cov (==2.12.1)", "pytest-cov (==4.1.0)", "pytest-mypy-plugins (==1.9.3)", "pytest-mypy-plugins (==3.0.0)", "sphinx-autobuild (==2021.3.14)", "sphinx-rtd-theme (==1.3.0)", "tox (==3.27.1)", "tox (==4.11.0)"] - [[package]] name = "markdown-it-py" version = "3.0.0" @@ -2231,28 +2194,35 @@ tests = ["check-manifest", "coverage", "defusedxml", "markdown2", "olefile", "pa [[package]] name = "pinecone-client" -version = "2.2.4" +version = "4.1.1" description = "Pinecone client and SDK" optional = false -python-versions = ">=3.8" +python-versions = "<4.0,>=3.8" files = [ - {file = "pinecone-client-2.2.4.tar.gz", hash = "sha256:2c1cc1d6648b2be66e944db2ffa59166a37b9164d1135ad525d9cd8b1e298168"}, - {file = "pinecone_client-2.2.4-py3-none-any.whl", hash = "sha256:5bf496c01c2f82f4e5c2dc977cc5062ecd7168b8ed90743b09afcc8c7eb242ec"}, + {file = "pinecone_client-4.1.1-py3-none-any.whl", hash = "sha256:e74ea91a0129a80f301662e286b1883f2eb896683ff7d2cdb03ea06346844d0d"}, + {file = "pinecone_client-4.1.1.tar.gz", hash = "sha256:b2e78c29de50c180dbfe75e15f08c87ec1a3a4f1bc6b2be1f0ccaee1ab4434fa"}, ] [package.dependencies] -dnspython = ">=2.0.0" -loguru = ">=0.5.0" -numpy = ">=1.22.0" -python-dateutil = ">=2.5.3" -pyyaml = ">=5.4" -requests = ">=2.19.0" +certifi = ">=2019.11.17" +pinecone-plugin-interface = ">=0.0.7,<0.0.8" tqdm = ">=4.64.1" typing-extensions = ">=3.7.4" -urllib3 = ">=1.21.1" +urllib3 = {version = ">=1.26.0", markers = "python_version >= \"3.8\" and python_version < \"3.12\""} [package.extras] -grpc = ["googleapis-common-protos (>=1.53.0)", "grpc-gateway-protoc-gen-openapiv2 (==0.1.0)", "grpcio (>=1.44.0)", "lz4 (>=3.1.3)", "protobuf (>=3.20.0,<3.21.0)"] +grpc = ["googleapis-common-protos (>=1.53.0)", "grpcio (>=1.44.0)", "grpcio (>=1.59.0)", "lz4 (>=3.1.3)", "protobuf (>=4.25,<5.0)", "protoc-gen-openapiv2 (>=0.0.1,<0.0.2)"] + +[[package]] +name = "pinecone-plugin-interface" +version = "0.0.7" +description = "Plugin interface for the Pinecone python client" +optional = false +python-versions = "<4.0,>=3.8" +files = [ + {file = "pinecone_plugin_interface-0.0.7-py3-none-any.whl", hash = "sha256:875857ad9c9fc8bbc074dbe780d187a2afd21f5bfe0f3b08601924a61ef1bba8"}, + {file = "pinecone_plugin_interface-0.0.7.tar.gz", hash = "sha256:b8e6675e41847333aa13923cc44daa3f85676d7157324682dc1640588a982846"}, +] [[package]] name = "platformdirs" @@ -3659,20 +3629,6 @@ MarkupSafe = ">=2.1.1" [package.extras] watchdog = ["watchdog (>=2.3)"] -[[package]] -name = "win32-setctime" -version = "1.1.0" -description = "A small Python utility to set file creation time on Windows" -optional = false -python-versions = ">=3.5" -files = [ - {file = "win32_setctime-1.1.0-py3-none-any.whl", hash = "sha256:231db239e959c2fe7eb1d7dc129f11172354f98361c4fa2d6d2d7e278baa8aad"}, - {file = "win32_setctime-1.1.0.tar.gz", hash = "sha256:15cf5750465118d6929ae4de4eb46e8edae9a5634350c01ba582df868e932cb2"}, -] - -[package.extras] -dev = ["black (>=19.3b0)", "pytest (>=4.6.2)"] - [[package]] name = "wrapt" version = "1.16.0" @@ -3902,4 +3858,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "3.9.17" -content-hash = "097fdacd61920e18edd5e7bf5f37595c268ea0c6e7eecd49f17eb4ad731b934a" +content-hash = "9ac0417e3e3a1fe7ed62b938045c0c90b3bf894c30640548ebccf50b9b260406" diff --git a/pyproject.toml b/pyproject.toml index 6c52eb0..3842350 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,7 @@ Flask = "^2.3.2" twilio = "^8.5.0" aiofiles = "23.1.0" gunicorn = "^21.2.0" -pinecone-client = "^2.2.2" +pinecone-client = "^4.1" streamlit-feedback = "0.0.9" boto3= "1.28.17" s3fs = "^2023.9.0" diff --git a/src/genai/streamlit_pages/dm_page.py b/src/genai/streamlit_pages/dm_page.py index a0e1433..722247e 100644 --- a/src/genai/streamlit_pages/dm_page.py +++ b/src/genai/streamlit_pages/dm_page.py @@ -12,7 +12,7 @@ from genai.utils import read_json -def eyfs_dm_kb(index_name: str = "eyfs-index", sidebar: bool = True) -> None: +def eyfs_dm_kb(index_name: str = "eyfs-index-1718673592-index", sidebar: bool = True) -> None: """Run the Development Matters app.""" # Define your custom CSS diff --git a/src/genai/streamlit_pages/eyfs_compare_page.py b/src/genai/streamlit_pages/eyfs_compare_page.py index 379c9f7..5013abc 100644 --- a/src/genai/streamlit_pages/eyfs_compare_page.py +++ b/src/genai/streamlit_pages/eyfs_compare_page.py @@ -10,7 +10,7 @@ def eyfs_compare() -> None: """Compare the EYFS prototypes.""" st.title("Compare the EYFS prototypes") - index = get_index(index_name="eyfs-index") + index = get_index(index_name="eyfs-index-1718673592-index") areas_of_learning_desc = read_json("src/genai/eyfs/areas_of_learning.json") aol = list(areas_of_learning_desc.keys()) diff --git a/src/genai/streamlit_pages/parenting_page.py b/src/genai/streamlit_pages/parenting_page.py index dbf1600..cc95f09 100644 --- a/src/genai/streamlit_pages/parenting_page.py +++ b/src/genai/streamlit_pages/parenting_page.py @@ -53,7 +53,7 @@ def parenting_chatbot(aws_key: str, aws_secret: str, s3_path: str, sidebar: bool selected_model = "gpt-3.5-turbo" temperature = 0.6 - pinecone_index = get_index(index_name="eyfs-index") + pinecone_index = get_index(index_name="eyfs-index-1718673592-index") if sidebar: with st.sidebar: diff --git a/src/genai/streamlit_pages/utils.py b/src/genai/streamlit_pages/utils.py index 4043fe3..c3d67b0 100644 --- a/src/genai/streamlit_pages/utils.py +++ b/src/genai/streamlit_pages/utils.py @@ -5,12 +5,16 @@ from typing import Optional from typing import Union +import dotenv import pinecone import streamlit as st from genai.vector_index import PineconeIndex +dotenv.load_dotenv() + + def reset_state(key: Optional[str] = None) -> None: """Delete the message placeholder state.""" keys = [ diff --git a/src/genai/vector_index.py b/src/genai/vector_index.py index 2067f01..d5a09b5 100644 --- a/src/genai/vector_index.py +++ b/src/genai/vector_index.py @@ -3,7 +3,8 @@ from typing import Optional -import pinecone +# import pinecone +from pinecone import Pinecone from genai.utils import batch @@ -23,24 +24,16 @@ def __init__( """Initialize the index.""" # Connect to pinecone - if api_key and environment: - pinecone.init( - api_key=api_key, - environment=environment, - ) + if api_key: + self.pc = Pinecone(api_key=api_key) else: - pinecone.init( - api_key=os.environ["PINECONE_API_KEY"], - environment=os.environ["PINECONE_REGION"], - ) + self.pc = Pinecone(api_key=os.environ["PINECONE_API_KEY"]) - def connect(self, index_name: str) -> pinecone.index.Index: + def connect(self, index_name: str) -> Pinecone.Index: """Connect to the index.""" - if index_name not in pinecone.list_indexes(): - raise ValueError(f"Index {index_name} does not exist.") - - return pinecone.Index(index_name) + return self.pc.Index(index_name) + # To do: update for the new Pinecone API def build_and_upsert( self, index_name: str, @@ -81,10 +74,10 @@ def build_and_upsert( if delete_if_exists: self.delete(index_name) - if index_name in pinecone.list_indexes(): + if index_name in pinecone.list_indexes(): # noqa: F821 index = self.connect(index_name) else: - pinecone.create_index( + pinecone.create_index( # noqa: F821 index_name, dimension=dimension, metadata_config=metadata_config, @@ -103,6 +96,6 @@ def build_and_upsert( def delete(index_name: str) -> None: """Delete the index.""" try: - pinecone.delete_index(index_name) + pinecone.delete_index(index_name) # noqa: F821 except Exception as e: print(e) # noqa: T001