Skip to content

Commit 1c9699d

Browse files
committed
chore: validate OPENAI_API_KEY and PINECONE_API_KEY
1 parent ddb9cc9 commit 1c9699d

File tree

3 files changed

+19
-51
lines changed

3 files changed

+19
-51
lines changed

models/const.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
from dotenv import find_dotenv, load_dotenv
88

99

10+
class ConfigurationError(Exception):
11+
"""Exception raised for errors in the configuration."""
12+
13+
def __init__(self, message):
14+
self.message = message
15+
super().__init__(self.message)
16+
17+
1018
# pylint: disable=duplicate-code
1119
dotenv_path = find_dotenv()
1220
if os.path.exists(dotenv_path):
@@ -25,6 +33,16 @@
2533
OPENAI_CHAT_MAX_RETRIES = int(os.environ.get("OPENAI_CHAT_MAX_RETRIES", 3))
2634
OPENAI_CHAT_CACHE = bool(os.environ.get("OPENAI_CHAT_CACHE", True))
2735
DEBUG_MODE = os.environ.get("DEBUG_MODE", "False") == "True"
36+
37+
if OPENAI_API_KEY == "PLEASE-ADD-ME":
38+
raise ConfigurationError("OPENAI_API_KEY is not set. Please add your OpenAI API key to the .env file.")
39+
if OPENAI_API_ORGANIZATION == "PLEASE-ADD-ME":
40+
raise ConfigurationError(
41+
"OPENAI_API_ORGANIZATION is not set. Please add your OpenAI API organization to the .env file."
42+
)
43+
if PINECONE_API_KEY == "PLEASE-ADD-ME":
44+
raise ConfigurationError("PINECONE_API_KEY is not set. Please add your Pinecone API key to the .env file.")
45+
2846
else:
2947
raise FileNotFoundError("No .env file found in root directory of repository")
3048

models/tests/test_hsr.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
"""
66
import pytest # pylint: disable=unused-import
77
from langchain.chat_models import ChatOpenAI
8-
from langchain.embeddings import OpenAIEmbeddings
98

10-
from models.hybrid_search_retreiver import HybridSearchRetriever, TextSplitter
9+
from models.hybrid_search_retreiver import HybridSearchRetriever
1110
from models.pinecone import PineConeIndex
1211

1312

@@ -29,5 +28,3 @@ def test_02_class_aatribute_types(self):
2928
hsr = HybridSearchRetriever()
3029
assert isinstance(hsr.chat, ChatOpenAI)
3130
assert isinstance(hsr.pinecone, PineConeIndex)
32-
assert isinstance(hsr.text_splitter, TextSplitter)
33-
assert isinstance(hsr.openai_embeddings, OpenAIEmbeddings)

models/tests/test_pinecone_lc.py

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)