Skip to content

Better handling of Sagemaker models #11410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Jacobh2
Copy link
Contributor

@Jacobh2 Jacobh2 commented Jun 4, 2025

Dynamic key for request body and handle response being embeddings directly

First stab at fixing #11019 as well as better handling of the response format from Sagemaker.

This makes it possible to dynamically select what the key should be for the request body for embedding models. It defaults to the existing value for backwards compatability.

Also handles the response a bit better by allowing the embeddings to be directly the response (which it is for some models e.g. the https://huggingface.co/nomic-ai/nomic-embed-text-v1 one) and not only a dict with a key.

Not included yet: This only handles the LiteLLM cli part, but for myself I'd like this to be supported to set on a per-model basis in the proxy as well. Any hints on how to do this would be highly appreciated!

Relevant issues

#11019

Type

🆕 New Feature
🐛 Bug Fix

Copy link

vercel bot commented Jun 4, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
litellm ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 5, 2025 6:13am

if isinstance(response, list):
embeddings = response
elif isinstance(response, dict):
embeddings = response["embedding"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if 'embedding' does not exist - can we raise a helpful error (maybe with the dict keys received) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure! How about this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also still the verbose print just above, which will log the entire response which can also help during debugging 🎉

@Jacobh2
Copy link
Contributor Author

Jacobh2 commented Jun 4, 2025

Trying to understand the router logic, and if I have understood it correctly, maybe the litellm_params in the config.yaml file of LiteLLM Proxy already is provided as extra input? Meaning I just have to add it there:

model_list:
  - litellm_params:
      sagemaker_input_key: inputs
      ...

Is that correctly understood?

@krrishdholakia
Copy link
Contributor

Yes that's right @Jacobh2

@Jacobh2
Copy link
Contributor Author

Jacobh2 commented Jun 4, 2025

Tested this with the nomic-ai/nomic-embed-text-v1 model and with the custom key for input and support for handling the embeddings directly as a list I now properly get an embedding result 🎉

EmbeddingResponse(
    model="my-test-endpoint",
    data=[{"object": "embedding", "index": 0, "embedding": [-0.005336614, ..., -0.019391568]}],
    object="list",
    usage=Usage(
        completion_tokens=0, prompt_tokens=4, total_tokens=4, completion_tokens_details=None, prompt_tokens_details=None
    ),
)

@Jacobh2 Jacobh2 requested a review from krrishdholakia June 4, 2025 19:52
@Jacobh2
Copy link
Contributor Author

Jacobh2 commented Jun 7, 2025

@krrishdholakia anything you'd like to change, or could we take this in?

@krrishdholakia
Copy link
Contributor

@Jacobh2 Can you please add a unit test under test_litellm/

This will prevent future regressions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants