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 beta retry decorator for marvin.fn #909

Merged
merged 3 commits into from
Apr 14, 2024
Merged

add beta retry decorator for marvin.fn #909

merged 3 commits into from
Apr 14, 2024

Conversation

zzstoatzz
Copy link
Collaborator

@zzstoatzz zzstoatzz commented Apr 14, 2024

adds a beta retry decorator to be used with marvin.fn that will include validation errors (as is, by default) in subsequent retries

you may also configure max_retries and a handler to parse ValidationErrors to the additional context that is actually passed back to the LLM

from typing import Annotated

import marvin
from marvin.beta.retries import retry_fn_on_validation_error
from pydantic import AfterValidator


def verify_random_number(number: int) -> int:
    if number != 37:
        raise ValueError("Everyone knows the most random number is 37!")
    return number


RandomNumber = Annotated[int, AfterValidator(verify_random_number)]


@retry_fn_on_validation_error  # shows the validation error message in subsequent retries
@marvin.fn
def get_random_number() -> RandomNumber:
    """returns a random number"""


if __name__ == "__main__":
    print(get_random_number())

@zzstoatzz zzstoatzz merged commit 4864b44 into main Apr 14, 2024
14 checks passed
@zzstoatzz zzstoatzz deleted the fn-retries branch April 14, 2024 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants