mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 19:24:27 +00:00
* feat(main.py): initial commit for `/image/variations` endpoint support * refactor(base_llm/): introduce new base llm base config for image variation endpoints * refactor(openai/image_variations/transformation.py): implement openai image variation transformation handler * fix: test * feat(openai/): working openai `/image/variation` endpoint calls via sdk * feat(topaz/): topaz sync image variation call support Addresses https://github.com/BerriAI/litellm/issues/7593 ' * fix(topaz/transformation.py): fix linting errors * fix(openai/image_variations/handler.py): fix passing json data * fix(main.py): image_variation/ support async image variation route - `aimage_variation` * fix(test_get_model_info.py): fix test * fix: cleanup unused imports * feat(openai/): add async `/image/variations` endpoint support * feat(topaz/): support async `/image/variations` calls * fix: test * fix(utils.py): fix get_model_info_helper for no model info w/ provider config handles situation where model info is not known but provider config exists * test(test_router_fallbacks.py): mark flaky test * fix: fix unused imports * test: bump otel load test perf threshold - accounts for current load tests hitting same server
131 lines
3.4 KiB
Python
131 lines
3.4 KiB
Python
from abc import ABC, abstractmethod
|
|
from typing import TYPE_CHECKING, Any, List, Optional
|
|
|
|
import httpx
|
|
from aiohttp import ClientResponse
|
|
|
|
from litellm.llms.base_llm.chat.transformation import BaseConfig
|
|
from litellm.types.llms.openai import (
|
|
AllMessageValues,
|
|
OpenAIImageVariationOptionalParams,
|
|
)
|
|
from litellm.types.utils import (
|
|
FileTypes,
|
|
HttpHandlerRequestFields,
|
|
ImageResponse,
|
|
ModelResponse,
|
|
)
|
|
|
|
if TYPE_CHECKING:
|
|
from litellm.litellm_core_utils.litellm_logging import Logging as _LiteLLMLoggingObj
|
|
|
|
LiteLLMLoggingObj = _LiteLLMLoggingObj
|
|
else:
|
|
LiteLLMLoggingObj = Any
|
|
|
|
|
|
class BaseImageVariationConfig(BaseConfig, ABC):
|
|
@abstractmethod
|
|
def get_supported_openai_params(
|
|
self, model: str
|
|
) -> List[OpenAIImageVariationOptionalParams]:
|
|
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`
|
|
"""
|
|
return api_base or ""
|
|
|
|
@abstractmethod
|
|
def transform_request_image_variation(
|
|
self,
|
|
model: Optional[str],
|
|
image: FileTypes,
|
|
optional_params: dict,
|
|
headers: dict,
|
|
) -> HttpHandlerRequestFields:
|
|
pass
|
|
|
|
def validate_environment(
|
|
self,
|
|
headers: dict,
|
|
model: str,
|
|
messages: List[AllMessageValues],
|
|
optional_params: dict,
|
|
api_key: Optional[str] = None,
|
|
api_base: Optional[str] = None,
|
|
) -> dict:
|
|
return {}
|
|
|
|
@abstractmethod
|
|
async def async_transform_response_image_variation(
|
|
self,
|
|
model: Optional[str],
|
|
raw_response: ClientResponse,
|
|
model_response: ImageResponse,
|
|
logging_obj: LiteLLMLoggingObj,
|
|
request_data: dict,
|
|
image: FileTypes,
|
|
optional_params: dict,
|
|
litellm_params: dict,
|
|
encoding: Any,
|
|
api_key: Optional[str] = None,
|
|
) -> ImageResponse:
|
|
pass
|
|
|
|
@abstractmethod
|
|
def transform_response_image_variation(
|
|
self,
|
|
model: Optional[str],
|
|
raw_response: httpx.Response,
|
|
model_response: ImageResponse,
|
|
logging_obj: LiteLLMLoggingObj,
|
|
request_data: dict,
|
|
image: FileTypes,
|
|
optional_params: dict,
|
|
litellm_params: dict,
|
|
encoding: Any,
|
|
api_key: Optional[str] = None,
|
|
) -> ImageResponse:
|
|
pass
|
|
|
|
def transform_request(
|
|
self,
|
|
model: str,
|
|
messages: List[AllMessageValues],
|
|
optional_params: dict,
|
|
litellm_params: dict,
|
|
headers: dict,
|
|
) -> dict:
|
|
raise NotImplementedError(
|
|
"ImageVariationConfig implementa 'transform_request_image_variation' for image variation models"
|
|
)
|
|
|
|
def transform_response(
|
|
self,
|
|
model: str,
|
|
raw_response: httpx.Response,
|
|
model_response: ModelResponse,
|
|
logging_obj: LiteLLMLoggingObj,
|
|
request_data: dict,
|
|
messages: List[AllMessageValues],
|
|
optional_params: dict,
|
|
litellm_params: dict,
|
|
encoding: Any,
|
|
api_key: Optional[str] = None,
|
|
json_mode: Optional[bool] = None,
|
|
) -> ModelResponse:
|
|
raise NotImplementedError(
|
|
"ImageVariationConfig implements 'transform_response_image_variation' for image variation models"
|
|
)
|