forked from langchain-ai/langchain
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Masking of API Key for GooseAI LLM (langchain-ai#12496)
Description: Add masking of API Key for GooseAI LLM when printed. Issue: langchain-ai#12165 Dependencies: None Tag maintainer: @eyurtsev --------- Co-authored-by: Samad Koita <>
- Loading branch information
1 parent
c17403a
commit b508271
Showing
2 changed files
with
46 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"""Test GooseAI""" | ||
|
||
import pytest | ||
from pytest import MonkeyPatch | ||
|
||
from langchain.llms.gooseai import GooseAI | ||
from langchain.pydantic_v1 import SecretStr | ||
|
||
|
||
@pytest.mark.requires("openai") | ||
def test_api_key_is_secret_string() -> None: | ||
llm = GooseAI(gooseai_api_key="secret-api-key") | ||
assert isinstance(llm.gooseai_api_key, SecretStr) | ||
assert llm.gooseai_api_key.get_secret_value() == "secret-api-key" | ||
|
||
|
||
@pytest.mark.requires("openai") | ||
def test_api_key_masked_when_passed_via_constructor() -> None: | ||
llm = GooseAI(gooseai_api_key="secret-api-key") | ||
assert str(llm.gooseai_api_key) == "**********" | ||
assert "secret-api-key" not in repr(llm.gooseai_api_key) | ||
assert "secret-api-key" not in repr(llm) | ||
|
||
|
||
@pytest.mark.requires("openai") | ||
def test_api_key_masked_when_passed_from_env() -> None: | ||
with MonkeyPatch.context() as mp: | ||
mp.setenv("GOOSEAI_API_KEY", "secret-api-key") | ||
llm = GooseAI() | ||
assert str(llm.gooseai_api_key) == "**********" | ||
assert "secret-api-key" not in repr(llm.gooseai_api_key) | ||
assert "secret-api-key" not in repr(llm) |