From 49e9f08cf5bb0ffe28c9487d0095dcc6a8c500e0 Mon Sep 17 00:00:00 2001 From: henri123lemoine Date: Tue, 27 Jun 2023 07:34:14 -0400 Subject: [PATCH] Removed magic number 3 by using a settings const --- src/dataset/settings.py | 5 ++++- src/dataset/update_dataset.py | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/dataset/settings.py b/src/dataset/settings.py index dcd4c91..063f22d 100644 --- a/src/dataset/settings.py +++ b/src/dataset/settings.py @@ -18,4 +18,7 @@ EMBEDDINGS_RATE_LIMIT = 3500 PINECONE_INDEX_NAME = "stampy-chat-embeddings-test" PINECONE_VALUES_DIMS = EMBEDDINGS_DIMS PINECONE_METRIC = "cosine" -PINECONE_METADATA_ENTRIES = ["entry_id", "source", "title", "authors", "text"] \ No newline at end of file +PINECONE_METADATA_ENTRIES = ["entry_id", "source", "title", "authors", "text"] + +### MISCELLANEOUS ### +MAX_NUM_AUTHORS_IN_SIGNATURE = 3 \ No newline at end of file diff --git a/src/dataset/update_dataset.py b/src/dataset/update_dataset.py index 580c509..5761cc2 100644 --- a/src/dataset/update_dataset.py +++ b/src/dataset/update_dataset.py @@ -10,7 +10,7 @@ from .text_splitter import TokenSplitter from .sql_db_handler import SQLDB from .pinecone_db_handler import PineconeDB -from .settings import EMBEDDINGS_MODEL, EMBEDDINGS_DIMS, EMBEDDINGS_RATE_LIMIT, ARD_DATASET_NAME +from .settings import EMBEDDINGS_MODEL, EMBEDDINGS_DIMS, EMBEDDINGS_RATE_LIMIT, ARD_DATASET_NAME, MAX_NUM_AUTHORS_IN_SIGNATURE import logging logger = logging.getLogger(__name__) @@ -114,6 +114,6 @@ def get_authors_str(authors_lst: List[str]) -> str: if authors_lst == []: return 'n/a' if len(authors_lst) == 1: return authors_lst[0] else: - authors_lst = authors_lst[:3] - authors_str = ", ".join(authors_lst[:-1]) + " and " + authors_lst[-1] + authors_lst = authors_lst[:MAX_NUM_AUTHORS_IN_SIGNATURE] + authors_str = f"{', '.join(authors_lst[:-1])} and {authors_lst[-1]}" return authors_str \ No newline at end of file