-
Notifications
You must be signed in to change notification settings - Fork 15.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mask API key for Aleph Alpha LLM #12377
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you skip these tests if aleph-alpha is not installed? Most langchain dependencies are optional. Two options:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. I'll implement the first option later today. |
||
@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 == "**********" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
neat! didn't know about
CaptureFixture
!