From 8658d1c121b7335873f61a327cb717ded8cff0e2 Mon Sep 17 00:00:00 2001 From: zhonghanjun Date: Tue, 2 Jan 2024 17:17:24 +0800 Subject: [PATCH] fix: revert ut->it, since qianfan need be installed. for lint --- .../chat_models/test_qianfan_endpoint.py | 60 +++++++++++++++++++ .../chat_models/test_qianfan_endpoint.py | 53 ---------------- 2 files changed, 60 insertions(+), 53 deletions(-) delete mode 100644 libs/community/tests/unit_tests/chat_models/test_qianfan_endpoint.py diff --git a/libs/community/tests/integration_tests/chat_models/test_qianfan_endpoint.py b/libs/community/tests/integration_tests/chat_models/test_qianfan_endpoint.py index ddd4fe6189603..caa5ef20eb4cc 100644 --- a/libs/community/tests/integration_tests/chat_models/test_qianfan_endpoint.py +++ b/libs/community/tests/integration_tests/chat_models/test_qianfan_endpoint.py @@ -293,3 +293,63 @@ def test_functions_call() -> None: chain = prompt | chat.bind(functions=_FUNCTIONS) resp = chain.invoke({}) assert isinstance(resp, AIMessage) + + +def test_rate_limit() -> None: + chat = QianfanChatEndpoint(model="ERNIE-Bot", init_kwargs={"query_per_second": 2}) + assert chat.client._client._rate_limiter._sync_limiter._query_per_second == 2 + responses = chat.batch( + [ + [HumanMessage(content="Hello")], + [HumanMessage(content="who are you")], + [HumanMessage(content="what is baidu")], + ] + ) + for res in responses: + assert isinstance(res, BaseMessage) + assert isinstance(res.content, str) + + +def test_qianfan_key_masked_when_passed_from_env( + monkeypatch: MonkeyPatch, capsys: CaptureFixture +) -> None: + """Test initialization with an API key provided via an env variable""" + monkeypatch.setenv("QIANFAN_AK", "test-api-key") + monkeypatch.setenv("QIANFAN_SK", "test-secret-key") + + chat = QianfanChatEndpoint() + print(chat.qianfan_ak, end="") + captured = capsys.readouterr() + assert captured.out == "**********" + + print(chat.qianfan_sk, end="") + captured = capsys.readouterr() + assert captured.out == "**********" + + +def test_qianfan_key_masked_when_passed_via_constructor( + capsys: CaptureFixture, +) -> None: + """Test initialization with an API key provided via the initializer""" + chat = QianfanChatEndpoint( + qianfan_ak="test-api-key", + qianfan_sk="test-secret-key", + ) + print(chat.qianfan_ak, end="") + captured = capsys.readouterr() + assert captured.out == "**********" + + print(chat.qianfan_sk, end="") + captured = capsys.readouterr() + + assert captured.out == "**********" + + +def test_uses_actual_secret_value_from_secret_str() -> None: + """Test that actual secret is retrieved using `.get_secret_value()`.""" + chat = QianfanChatEndpoint( + qianfan_ak="test-api-key", + qianfan_sk="test-secret-key", + ) + assert cast(SecretStr, chat.qianfan_ak).get_secret_value() == "test-api-key" + assert cast(SecretStr, chat.qianfan_sk).get_secret_value() == "test-secret-key" diff --git a/libs/community/tests/unit_tests/chat_models/test_qianfan_endpoint.py b/libs/community/tests/unit_tests/chat_models/test_qianfan_endpoint.py deleted file mode 100644 index 5a74411e3a88a..0000000000000 --- a/libs/community/tests/unit_tests/chat_models/test_qianfan_endpoint.py +++ /dev/null @@ -1,53 +0,0 @@ -from typing import cast - -from langchain_core.pydantic_v1 import SecretStr -from pytest import CaptureFixture, MonkeyPatch - -from langchain_community.chat_models.baidu_qianfan_endpoint import ( - QianfanChatEndpoint, -) - - -def test_qianfan_key_masked_when_passed_from_env( - monkeypatch: MonkeyPatch, capsys: CaptureFixture -) -> None: - """Test initialization with an API key provided via an env variable""" - monkeypatch.setenv("QIANFAN_AK", "test-api-key") - monkeypatch.setenv("QIANFAN_SK", "test-secret-key") - - chat = QianfanChatEndpoint() - print(chat.qianfan_ak, end="") - captured = capsys.readouterr() - assert captured.out == "**********" - - print(chat.qianfan_sk, end="") - captured = capsys.readouterr() - assert captured.out == "**********" - - -def test_qianfan_key_masked_when_passed_via_constructor( - capsys: CaptureFixture, -) -> None: - """Test initialization with an API key provided via the initializer""" - chat = QianfanChatEndpoint( - qianfan_ak="test-api-key", - qianfan_sk="test-secret-key", - ) - print(chat.qianfan_ak, end="") - captured = capsys.readouterr() - assert captured.out == "**********" - - print(chat.qianfan_sk, end="") - captured = capsys.readouterr() - - assert captured.out == "**********" - - -def test_uses_actual_secret_value_from_secret_str() -> None: - """Test that actual secret is retrieved using `.get_secret_value()`.""" - chat = QianfanChatEndpoint( - qianfan_ak="test-api-key", - qianfan_sk="test-secret-key", - ) - assert cast(SecretStr, chat.qianfan_ak).get_secret_value() == "test-api-key" - assert cast(SecretStr, chat.qianfan_sk).get_secret_value() == "test-secret-key" \ No newline at end of file