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

Update dataclasses.replace calls in DefaultRetryStrategy #112

Merged
merged 8 commits into from
Sep 5, 2024
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ packages=["spice"]

[project]
name = "spiceai"
version = "0.4.2"
version = "0.4.3"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good job on bumping the version number. This is important for releasing the bug fix.

license = {text = "Apache-2.0"}
description = "A Python library for building AI-powered applications."
readme = "README.md"
Expand Down
5 changes: 2 additions & 3 deletions spice/retry_strategy/default_strategy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import dataclasses
from typing import Any, Callable, Optional

from spice.call_args import SpiceCallArgs
Expand All @@ -17,9 +16,9 @@ def decide(
self, call_args: SpiceCallArgs, attempt_number: int, model_output: str, name: str
) -> tuple[Behavior, SpiceCallArgs, Any, str]:
if attempt_number == 1 and call_args.temperature is not None:
call_args = dataclasses.replace(call_args, temperature=max(0.2, call_args.temperature))
call_args = call_args.model_copy(update={"temperature": max(0.2, call_args.temperature)})
elif attempt_number > 1 and call_args.temperature is not None:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
call_args = call_args.model_copy(update={"temperature": max(0.2, call_args.temperature)})
call_args = call_args.model_copy(update={"temperature": max(0.2, call_args.temperature or 0)})

It's a good practice to provide a default value when using or with None. This ensures that max() always receives two numeric values, even if call_args.temperature is None.

call_args = dataclasses.replace(call_args, temperature=max(0.5, call_args.temperature))
call_args = call_args.model_copy(update={"temperature": max(0.5, call_args.temperature)})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
call_args = call_args.model_copy(update={"temperature": max(0.5, call_args.temperature)})
call_args = call_args.model_copy(update={"temperature": max(0.5, call_args.temperature or 0)})

Similar to the previous comment, it's safer to provide a default value when call_args.temperature might be None.

if self.validator and not self.validator(model_output):
if attempt_number < self.retries:
Expand Down
Loading