Skip to content

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
@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