fix: use IAM roles for bedrock access#578
Conversation
|
The PR description has been updated. Please fill out the template for your PR to be reviewed. |
Merge ProtectionsYour pull request matches the following merge protections and will not be merged until they are valid. 🟢 Enforce conventional commitWonderful, this rule succeeded.Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
|
@jakelorocco you are tagged as a reviewer because I changed core.py to only call post-processing if there are no exceptions. The status quo continues to give us pain. |
|
I think that sounds good. I will review once the changes are done. We will need to make sure the finally block / telemetry stuff doesn't cause issues with this change. |
|
Looks like there's another draft PR open to more comprehensively fix the post process issue: #580 (comment). I will take a closer look tomorrow. |
|
Hey folks - thank you so much for adding support for the BedRock non-mantle endpoints through the LiteLLM backend! I'm currently working on integrating Mellea with a fork of IBM's FactReasoner. I made a couple additional (local) edits to this PR in order to get it to work for me, which include:
Let me know if these changes would be valuable to contribue back to the main Mellea repo, I'm happy to either open a PR from my own fork (which would be branched off of this PR), or wait till this PR is merged to open mine, or any other way to contribute the changes that makes sense with your workflow; I'm just trying to avoid forking on top of a fork! (the edits are all in the Once again, thank for getting the LiteLLM Bedrock backend working! |
|
@leothomas, I think all these changes sound good. I will check in with @nrfulton today and see if we can get this base PR merged so that your PRs can be opened. I can't test this myself. The |
|
Hey there! I pulled @nrfulton 's branch into my own forks and then added the edits mentioned above. Here's the branch if you want to check it out: https://github.com/leothomas/mellea/tree/bedrock_aws_access_key_id @jakelorocco I'll wait for y'all to merge this PR to open one from my branch! |
|
Also, here's the LiteLLM fork with LogProbs: https://github.com/leothomas/litellm/tree/feature/logprobs I still have to write tests and all that good stuff before opening a PR against LiteLLM |
|
I changed up the auto-selected reviewers to match the reviewers assigned to #849 . FYI @ajbozarth and @jakelorocco: TL;DR: same state as #849. This is the OG PR for that work. Switched here because maintainer commit rights were disabled for the #849 branch and there were a number of failing pre-commit hooks + a merge required to proceed. I think this is good to go if tests pass. Please give a once over since there's been a fair amount of changes since this PR was first opened. The main design decisions:
FYI, all tests pass on my local machine with |
|
Thanks for following up on this and getting it over the finish line @nrfulton - again please let me know if I can support in any way! |
| hf_model_name="openai/gpt-oss-20b", # OpenAI GPT-OSS 20B | ||
| ollama_name="gpt-oss:20b", # Ollama | ||
| bedrock_name="openai.gpt-oss-20b", | ||
| bedrock_litellm_name="bedrock/converse/openai.gpt-oss-120b-1:0", |
| def _assert_region(region: str | None) -> None: | ||
| resolved_region = ( | ||
| region | ||
| or os.environ.get("AWS_REGION_NAME") | ||
| or os.environ.get("AWS_DEFAULT_REGION") | ||
| or os.environ.get("AWS_REGION") | ||
| ) | ||
| assert resolved_region is not None, ( | ||
| "you must specify a region: pass `region` explicitly or set AWS_REGION_NAME, AWS_DEFAULT_REGION, or AWS_REGION." | ||
| ) |
There was a problem hiding this comment.
Do the OpenAI and LiteLLM SDKs check for these same env vars?
| # TODO litellm doesn't even appear to use this...? | ||
| backend._base_url = None # type: ignore |
There was a problem hiding this comment.
Can we remove this? or add a comment why setting the _base_url to None is necessary?
|
|
||
| def create_bedrock_mantle_backend( | ||
| def create_bedrock_litellm_backend( | ||
| model_id: ModelIdentifier | str, region: str | None = None, num_retries: int = 15 |
There was a problem hiding this comment.
15 seems like a high default for retries. I did a quick search and it seems like Litellm uses exponential waits. I couldn't find a number, but that seems like this might resolve in long hangs.
| # Extract top-level Ollama params that must not be forwarded into `options`. | ||
| logprobs = model_opts.pop("logprobs", None) | ||
| top_logprobs = model_opts.pop("top_logprobs", None) | ||
| MelleaLogger.get_logger().info(f"Tools for call: {tools.keys()}") |
There was a problem hiding this comment.
This should be moved back to the indented block above.
|
|
||
| m = MelleaSession( | ||
| backend=create_bedrock_mantle_backend( | ||
| backend=create_bedrock_openai_backend( |
There was a problem hiding this comment.
This should be the litellm path given the import above.
planetf1
left a comment
There was a problem hiding this comment.
A few things separate from the existing thread. Inline comments above cover a misnamed function in the troubleshooting section, a boto3 import regression for base-install users, assert-as-config-validation (which gets stripped under -O), and the missing deprecation alias.
One more that cannot be pinned inline — docs/docs/integrations/bedrock.md line 45 still has a stray prose reference to create_bedrock_mantle_backend that was not updated by the rename.
|
To try to help move this along, I pushed a commit that attempted to address the outstanding review items from @jakelorocco and @planetf1 . If we're not happy with it, I don't mind reverting either. |
jakelorocco
left a comment
There was a problem hiding this comment.
Paul's changes addressed my concerns.
2e10616 to
d541a90
Compare
| <!-- leothomas, please delete this line --> | ||
|
|
There was a problem hiding this comment.
@leothomas can you suggest a change (through the UI) to delete these two lines? the UI should now ask you to sign-off, so that should let us satisfy the bot and get this in
There was a problem hiding this comment.
Hey @psschwei let me know if that worked as expected. Thank you!
d541a90 to
3850326
Compare
|
gentle ping @leothomas |
|
Hi @psschwei! I submitted a review with the requested change to remove the line you had indicated last week, please let me know if that's what you were looking for or if I've misunderstood the ask |
|
Weird, I don't see your review @leothomas
I reached out on another medium with an idea on how to get this resolved. |
|
Oh man @psschwei that's completely my fault - I hadn't submitted the review, so it was still in a pending state. I've just submitted it - let me know if that works |
c702536 to
b7f4ea2
Compare
Adds IAM auth support to Bedrock, logprobs and retries support, boto3 auth verification, and renames create_bedrock_mantle_backend to create_bedrock_openai_backend. Includes related test and docs updates. Signed-off-by: Paul S. Schweigert <paul@paulschweigert.com> Co-authored-by: Nathan Fulton <gitcommit@nfulton.org> Signed-off-by: Nathan Fulton <gitcommit@nfulton.org> Co-authored-by: Leo Thomas <leothomas@users.noreply.github.com> Signed-off-by: Leo Thomas <leothomas@users.noreply.github.com>
Signed-off-by: Paul S. Schweigert <paul@paulschweigert.com>
Co-authored-by: Leo Thomas <leothomas@users.noreply.github.com> Signed-off-by: Paul Schweigert <paul@paulschweigert.com>
b7f4ea2 to
2f9b6f0
Compare
|
So @leothomas if you can confirm signing off, we can merge like this:
|
|
I sign off on my commits on this PR |
|
Big thanks for seeing this through @psschwei - apologies for all the complications with the PR merging process! |
no worries! thanks for your patience across this process. @jakelorocco would you mind taking one more quick look? I had to rebase to pick up some changes, which required a bit of reworking, so would be good to give it a quick once over before we merge |
There was a problem hiding this comment.
I think we missed this last time; so feel free to open a follow-up PR / issue since this PR doesn't make it worse, but the region parameter for stringify_mantle_model_ids should probably be passed here?
There was a problem hiding this comment.
was an easy fix, just did it here
| model_options: dict = {"num_retries": num_retries} | ||
| resolved_region = _resolve_region(region) | ||
| if resolved_region is not None: | ||
| model_options["aws_region_name"] = resolved_region | ||
|
|
||
| return LiteLLMBackend( | ||
| model_id=model_name, model_options=model_options, num_retries=num_retries | ||
| ) |
There was a problem hiding this comment.
num_retries is getting passed in as both a model_option and directly as a parameter. We should just choose one way of doing this. I feel like as a model_option makes sense.
Signed-off-by: Paul S. Schweigert <paul@paulschweigert.com>
Signed-off-by: Jake LoRocco <jake.lorocco@ibm.com>
jakelorocco
left a comment
There was a problem hiding this comment.
I pushed a fix to remove num_retries completely from the litellm backend. The bedrock function was already passing it as a model option after @psschwei's changes. There's no need to have the field.
|
alright, let's do this! |
7f75108




Misc PR
Type of PR
Description
Testing