mirror of
https://github.com/hwchase17/langchain.git
synced 2025-05-03 14:18:03 +00:00
Signed-off-by: ChengZi <chen.zhang@zilliz.com> Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com> Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com> Co-authored-by: Dan O'Donovan <dan.odonovan@gmail.com> Co-authored-by: Tom Daniel Grande <tomdgrande@gmail.com> Co-authored-by: Grande <Tom.Daniel.Grande@statsbygg.no> Co-authored-by: Bagatur <baskaryan@gmail.com> Co-authored-by: ccurme <chester.curme@gmail.com> Co-authored-by: Harrison Chase <hw.chase.17@gmail.com> Co-authored-by: Tomaz Bratanic <bratanic.tomaz@gmail.com> Co-authored-by: ZhangShenao <15201440436@163.com> Co-authored-by: Friso H. Kingma <fhkingma@gmail.com> Co-authored-by: ChengZi <chen.zhang@zilliz.com> Co-authored-by: Nuno Campos <nuno@langchain.dev> Co-authored-by: Morgante Pell <morgantep@google.com>
47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
"""Test GooseAI"""
|
|
|
|
import pytest
|
|
from pydantic import SecretStr
|
|
from pytest import MonkeyPatch
|
|
|
|
from langchain_community.llms.gooseai import GooseAI
|
|
from langchain_community.utils.openai import is_openai_v1
|
|
|
|
|
|
def _openai_v1_installed() -> bool:
|
|
try:
|
|
return is_openai_v1()
|
|
except Exception as _:
|
|
return False
|
|
|
|
|
|
@pytest.mark.requires("openai")
|
|
def test_api_key_is_secret_string() -> None:
|
|
llm = GooseAI(gooseai_api_key="secret-api-key") # type: ignore[arg-type, call-arg]
|
|
assert isinstance(llm.gooseai_api_key, SecretStr)
|
|
assert llm.gooseai_api_key.get_secret_value() == "secret-api-key"
|
|
|
|
|
|
@pytest.mark.skipif(
|
|
_openai_v1_installed(), reason="GooseAI currently only works with openai<1"
|
|
)
|
|
@pytest.mark.requires("openai")
|
|
def test_api_key_masked_when_passed_via_constructor() -> None:
|
|
llm = GooseAI(gooseai_api_key="secret-api-key") # type: ignore[arg-type, call-arg]
|
|
assert str(llm.gooseai_api_key) == "**********"
|
|
assert "secret-api-key" not in repr(llm.gooseai_api_key)
|
|
assert "secret-api-key" not in repr(llm)
|
|
|
|
|
|
@pytest.mark.skipif(
|
|
_openai_v1_installed(), reason="GooseAI currently only works with openai<1"
|
|
)
|
|
@pytest.mark.requires("openai")
|
|
def test_api_key_masked_when_passed_from_env() -> None:
|
|
with MonkeyPatch.context() as mp:
|
|
mp.setenv("GOOSEAI_API_KEY", "secret-api-key")
|
|
llm = GooseAI() # type: ignore[call-arg]
|
|
assert str(llm.gooseai_api_key) == "**********"
|
|
assert "secret-api-key" not in repr(llm.gooseai_api_key)
|
|
assert "secret-api-key" not in repr(llm)
|