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 passing top_k parameter for Bedrock Anthropic models #8131

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

Conversation

vibhavbhat
Copy link

@vibhavbhat vibhavbhat commented Jan 31, 2025

Title

Fix passing top_k parameter for Bedrock Anthropic models

Relevant issues

Fixes #7782

Type

πŸ› Bug Fix
βœ… Test

Changes

The bug arose from the fact that different bedrock models pass in the top_k parameter in different ways.

Specifically the nova model passes in the parameter through

additionalModelRequestFields = {
    "inferenceConfig": {
         "topK": 20
    }
}

and the anthropic model passes it in through

additional_model_fields = {"top_k": top_k}

This PR checks the model types and sets the parameter based on that. Right now, this is a simple if statement, but a long term fix might be to create a new class for each model, and create handling logic for supported / model-specific param within each class. This way the overall converse handler does not need to know about these specifics.

This PR also simplifies the additional_model_fields creation logic

[REQUIRED] Testing - Attach a screenshot of any new tests passing locally

If UI changes, send a screenshot/GIF of working UI fixes

Tested the top_k param for 4 different models w/ real API calls:
image

Tests still passed w/ mocks:
image

Copy link

vercel bot commented Jan 31, 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 Jan 31, 2025 7:54pm

Copy link
Contributor

@ishaan-jaff ishaan-jaff left a comment

Choose a reason for hiding this comment

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

LGTM overall, just a couple minor points of feedback

for k, v in inference_params.items():
if (
k not in supported_converse_params
and k not in supported_tool_call_params
Copy link
Contributor

Choose a reason for hiding this comment

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

is this deletion required ? I'm pretty sure we need to filter our specific guardrail params

Copy link
Author

Choose a reason for hiding this comment

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

I just wanted to simplify the code a bit (using list comprehension instead of adding and then popping from the dict). From my understanding the before and after logic should be functionally equivalent, but if I'm wrong, I can revert it

"bedrock/mistral.mistral-7b-instruct-v0:2",
]
)
def test_bedrock_top_k(model):
Copy link
Contributor

Choose a reason for hiding this comment

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

can you send a screenshot of this test working for all the API calls here ?

Copy link
Contributor

Choose a reason for hiding this comment

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

i think he did

Copy link
Author

Choose a reason for hiding this comment

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

Yeah I have it added it in the description, let me know if you need more screenshots

top_k=2,
client=client
)
except Exception as e:
Copy link

@spacesphere spacesphere Jan 31, 2025

Choose a reason for hiding this comment

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

why do you catch exceptions in the test and just print it?

Copy link
Contributor

Choose a reason for hiding this comment

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

it's a mock call - the test is checking for the input. the mock call isn't returning a response, so for the mock test the translation output error is expected

@krrishdholakia
Copy link
Contributor

Is this okay to merge? @ishaan-jaff

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]: Cannot pass provider-specific parameters to Bedrock Anthropic models
4 participants