From b3f4bfda096b1424875c7ab7ba2e91a772c42758 Mon Sep 17 00:00:00 2001 From: Jeff Katz Date: Tue, 23 Apr 2024 21:06:40 +0000 Subject: [PATCH 1/3] perplexity[patch]: standardize chat init args --- .../langchain_community/chat_models/perplexity.py | 7 +++++-- .../tests/unit_tests/chat_models/test_perplexity.py | 11 ++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/libs/community/langchain_community/chat_models/perplexity.py b/libs/community/langchain_community/chat_models/perplexity.py index 23d7c9e09a665..9a6ff220e8af3 100644 --- a/libs/community/langchain_community/chat_models/perplexity.py +++ b/libs/community/langchain_community/chat_models/perplexity.py @@ -63,10 +63,13 @@ 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 071f1340dd54a..4269642321016 100644 --- a/libs/community/tests/unit_tests/chat_models/test_perplexity.py +++ b/libs/community/tests/unit_tests/chat_models/test_perplexity.py @@ -25,6 +25,11 @@ 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" From 8402800963f11b585aac6f3e0c28593c23ebcfee Mon Sep 17 00:00:00 2001 From: Jeff Katzy Date: Wed, 24 Apr 2024 17:59:19 +0000 Subject: [PATCH 2/3] format code for clarity --- .../community/langchain_community/chat_models/perplexity.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/community/langchain_community/chat_models/perplexity.py b/libs/community/langchain_community/chat_models/perplexity.py index 9a6ff220e8af3..110f4518e3ed1 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 @@ -67,9 +68,8 @@ class ChatPerplexity(BaseChatModel): """Base URL path for API requests, leave blank if not using a proxy or service emulator.""" request_timeout: Optional[Union[float, Tuple[float, float]]] = Field( - None, - alias="timeout" - ) + 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.""" From 374825fcadae4218a4a5410949ccdd74def11db6 Mon Sep 17 00:00:00 2001 From: Jeff Katzy Date: Wed, 24 Apr 2024 18:14:12 +0000 Subject: [PATCH 3/3] reformate perplexity test for clarity --- .../unit_tests/chat_models/test_perplexity.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) 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 4269642321016..1ae6cd8b5fdc8 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 @@ -26,10 +27,16 @@ def test_perplexity_initialization() -> None: # Verify that chat perplexity can be initialized using a secret key provided # as a parameter rather than an environment variable. 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) - ]: + 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"