|
2 | 2 | # pylint: disable=too-few-public-methods
|
3 | 3 | """Sales Support Model (hsr) for the LangChain project."""
|
4 | 4 |
|
5 |
| -import os |
6 | 5 | import re
|
7 | 6 |
|
8 |
| -from dotenv import find_dotenv, load_dotenv |
9 |
| - |
10 |
| - |
11 |
| -class ConfigurationError(Exception): |
12 |
| - """Exception raised for errors in the configuration.""" |
13 |
| - |
14 |
| - def __init__(self, message): |
15 |
| - self.message = message |
16 |
| - super().__init__(self.message) |
17 |
| - |
18 |
| - |
19 |
| -# pylint: disable=duplicate-code |
20 |
| -dotenv_path = find_dotenv() |
21 |
| -if os.path.exists(dotenv_path): |
22 |
| - load_dotenv(dotenv_path=dotenv_path, verbose=True) |
23 |
| - OPENAI_API_KEY = os.environ["OPENAI_API_KEY"] |
24 |
| - OPENAI_API_ORGANIZATION = os.environ["OPENAI_API_ORGANIZATION"] |
25 |
| - PINECONE_API_KEY = os.environ["PINECONE_API_KEY"] |
26 |
| - PINECONE_ENVIRONMENT = os.environ["PINECONE_ENVIRONMENT"] |
27 |
| - PINECONE_INDEX_NAME = os.environ.get("PINECONE_INDEX_NAME", "hsr") |
28 |
| - PINECONE_VECTORSTORE_TEXT_KEY = os.environ.get("PINECONE_VECTORSTORE_TEXT_KEY", "lc_id") |
29 |
| - PINECONE_METRIC = os.environ.get("PINECONE_METRIC", "dotproduct") |
30 |
| - PINECONE_DIMENSIONS = int(os.environ.get("PINECONE_DIMENSIONS", 1536)) |
31 |
| - OPENAI_CHAT_MODEL_NAME = os.environ.get("OPENAI_CHAT_MODEL_NAME", "gpt-3.5-turbo") |
32 |
| - OPENAI_PROMPT_MODEL_NAME = os.environ.get("OPENAI_PROMPT_MODEL_NAME", "text-davinci-003") |
33 |
| - OPENAI_CHAT_TEMPERATURE = float(os.environ.get("OPENAI_CHAT_TEMPERATURE", 0.0)) |
34 |
| - OPENAI_CHAT_MAX_RETRIES = int(os.environ.get("OPENAI_CHAT_MAX_RETRIES", 3)) |
35 |
| - OPENAI_CHAT_CACHE = bool(os.environ.get("OPENAI_CHAT_CACHE", True)) |
36 |
| - DEBUG_MODE = os.environ.get("DEBUG_MODE", "False") == "True" |
37 |
| - |
38 |
| - if not re.match(r"^sk-\w+$", OPENAI_API_KEY): |
39 |
| - raise ConfigurationError("OPENAI_API_KEY is not set. Please add your OpenAI API key to the .env file.") |
40 |
| - if not re.match(r"^org-\w+$", OPENAI_API_ORGANIZATION): |
41 |
| - raise ConfigurationError( |
42 |
| - "OPENAI_API_ORGANIZATION is not set. Please add your OpenAI API organization to the .env file." |
43 |
| - ) |
44 |
| - if not re.match(r"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$", PINECONE_API_KEY): |
45 |
| - raise ConfigurationError("PINECONE_API_KEY is not set. Please add your Pinecone API key to the .env file.") |
46 |
| - |
47 |
| -else: |
48 |
| - raise FileNotFoundError("No .env file found in root directory of repository") |
| 7 | +from decouple import config |
| 8 | + |
| 9 | +from models.exceptions import ConfigurationError |
| 10 | + |
| 11 | + |
| 12 | +OPENAI_API_KEY = config("OPENAI_API_KEY") |
| 13 | +OPENAI_API_ORGANIZATION = config("OPENAI_API_ORGANIZATION") |
| 14 | +PINECONE_API_KEY = config("PINECONE_API_KEY") |
| 15 | +PINECONE_ENVIRONMENT = config("PINECONE_ENVIRONMENT") |
| 16 | +PINECONE_INDEX_NAME = config("PINECONE_INDEX_NAME", default="rag") |
| 17 | +PINECONE_VECTORSTORE_TEXT_KEY = config("PINECONE_VECTORSTORE_TEXT_KEY", default="lc_id") |
| 18 | +PINECONE_METRIC = config("PINECONE_METRIC", default="dotproduct") |
| 19 | +PINECONE_DIMENSIONS = config("PINECONE_DIMENSIONS", default=1536, cast=int) |
| 20 | +OPENAI_CHAT_MODEL_NAME = config("OPENAI_CHAT_MODEL_NAME", default="gpt-3.5-turbo") |
| 21 | +OPENAI_PROMPT_MODEL_NAME = config("OPENAI_PROMPT_MODEL_NAME", default="text-davinci-003") |
| 22 | +OPENAI_CHAT_TEMPERATURE = config("OPENAI_CHAT_TEMPERATURE", default=0.0, cast=float) |
| 23 | +OPENAI_CHAT_MAX_RETRIES = config("OPENAI_CHAT_MAX_RETRIES", default=3, cast=int) |
| 24 | +OPENAI_CHAT_CACHE = config("OPENAI_CHAT_CACHE", default=True, cast=bool) |
| 25 | +DEBUG_MODE = config("DEBUG_MODE", default=False, cast=bool) |
| 26 | + |
| 27 | +if not re.match(r"^sk-\w+$", OPENAI_API_KEY): |
| 28 | + raise ConfigurationError("OPENAI_API_KEY is not set. Please add your OpenAI API key to the .env file.") |
| 29 | +if not re.match(r"^org-\w+$", OPENAI_API_ORGANIZATION): |
| 30 | + raise ConfigurationError( |
| 31 | + "OPENAI_API_ORGANIZATION is not set. Please add your OpenAI API organization to the .env file." |
| 32 | + ) |
| 33 | +if not re.match(r"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$", PINECONE_API_KEY): |
| 34 | + raise ConfigurationError("PINECONE_API_KEY is not set. Please add your Pinecone API key to the .env file.") |
49 | 35 |
|
50 | 36 |
|
51 | 37 | class ReadOnly(type):
|
|
0 commit comments