Underground-Digital/Workflow-Engine
0
1from collections.abc import Mapping2 3import openai4 5from core.model_runtime.errors.invoke import (6 InvokeAuthorizationError,7 InvokeBadRequestError,8 InvokeConnectionError,9 InvokeError,10 InvokeRateLimitError,11 InvokeServerUnavailableError,12)13 14 15class _CommonFireworks:16 def _to_credential_kwargs(self, credentials: Mapping) -> dict:17 """18 Transform credentials to kwargs for model instance19 20 :param credentials:21 :return:22 """23 credentials_kwargs = {24 "api_key": credentials["fireworks_api_key"],25 "base_url": "https://api.fireworks.ai/inference/v1",26 "max_retries": 1,27 }28 29 return credentials_kwargs30 31 @property32 def _invoke_error_mapping(self) -> dict[type[InvokeError], list[type[Exception]]]:33 """34 Map model invoke error to unified error35 The key is the error type thrown to the caller36 The value is the error type thrown by the model,37 which needs to be converted into a unified error type for the caller.38 39 :return: Invoke error mapping40 """41 return {42 InvokeConnectionError: [openai.APIConnectionError, openai.APITimeoutError],43 InvokeServerUnavailableError: [openai.InternalServerError],44 InvokeRateLimitError: [openai.RateLimitError],45 InvokeAuthorizationError: [openai.AuthenticationError, openai.PermissionDeniedError],46 InvokeBadRequestError: [47 openai.BadRequestError,48 openai.NotFoundError,49 openai.UnprocessableEntityError,50 openai.APIError,51 ],52 }53 