Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retry support to catch_and_convert_errors #90

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 9 additions & 1 deletion spice/spice.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ def __init__(
logging_dir: Optional[Path | str] = None,
logging_callback: Optional[Callable[[SpiceResponse, str, str], None]] = None,
default_temperature: Optional[float] = None,
max_retries: int = 0, # Add this line
base_delay: float = 1.0, # Add this line
max_delay: float = 32.0, # Add this line
):
"""
Creates a new Spice client.
Expand Down Expand Up @@ -268,6 +271,11 @@ def __init__(
self._default_embeddings_model = embeddings_model
self._default_temperature = default_temperature

# Initialize retry configuration parameters
self.max_retries = max_retries
self.base_delay = base_delay
self.max_delay = max_delay

# TODO: Should we validate model aliases?
self._model_aliases = model_aliases

Expand Down Expand Up @@ -451,7 +459,7 @@ async def get_response(
elif i > 1 and call_args.temperature is not None:
call_args.temperature = max(0.5, call_args.temperature)

with client.catch_and_convert_errors():
with client.catch_and_convert_errors(max_retries=self.max_retries, base_delay=self.base_delay, max_delay=self.max_delay):
if streaming_callback is not None:
stream = await client.get_chat_completion_or_stream(call_args)
stream = cast(AsyncIterator, stream)
Expand Down
1 change: 1 addition & 0 deletions spice/wrapped_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import base64
import io
import mimetypes
import time
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't add the implementation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I apologize for the oversight. I'll implement the retry logic in the catch_and_convert_errors method for the WrappedOpenAIClient and WrappedAnthropicClient classes. Thank you for catching that.

from abc import ABC, abstractmethod
from contextlib import contextmanager
from pathlib import Path
Expand Down
Loading