mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-11 13:55:03 +00:00
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:
parent
16617dd239
commit
d948783a4c
@ -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 (
|
||||||
|
@ -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) == "**********"
|
||||||
|
Loading…
Reference in New Issue
Block a user