From 5ab3f9a995504d9d953640f5646bf7752454efd9 Mon Sep 17 00:00:00 2001 From: JeffKatzy Date: Wed, 24 Apr 2024 12:26:05 -0700 Subject: [PATCH] community[patch]: standardize chat init args (#20844) Thank you for contributing to LangChain! community:perplexity[patch]: standardize init args updated pplx_api_key and request_timeout so that aliased to api_key, and timeout respectively. Added test that both continue to set the same underlying attributes. Related to [20085](https://github.com/langchain-ai/langchain/issues/20085) --------- Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com> --- .../chat_models/perplexity.py | 7 +++++-- .../unit_tests/chat_models/test_perplexity.py | 18 +++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/libs/community/langchain_community/chat_models/perplexity.py b/libs/community/langchain_community/chat_models/perplexity.py index 23d7c9e09a6..110f4518e3e 100644 --- a/libs/community/langchain_community/chat_models/perplexity.py +++ b/libs/community/langchain_community/chat_models/perplexity.py @@ -1,4 +1,5 @@ """Wrapper around Perplexity APIs.""" + from __future__ import annotations import logging @@ -63,10 +64,12 @@ class ChatPerplexity(BaseChatModel): """What sampling temperature to use.""" model_kwargs: Dict[str, Any] = Field(default_factory=dict) """Holds any model parameters valid for `create` call not explicitly specified.""" - pplx_api_key: Optional[str] = None + pplx_api_key: Optional[str] = Field(None, alias="api_key") """Base URL path for API requests, leave blank if not using a proxy or service emulator.""" - request_timeout: Optional[Union[float, Tuple[float, float]]] = None + request_timeout: Optional[Union[float, Tuple[float, float]]] = Field( + None, alias="timeout" + ) """Timeout for requests to PerplexityChat completion API. Default is 600 seconds.""" max_retries: int = 6 """Maximum number of retries to make when generating.""" diff --git a/libs/community/tests/unit_tests/chat_models/test_perplexity.py b/libs/community/tests/unit_tests/chat_models/test_perplexity.py index 071f1340dd5..1ae6cd8b5fd 100644 --- a/libs/community/tests/unit_tests/chat_models/test_perplexity.py +++ b/libs/community/tests/unit_tests/chat_models/test_perplexity.py @@ -1,4 +1,5 @@ """Test Perplexity Chat API wrapper.""" + import os import pytest @@ -25,6 +26,17 @@ def test_perplexity_initialization() -> None: """Test perplexity initialization.""" # Verify that chat perplexity can be initialized using a secret key provided # as a parameter rather than an environment variable. - ChatPerplexity( - model="test", perplexity_api_key="test", temperature=0.7, verbose=True - ) + for model in [ + ChatPerplexity( + model="test", timeout=1, api_key="test", temperature=0.7, verbose=True + ), + ChatPerplexity( + model="test", + request_timeout=1, + pplx_api_key="test", + temperature=0.7, + verbose=True, + ), + ]: + assert model.request_timeout == 1 + assert model.pplx_api_key == "test"