From f0bdbe6075abe3cce18ed9ce98ba12aff7f231cb Mon Sep 17 00:00:00 2001 From: Vasilisa Parshikova Date: Mon, 9 Mar 2026 18:41:00 +0400 Subject: [PATCH] (sap) Align embedding request transformation with current API --- docs/my-website/docs/providers/sap.md | 16 +++++++++---- litellm/llms/sap/embed/transformation.py | 24 +++++++++++++++---- .../embed/test_sap_embed_transformation.py | 4 +++- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/docs/my-website/docs/providers/sap.md b/docs/my-website/docs/providers/sap.md index eee8c98e33e..11f240adbdd 100644 --- a/docs/my-website/docs/providers/sap.md +++ b/docs/my-website/docs/providers/sap.md @@ -595,7 +595,7 @@ For more information about all available translation configurations, see the [do The data masking module serves to anonymize or pseudonymize personally identifiable information from the input for selected entities. ```python showLineNumbers title="Data Masking Example" -from litellm import completion +from litellm import completion, embedding masking_config = { 'providers': [ @@ -620,9 +620,19 @@ response = completion(model="sap/gpt-4o", placeholder_values={"cv": mock_cv}, masking=masking_config) print(response.choices[0].message.content) + +###Data masking module also available for embedding +response = embedding(model="sap/text-embedding-3-small", + input=mock_cv, + masking=masking_config) +print(response.data[0]) ``` For more information about all available data masking configurations, see the [documentation](https://help.sap.com/docs/sap-ai-core/generative-ai/enhancing-model-consumption-with-data-masking-66ad6f469afc4c2cbaa91a27a33f7b21?locale=en-US) + + + + #### Content Filtering The content filtering module allows you to filter input and output based on content safety criteria. @@ -680,7 +690,7 @@ except Exception as e: ``` For more information about all available content filtering configurations, see the [documentation](https://help.sap.com/docs/sap-ai-core/generative-ai/content-filtering?locale=en-US) -#### List of moduls configuration for fallback +#### List of modules configuration for fallback SAP GEN AI Hub supports a fallback mechanism for handling errors. This mechanism allows you to specify a list of fallback modules to use in case of errors. The fallback modules should contain all parameters that are required for configuring the request. Required parameters: @@ -700,8 +710,6 @@ Optional parameters: ```python showLineNumbers title="Fallback Example" from litellm import completion -from litellm import completion - translation_config = { 'input': {'type': 'sap_document_translation', diff --git a/litellm/llms/sap/embed/transformation.py b/litellm/llms/sap/embed/transformation.py index 0bbf4f259f7..d8697e2b9d6 100644 --- a/litellm/llms/sap/embed/transformation.py +++ b/litellm/llms/sap/embed/transformation.py @@ -5,6 +5,7 @@ Translates from OpenAI's `/v1/embeddings` to IBM's `/text/embeddings` route. from typing import Optional, List, Dict, Literal, Union from pydantic import BaseModel, Field from functools import cached_property +from litellm.llms.sap.chat.models import MaskingModuleConfig import httpx @@ -48,24 +49,31 @@ class EmbeddingModel(BaseModel): name: str version: str = "latest" params: dict = Field(default_factory=dict, validation_alias="parameters") + timeout: Optional[int] = Field(default=600, ge=1, le=600) + max_retries: Optional[int] = Field(default=2, ge=0, le=5) +class EmbeddingsModelConfig(BaseModel): + model: EmbeddingModel class EmbeddingsModules(BaseModel): - embeddings: EmbeddingModel + embeddings: EmbeddingsModelConfig + masking: Optional[MaskingModuleConfig] = None class EmbeddingInput(BaseModel): text: Union[str, List[str]] type: Literal["text", "document", "query"] = "text" +class EmbeddingComfig(BaseModel): + modules: EmbeddingsModules class EmbeddingRequest(BaseModel): - config: EmbeddingsModules + config: EmbeddingComfig input: EmbeddingInput def validate_dict(data: dict, model) -> dict: - return model(**data).model_dump() + return model(**data).model_dump(exclude_none=True, by_alias=True) class GenAIHubEmbeddingConfig(BaseEmbeddingConfig): @@ -153,14 +161,20 @@ class GenAIHubEmbeddingConfig(BaseEmbeddingConfig): model_dict["version"] = optional_params.get("version", "latest") model_dict["params"] = optional_params.get("parameters", {}) input_dict = {"text": input} + if optional_params.get("type"): + input_dict["type"] = optional_params.get("type") + masking = {"masking": optional_params.get("masking")} if optional_params.get("masking") else {} body = { "config": { "modules": { - "embeddings": {"model": validate_dict(model_dict, EmbeddingModel)} + "embeddings": {"model": model_dict}, + **masking } }, - "input": validate_dict(input_dict, EmbeddingInput), + "input": input_dict, } + body = validate_dict(body, EmbeddingRequest) + return body def transform_embedding_response( diff --git a/tests/test_litellm/llms/sap/embed/test_sap_embed_transformation.py b/tests/test_litellm/llms/sap/embed/test_sap_embed_transformation.py index dfb56d8c3c7..511828bf10a 100644 --- a/tests/test_litellm/llms/sap/embed/test_sap_embed_transformation.py +++ b/tests/test_litellm/llms/sap/embed/test_sap_embed_transformation.py @@ -21,7 +21,9 @@ def test_basic_config_transform(fake_token_creator, fake_deployment_url): 'model': { 'name': 'text-embedding-3-small', 'version': 'latest', - 'params': {} + 'params': {}, + 'timeout': 600, + 'max_retries': 2 } } }