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.
Mask API key for Aleph Alpha LLM (langchain-ai#12377)
- **Description:** Add masking of API Key for Aleph Alpha LLM when printed. - **Issue**: langchain-ai#12165 - **Dependencies:** None - **Tag maintainer:** @eyurtsev --------- Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
- Loading branch information
Showing
4 changed files
with
74 additions
and
8 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,36 @@ | ||
"""Test Aleph Alpha specific stuff.""" | ||
|
||
import pytest | ||
from pytest import CaptureFixture, MonkeyPatch | ||
|
||
from langchain.llms.aleph_alpha import AlephAlpha | ||
from langchain.pydantic_v1 import SecretStr | ||
|
||
|
||
@pytest.mark.requires("aleph_alpha_client") | ||
def test_api_key_is_secret_string() -> None: | ||
llm = AlephAlpha(aleph_alpha_api_key="secret-api-key") | ||
assert isinstance(llm.aleph_alpha_api_key, SecretStr) | ||
|
||
|
||
@pytest.mark.requires("aleph_alpha_client") | ||
def test_api_key_masked_when_passed_via_constructor( | ||
capsys: CaptureFixture, | ||
) -> None: | ||
llm = AlephAlpha(aleph_alpha_api_key="secret-api-key") | ||
print(llm.aleph_alpha_api_key, end="") | ||
captured = capsys.readouterr() | ||
|
||
assert captured.out == "**********" | ||
|
||
|
||
@pytest.mark.requires("aleph_alpha_client") | ||
def test_api_key_masked_when_passed_from_env( | ||
monkeypatch: MonkeyPatch, capsys: CaptureFixture | ||
) -> None: | ||
monkeypatch.setenv("ALEPH_ALPHA_API_KEY", "secret-api-key") | ||
llm = AlephAlpha() | ||
print(llm.aleph_alpha_api_key, end="") | ||
captured = capsys.readouterr() | ||
|
||
assert captured.out == "**********" |