Skip to content

Commit

Permalink
fix: revert ut->it, since qianfan need be installed. for lint
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhjz committed Jan 2, 2024
1 parent 9675739 commit 8658d1c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"

This file was deleted.

0 comments on commit 8658d1c

Please sign in to comment.