File tree Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change 27
27
raise FileNotFoundError ("No .env file found in root directory of repository" )
28
28
29
29
30
- class Config :
30
+ class ReadOnly (type ):
31
+ """Metaclass to make all class attributes read-only."""
32
+
33
+ def __setattr__ (cls , name , value ):
34
+ if name in cls .__dict__ :
35
+ raise TypeError (f"Cannot change a read-only attribute { name } " )
36
+ super ().__setattr__ (name , value )
37
+
38
+
39
+ class Config (metaclass = ReadOnly ):
31
40
"""Configuration parameters."""
32
41
33
42
DEBUG_MODE : bool = DEBUG_MODE
@@ -41,7 +50,7 @@ class Config:
41
50
PINECONE_VECTORSTORE_TEXT_KEY : str = PINECONE_VECTORSTORE_TEXT_KEY
42
51
43
52
44
- class Credentials :
53
+ class Credentials ( metaclass = ReadOnly ) :
45
54
"""Credentials."""
46
55
47
56
OPENAI_API_KEY = OPENAI_API_KEY
Original file line number Diff line number Diff line change 37
37
# 8.) LangChain agents
38
38
from langchain_experimental .agents .agent_toolkits .python .base import create_python_agent
39
39
40
+ from models .const import Config , Credentials
41
+
40
42
41
43
# Load environment variables from .env file in all folders
42
44
# pylint: disable=duplicate-code
45
47
load_dotenv (dotenv_path = dotenv_path , verbose = True )
46
48
OPENAI_API_KEY = os .environ ["OPENAI_API_KEY" ]
47
49
OPENAI_API_ORGANIZATION = os .environ ["OPENAI_API_ORGANIZATION" ]
48
- PINECONE_API_KEY = os .environ ["PINECONE_API_KEY" ]
49
- PINECONE_ENVIRONMENT = os .environ ["PINECONE_ENVIRONMENT" ]
50
50
else :
51
51
raise FileNotFoundError ("No .env file found in root directory of repository" )
52
52
@@ -66,7 +66,7 @@ class LangChainDev:
66
66
tool = PythonREPL (),
67
67
verbose = True ,
68
68
)
69
- pinecone .init (api_key = PINECONE_API_KEY , environment = PINECONE_ENVIRONMENT ) # minute 10:43
69
+ pinecone .init (api_key = Credentials . PINECONE_API_KEY , environment = Config . PINECONE_ENVIRONMENT ) # minute 10:43
70
70
71
71
# LLM wrappers. minute 5:46
72
72
def test_01_basic (self ):
You can’t perform that action at this time.
0 commit comments