community[patch]: standardize init args, update for javelin sdk release. (#21980)

Related to
[20085](https://github.com/langchain-ai/langchain/issues/20085) Updated
the Javelin chat model to standardize the initialization argument. Also
fixed an existing bug, where code was initialized with incorrect call to
the JavelinClient defined in the javelin_sdk, resulting in an
initialization error. See related [Javelin
Documentation](https://docs.getjavelin.io/docs/javelin-python/quickstart).
This commit is contained in:
MSubik 2024-05-23 03:17:28 +05:30 committed by GitHub
parent 16617dd239
commit d948783a4c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 2 deletions

View File

@ -18,7 +18,7 @@ from langchain_core.outputs import (
ChatGeneration, ChatGeneration,
ChatResult, ChatResult,
) )
from langchain_core.pydantic_v1 import BaseModel, Extra, SecretStr from langchain_core.pydantic_v1 import BaseModel, Extra, Field, SecretStr
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -65,9 +65,14 @@ class ChatJavelinAIGateway(BaseChatModel):
client: Any client: Any
"""javelin client.""" """javelin client."""
javelin_api_key: Optional[SecretStr] = None javelin_api_key: Optional[SecretStr] = Field(None, alias="api_key")
"""The API key for the Javelin AI Gateway.""" """The API key for the Javelin AI Gateway."""
class Config:
"""Configuration for this pydantic object."""
allow_population_by_field_name = True
def __init__(self, **kwargs: Any): def __init__(self, **kwargs: Any):
try: try:
from javelin_sdk import ( from javelin_sdk import (

View File

@ -30,3 +30,17 @@ def test_api_key_masked_when_passed_via_constructor() -> None:
assert str(llm.javelin_api_key) == "**********" assert str(llm.javelin_api_key) == "**********"
assert "secret-api-key" not in repr(llm.javelin_api_key) assert "secret-api-key" not in repr(llm.javelin_api_key)
assert "secret-api-key" not in repr(llm) assert "secret-api-key" not in repr(llm)
@pytest.mark.requires("javelin_sdk")
def test_api_key_alias() -> None:
for model in [
ChatJavelinAIGateway(
route="<javelin-ai-gateway-chat-route>",
javelin_api_key="secret-api-key",
),
ChatJavelinAIGateway(
route="<javelin-ai-gateway-chat-route>", api_key="secret-api-key"
),
]:
assert str(model.javelin_api_key) == "**********"