From 6462466e020fc3a68fc80041f29812b887dc9e03 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Tue, 11 Mar 2025 15:09:42 -0700 Subject: [PATCH] add OpenAIResponsesAPIConfig --- .../llms/base_llm/responses/transformation.py | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 litellm/llms/base_llm/responses/transformation.py diff --git a/litellm/llms/base_llm/responses/transformation.py b/litellm/llms/base_llm/responses/transformation.py new file mode 100644 index 00000000000..d80deed29c0 --- /dev/null +++ b/litellm/llms/base_llm/responses/transformation.py @@ -0,0 +1,97 @@ +import types +from abc import ABC, abstractmethod +from typing import TYPE_CHECKING, Any, Optional + +from litellm.types.utils import ModelInfo + +from ..chat.transformation import BaseLLMException + +if TYPE_CHECKING: + from litellm.litellm_core_utils.litellm_logging import Logging as _LiteLLMLoggingObj + + LiteLLMLoggingObj = _LiteLLMLoggingObj +else: + LiteLLMLoggingObj = Any + + +class BaseResponsesAPIConfig(ABC): + def __init__(self): + pass + + @classmethod + def get_config(cls): + return { + k: v + for k, v in cls.__dict__.items() + if not k.startswith("__") + and not k.startswith("_abc") + and not isinstance( + v, + ( + types.FunctionType, + types.BuiltinFunctionType, + classmethod, + staticmethod, + ), + ) + and v is not None + } + + @abstractmethod + def get_supported_openai_params(self, model: str) -> list: + pass + + @abstractmethod + def map_openai_params( + self, + non_default_params: dict, + optional_params: dict, + model: str, + drop_params: bool, + ) -> dict: + pass + + @abstractmethod + def validate_environment( + self, + headers: dict, + model: str, + optional_params: dict, + api_key: Optional[str] = None, + api_base: Optional[str] = None, + ) -> dict: + pass + + def get_complete_url( + self, + api_base: Optional[str], + model: str, + optional_params: dict, + stream: Optional[bool] = None, + ) -> str: + """ + OPTIONAL + + Get the complete url for the request + + Some providers need `model` in `api_base` + """ + if api_base is None: + raise ValueError("api_base is required") + return api_base + + @abstractmethod + def transform_request( + self, + model: str, + optional_params: dict, + litellm_params: dict, + headers: dict, + ) -> dict: + pass + + @abstractmethod + def transform_response( + self, + ): + pass