Skip to content

Commit b5acb91

Browse files
AnasKhan0607HassanA01kristinspencfaisalt14Harshil-Patel28
authored
Mask API keys for various LLM/ChatModel Modules (#13885)
**Description:** - Added masking of the API Keys for the modules: - `langchain/chat_models/openai.py` - `langchain/llms/openai.py` - `langchain/llms/google_palm.py` - `langchain/chat_models/google_palm.py` - `langchain/llms/edenai.py` - Updated the modules to utilize `SecretStr` from pydantic to securely manage API key. - Added unit/integration tests - `langchain/chat_models/asure_openai.py` used the `open_api_key` that is derived from the `ChatOpenAI` Class and it was assuming `openai_api_key` is a str so we changed it to expect `SecretStr` instead. **Issue:** #12165 , **Dependencies:** none, **Tag maintainer:** @eyurtsev --------- Co-authored-by: HassanA01 <[email protected]> Co-authored-by: Aneeq Hassan <[email protected]> Co-authored-by: kristinspenc <[email protected]> Co-authored-by: faisalt14 <[email protected]> Co-authored-by: Harshil-Patel28 <[email protected]> Co-authored-by: kristinspenc <[email protected]> Co-authored-by: faisalt14 <[email protected]> Co-authored-by: Chester Curme <[email protected]>
1 parent f99369a commit b5acb91

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

libs/community/tests/integration_tests/llms/test_edenai.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
You'll then need to set EDENAI_API_KEY environment variable to your api key.
1010
"""
1111

12+
from langchain_core.pydantic_v1 import SecretStr
13+
1214
from langchain_community.llms import EdenAI
1315

1416

@@ -45,3 +47,13 @@ def test_edenai_call_with_old_params() -> None:
4547
assert llm.feature == "text"
4648
assert llm.subfeature == "generation"
4749
assert isinstance(output, str)
50+
51+
52+
def test_api_key_is_secret_string() -> None:
53+
llm = EdenAI(provider="openai", edenai_api_key="secret-api-key")
54+
assert isinstance(llm.edenai_api_key, SecretStr)
55+
56+
57+
def test_uses_actual_secret_value() -> None:
58+
llm = EdenAI(provider="openai", edenai_api_key="secret-api-key")
59+
assert llm.edenai_api_key.get_secret_value() == "secret-api-key"

0 commit comments

Comments
 (0)