Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 39 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 1 addition & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,8 @@ pillow = "^10.1.0"
cairosvg = "^2.7.1"
mkdocs-glightbox = "^0.3.4"

[[tool.poetry.source]]
name = "torch"
url = "https://download.pytorch.org/whl/cpu"
priority = "explicit"

[[tool.poetry.source]]
name = "PyPI"
priority = "primary"

[build-system]
requires = ["poetry-core"]
Expand All @@ -123,4 +117,4 @@ include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
ensure_newline_before_comments = true
line_length = 88
line_length = 88
45 changes: 8 additions & 37 deletions tests/unit_tests/test_llm_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,6 @@

from .mocks import MockAsyncOpenAILlm, MockOpenAILlm

# def test_openai_callable_retries_on_retryable_errors(mocker):
# llm = MockCustomLlm()
# fail_retryable_spy = mocker.spy(llm, "fail_retryable")
#
# arbitrary_callable = ArbitraryCallable(llm.fail_retryable, prompt="Hello")
# response = arbitrary_callable()
#
# assert fail_retryable_spy.call_count == 2
# assert isinstance(response, LLMResponse) is True
# assert response.output == "Hello world!"
# assert response.prompt_token_count is None
# assert response.response_token_count is None


@pytest.mark.skipif(not OPENAI_VERSION.startswith("0"), reason="OpenAI v0 only")
def test_openai_callable_does_not_retry_on_non_retryable_errors(mocker):
Expand Down Expand Up @@ -65,22 +52,6 @@ def test_openai_callable_does_not_retry_on_success(mocker):
assert response.response_token_count is None


# @pytest.mark.asyncio
# async def test_async_openai_callable_retries_on_retryable_errors(mocker):
# llm = MockAsyncCustomLlm()
# fail_retryable_spy = mocker.spy(llm, "fail_retryable")
#
# arbitrary_callable = AsyncArbitraryCallable(llm.fail_retryable, prompt="Hello")
# response = await arbitrary_callable()
#
# assert fail_retryable_spy.call_count == 2
# assert isinstance(response, LLMResponse) is True
# assert response.output == "Hello world!"
# assert response.prompt_token_count is None
# assert response.response_token_count is None


# Passing
@pytest.mark.skipif(not OPENAI_VERSION.startswith("0"), reason="OpenAI v0 only")
@pytest.mark.asyncio
async def test_async_openai_callable_does_not_retry_on_non_retryable_errors(mocker):
Expand Down Expand Up @@ -664,19 +635,19 @@ def test_get_llm_ask_cohere():


@pytest.mark.skipif(
not importlib.util.find_spec("anthropic.resources"),
reason="antrhopic is not installed",
not importlib.util.find_spec("anthropic"),
reason="anthropic is not installed",
)
def test_get_llm_ask_anthropic():
from anthropic import Anthropic

from guardrails.llm_providers import AnthropicCallable
if importlib.util.find_spec("anthropic"):
from anthropic import Anthropic

anthropic_client = Anthropic(api_key="my_api_key")
from guardrails.llm_providers import AnthropicCallable

prompt_callable = get_llm_ask(anthropic_client.completions.create)
anthropic_client = Anthropic(api_key="my_api_key")
prompt_callable = get_llm_ask(anthropic_client.completions.create)

assert isinstance(prompt_callable, AnthropicCallable)
assert isinstance(prompt_callable, AnthropicCallable)


@pytest.mark.skipif(
Expand Down