Refactor: use SecretStr for llm_rails embeddings (#15090)

This commit is contained in:
chyroc
2024-01-02 07:24:50 +08:00
committed by GitHub
parent b440f92d81
commit 32e96a471c
4 changed files with 38 additions and 11 deletions

View File

@@ -14,6 +14,7 @@ EXPECTED_ALL = [
"GradientEmbeddings",
"JinaEmbeddings",
"LlamaCppEmbeddings",
"LLMRailsEmbeddings",
"HuggingFaceHubEmbeddings",
"MlflowAIGatewayEmbeddings",
"MlflowEmbeddings",

View File

@@ -0,0 +1,21 @@
"""Test LLMRailsEmbeddings embeddings"""
from langchain_core.pydantic_v1 import SecretStr
from pytest import CaptureFixture
from langchain_community.embeddings import LLMRailsEmbeddings
def test_api_key_is_string() -> None:
llm = LLMRailsEmbeddings(api_key="secret-api-key")
assert isinstance(llm.api_key, SecretStr)
def test_api_key_masked_when_passed_via_constructor(
capsys: CaptureFixture,
) -> None:
llm = LLMRailsEmbeddings(api_key="secret-api-key")
print(llm.api_key, end="")
captured = capsys.readouterr()
assert captured.out == "**********"