-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from stealthrocket/openapi-integration
OpenAI integration
- Loading branch information
Showing
2 changed files
with
20 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import openai # type: ignore | ||
|
||
from dispatch.integrations.http import http_response_code_status | ||
from dispatch.status import Status, register_error_type | ||
|
||
|
||
def openai_error_status(error: Exception) -> Status: | ||
# See https://github.com/openai/openai-python/blob/main/src/openai/_exceptions.py | ||
match error: | ||
case openai.APITimeoutError(): | ||
return Status.TIMEOUT | ||
case openai.APIStatusError(): | ||
return http_response_code_status(error.status_code) | ||
|
||
return Status.TEMPORARY_ERROR | ||
|
||
|
||
# Register base exception. | ||
register_error_type(openai.OpenAIError, openai_error_status) |