community: fix AttributeError: 'YandexGPT' object has no attribute '_grpc_metadata' (#24432)

Fixes #24049

---------

Co-authored-by: Erick Friis <erick@langchain.dev>
This commit is contained in:
Nikita Pakunov 2024-08-01 00:18:33 +03:00 committed by GitHub
parent 752a71b688
commit c776471ac6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 1 deletions

View File

@ -57,7 +57,7 @@ class _BaseYandexGPT(Serializable):
disable_request_logging: bool = False disable_request_logging: bool = False
"""YandexGPT API logs all request data by default. """YandexGPT API logs all request data by default.
If you provide personal data, confidential information, disable logging.""" If you provide personal data, confidential information, disable logging."""
_grpc_metadata: Sequence _grpc_metadata: Optional[Sequence] = None
@property @property
def _llm_type(self) -> str: def _llm_type(self) -> str:

View File

@ -0,0 +1,38 @@
import pytest
from langchain_community.llms.yandex import YandexGPT
def test_yandexgpt_initialization() -> None:
llm = YandexGPT(
iam_token="your_iam_token", # type: ignore[arg-type]
api_key="your_api_key", # type: ignore[arg-type]
folder_id="your_folder_id",
)
assert llm.model_name == "yandexgpt-lite"
assert llm.model_uri.startswith("gpt://your_folder_id/yandexgpt-lite/")
def test_yandexgpt_model_params() -> None:
llm = YandexGPT(
model_name="custom-model",
model_version="v1",
iam_token="your_iam_token", # type: ignore[arg-type]
api_key="your_api_key", # type: ignore[arg-type]
folder_id="your_folder_id",
)
assert llm.model_name == "custom-model"
assert llm.model_version == "v1"
assert llm.iam_token.get_secret_value() == "your_iam_token"
assert llm.model_uri == "gpt://your_folder_id/custom-model/v1"
def test_yandexgpt_invalid_model_params() -> None:
with pytest.raises(ValueError):
YandexGPT(model_uri="", iam_token="your_iam_token") # type: ignore[arg-type]
with pytest.raises(ValueError):
YandexGPT(
iam_token="", # type: ignore[arg-type]
api_key="your_api_key", # type: ignore[arg-type]
model_uri="",
)