Skip to content
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

[Fix] Graceful rejection of token input for AWS Embeddings API #1685

Merged
merged 3 commits into from
Jan 30, 2024

Conversation

ishaan-jaff
Copy link
Contributor

@ishaan-jaff ishaan-jaff commented Jan 30, 2024

Bedrock Embeddings API for accepts only str | List[str].

Copy link

railway-app bot commented Jan 30, 2024

This PR is being deployed to Railway 🚅

litellm: ◻️ REMOVED

Copy link

vercel bot commented Jan 30, 2024

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 Jan 30, 2024 4:33pm
litellm-dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 30, 2024 4:33pm

@@ -702,6 +702,11 @@ def _embedding_func_single(
encoding=None,
logging_obj=None,
):
if type(input) != str:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rmann-nflx doing the check here as opposed to 810, because on 810 we'd have to loop through all elements in the list and assert none of them are str

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense -- much cleaner approach imho

model="amazon.titan-embed-text-v1",
input=[1],
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added your unit test to our ci/cd @rmann-nflx

Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome!

@@ -702,6 +702,11 @@ def _embedding_func_single(
encoding=None,
logging_obj=None,
):
if type(input) != str:
Copy link
Contributor

@rmann-nflx rmann-nflx Jan 30, 2024

Choose a reason for hiding this comment

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

Heads up, I think this needs to be:

if isinstance(input, str) is False:
  ...

If you inherit from str then this rejects when I think it would be valid for it to work:

Example:

class CustomStr(str):
    pass

def test_lower_str():
    x = CustomStr("x")

    assert x == "x"
    assert x != "y"

    assert type(x) != str
    assert isinstance(x, str)

This is a toy example, but I have seen stuff like this in the wild to constrain str to known patterns

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated !

@ishaan-jaff
Copy link
Contributor Author

will merge once main is stable

@ishaan-jaff ishaan-jaff merged commit 2686ec0 into main Jan 30, 2024
5 of 8 checks passed
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.

[Bug]: Graceful rejection of token input for AWS Embeddings API
2 participants