2023-02-14 05:20:19 +00:00
|
|
|
"""Test Petals API wrapper."""
|
|
|
|
|
2023-12-26 20:57:37 +00:00
|
|
|
from langchain_core.pydantic_v1 import SecretStr
|
|
|
|
from pytest import CaptureFixture
|
|
|
|
|
2023-12-11 21:53:30 +00:00
|
|
|
from langchain_community.llms.petals import Petals
|
2023-02-14 05:20:19 +00:00
|
|
|
|
|
|
|
|
2023-12-26 20:57:37 +00:00
|
|
|
def test_api_key_is_string() -> None:
|
2024-05-13 18:55:07 +00:00
|
|
|
llm = Petals(huggingface_api_key="secret-api-key") # type: ignore[arg-type, call-arg]
|
2023-12-26 20:57:37 +00:00
|
|
|
assert isinstance(llm.huggingface_api_key, SecretStr)
|
|
|
|
|
|
|
|
|
|
|
|
def test_api_key_masked_when_passed_via_constructor(
|
|
|
|
capsys: CaptureFixture,
|
|
|
|
) -> None:
|
2024-05-13 18:55:07 +00:00
|
|
|
llm = Petals(huggingface_api_key="secret-api-key") # type: ignore[arg-type, call-arg]
|
2024-02-10 00:13:30 +00:00
|
|
|
print(llm.huggingface_api_key, end="") # noqa: T201
|
2023-12-26 20:57:37 +00:00
|
|
|
captured = capsys.readouterr()
|
|
|
|
|
|
|
|
assert captured.out == "**********"
|
|
|
|
|
|
|
|
|
2023-02-14 05:20:19 +00:00
|
|
|
def test_gooseai_call() -> None:
|
|
|
|
"""Test valid call to gooseai."""
|
2024-05-13 18:55:07 +00:00
|
|
|
llm = Petals(max_new_tokens=10) # type: ignore[call-arg]
|
2024-04-24 23:39:23 +00:00
|
|
|
output = llm.invoke("Say foo:")
|
2023-02-14 05:20:19 +00:00
|
|
|
assert isinstance(output, str)
|