Skip to content

Commit

Permalink
Add test for the new changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lazyhope committed May 29, 2024
1 parent 583eb47 commit dc467dd
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/llm/test_openai/test_retries.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,32 @@ def test_upper_case_tenacity(model, mode, client):
max_retries=retries,
)
assert response.name == "JASON"


@pytest.mark.parametrize("model, mode", product(models, modes))
def test_custom_retry_response_error(model, mode, client):
client = instructor.patch(client, mode=mode)
client.api_key = "incorrect_key"

from openai import AuthenticationError
from instructor.exceptions import InstructorRetryException
from tenacity import Retrying, retry_if_not_exception_type, stop_after_attempt

retries = Retrying(
retry=retry_if_not_exception_type(ZeroDivisionError), stop=stop_after_attempt(1)
)
try:
client.chat.completions.create(
model=model,
max_retries=retries,
messages=[
{
"role": "user",
"content": "Jason is 25 years old",
}
],
response_model=UserDetail,
)
except InstructorRetryException as e:
assert isinstance(e.__cause__.__cause__, AuthenticationError)
assert e.last_completion is None

0 comments on commit dc467dd

Please sign in to comment.