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

Simplify registration of error/output to status mappings #166

Merged
merged 1 commit into from
May 14, 2024

Conversation

chriso
Copy link
Contributor

@chriso chriso commented May 14, 2024

One of the responsibilities of the SDK is to categorize function outputs (return values or exceptions raised) into a Status, so that Dispatch knows a) whether to retry, and b) how to adjust the execution concurrency moving forwards.

The SDK provides two functions for registering handler functions that map base error and output (return value) classes to a Status:

register_error_type(cls: Type[Exception], handler: Callable[[Exception], Status])

register_output_type(cls: Type[Any], handler: Callable[[Any], Status])

For example usage, see https://github.com/dispatchrun/dispatch-py/blob/main/src/dispatch/integrations/openai.py

Sometimes the user simply wants to map a specific class to a specific status, and the handler function is unnecessary indirection.

This PR simplifies the interface so that users can either pass a Status directly, or (as before) a handler function that maps error/output classes to statuses. For example, the following is now accepted:

register_error_type(TimeoutError, Status.TIMEOUT)

@chriso chriso self-assigned this May 14, 2024
@chriso chriso merged commit fbec88d into main May 14, 2024
7 checks passed
@chriso chriso deleted the simplify-error-output-status-registration branch May 14, 2024 22:48
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.

2 participants