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>
This commit is contained in:
JeffKatzy 2024-04-24 12:26:05 -07:00 committed by GitHub
parent 70ae59bcfe
commit 5ab3f9a995
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 5 deletions

View File

@ -1,4 +1,5 @@
"""Wrapper around Perplexity APIs.""" """Wrapper around Perplexity APIs."""
from __future__ import annotations from __future__ import annotations
import logging import logging
@ -63,10 +64,12 @@ class ChatPerplexity(BaseChatModel):
"""What sampling temperature to use.""" """What sampling temperature to use."""
model_kwargs: Dict[str, Any] = Field(default_factory=dict) model_kwargs: Dict[str, Any] = Field(default_factory=dict)
"""Holds any model parameters valid for `create` call not explicitly specified.""" """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, """Base URL path for API requests,
leave blank if not using a proxy or service emulator.""" 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.""" """Timeout for requests to PerplexityChat completion API. Default is 600 seconds."""
max_retries: int = 6 max_retries: int = 6
"""Maximum number of retries to make when generating.""" """Maximum number of retries to make when generating."""

View File

@ -1,4 +1,5 @@
"""Test Perplexity Chat API wrapper.""" """Test Perplexity Chat API wrapper."""
import os import os
import pytest import pytest
@ -25,6 +26,17 @@ def test_perplexity_initialization() -> None:
"""Test perplexity initialization.""" """Test perplexity initialization."""
# Verify that chat perplexity can be initialized using a secret key provided # Verify that chat perplexity can be initialized using a secret key provided
# as a parameter rather than an environment variable. # as a parameter rather than an environment variable.
ChatPerplexity( for model in [
model="test", perplexity_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"