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

add support for Amazon Nova Canvas model #7838

Conversation

omrishiv
Copy link
Contributor

Title

Add initial support for Amazon Nova Canvas image generation

Relevant issues

Type

🆕 New Feature

Changes

  • Adds Nova Canvas model to provider list and adds supporting transformations for Bedrock

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

Added new test TestBedrockNova
image

Signed-off-by: omrishiv <327609+omrishiv@users.noreply.github.com>
Copy link

vercel bot commented Jan 17, 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 Mar 10, 2025 3:02pm

@krrishdholakia
Copy link
Contributor

@omrishiv can you share a screenshot of it passing your testing

@omrishiv
Copy link
Contributor Author

@krrishdholakia is there not one attached to the text? If you look at the bottom you’ll see the test name and it passing.

"""
No additional OpenAI params are mapped for Nova
"""
return []
Copy link
Contributor

Choose a reason for hiding this comment

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

does amazon nova not support any openai image gen params?

if you could link me to their optional params that would help

Copy link
Contributor

Choose a reason for hiding this comment

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

imageGenerationConfig":{"cfgScale":8,"seed":42,"quality":"standard","width":1280,"height":720,"numberOfImages":3}

i see:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I’m happy to convert those to the Nova ones, I’ll update for that

"""
Map the OpenAI params to the Bedrock params

No OpenAI params are mapped for Nova, so directly return the optional_params
Copy link
Contributor

Choose a reason for hiding this comment

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

@omrishiv could you please map the params listed above.

this also needs to be be used here -

elif custom_llm_provider == "bedrock":

Signed-off-by: omrishiv <327609+omrishiv@users.noreply.github.com>
Signed-off-by: omrishiv <327609+omrishiv@users.noreply.github.com>
width, height = _size.split("x")
width, height = int(width), int(height)
number_of_images = non_default_params.get("n", 1)
quality = "premium" if non_default_params.get("quality") == "premium" else "standard"
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't it also handle the openai equivalent value - hd

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I apologize, I now understand what this is doing. Can you clarify if intend for this to only handle openAI API parameters or if it should work for both? As in, would I expect quality premium|hd is premium or if we are only handling the openAI ones

Signed-off-by: omrishiv <327609+omrishiv@users.noreply.github.com>
Signed-off-by: omrishiv <327609+omrishiv@users.noreply.github.com>
@omrishiv
Copy link
Contributor Author

I've added the rest of the image generation tasks:

  • text_image with image conditioning
  • color guided image generation
  • image variation
  • inpainting
  • outpainting
  • background removal

I'll push the changes soon

Signed-off-by: omrishiv <327609+omrishiv@users.noreply.github.com>
Signed-off-by: omrishiv <327609+omrishiv@users.noreply.github.com>
Signed-off-by: omrishiv <327609+omrishiv@users.noreply.github.com>
Signed-off-by: omrishiv <327609+omrishiv@users.noreply.github.com>
Signed-off-by: omrishiv <327609+omrishiv@users.noreply.github.com>
@omrishiv
Copy link
Contributor Author

@krrishdholakia when you have a moment, can you please take a look at this again. I added all of the image generation tasks and tests for all of them. Thank you!

@omrishiv omrishiv changed the title add initial support for Amazon Nova Canvas model add support for Amazon Nova Canvas model Jan 22, 2025
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.

overall LGTM, looks like you addressed all points in the review. Can you fix merge conflicts ? @omrishiv

cc @krrishdholakia, can you confirm this has addressed your points too ?

return {"model": "bedrock/amazon.nova-canvas-v1:0",
"n": 1,
"size": "320x320",
"imageGenerationConfig": {"cfgScale":6.5,"seed":12},
Copy link
Contributor

Choose a reason for hiding this comment

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

i'm confused these are not litellm input params. Your tests should be passing these params https://docs.litellm.ai/docs/image_generation#input-params-for-litellmimage_generation

Copy link
Contributor Author

@omrishiv omrishiv Feb 13, 2025

Choose a reason for hiding this comment

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

My understanding was that we can pass model specific parameters that can be used downstream https://github.com/BerriAI/litellm/blob/main/litellm/main.py#L3307. Happy to be corrected and address

Transform the request body for Amazon Nova Canvas model
"""
task_type = optional_params.pop("taskType")
image_generation_config = optional_params.pop("imageGenerationConfig", {})
Copy link
Contributor

Choose a reason for hiding this comment

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

this is done incorrectly, litellm standardizes to this spec here: https://docs.litellm.ai/docs/image_generation#input-params-for-litellmimage_generation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above I think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I may be confused by what's on the page image

Is this different?

Copy link
Contributor

Choose a reason for hiding this comment

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

There is no need for a new parameter - imageGenerationConfig

Any non-openai param, is passed directly though via optional_params - https://docs.litellm.ai/docs/completion/provider_specific_params

@omrishiv
Copy link
Contributor Author

I fixed the merge conflict and would be happy to address the custom parameters. Bedrock allows for multiple tasks for the Nova Canvas model so I'd like to support those however makes sense

@krrishdholakia krrishdholakia self-assigned this Feb 21, 2025
"""
Transform the request body for Amazon Nova Canvas model
"""
task_type = optional_params.pop("taskType")
Copy link
Contributor

Choose a reason for hiding this comment

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

if this is None - what is the default behaviour? I would assume it's text -> image, given this is for image_generation

return AmazonNovaCanvasColorGuidedRequest(taskType=task_type,
colorGuidedGenerationParams=color_guided_generation_params,
imageGenerationConfig=image_generation_config)
if task_type == "IMAGE_VARIATION":
Copy link
Contributor

Choose a reason for hiding this comment

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

@omrishiv this is the wrong endpoint to do image_variation on.

There is already an existing openai endpoint for this - https://platform.openai.com/docs/api-reference/images/createVariation

return AmazonNovaCanvasImageVariationRequest(taskType=task_type,
imageVariationParams=image_variation_params,
imageGenerationConfig=image_generation_config)
if task_type == "INPAINTING":
Copy link
Contributor

Choose a reason for hiding this comment

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

this is the wrong endpoint for this.

It should be on image edit - https://platform.openai.com/docs/api-reference/images/createEdit

return AmazonNovaCanvasOutpaintingRequest(taskType=task_type,
outPaintingParams=outpainting_params,
imageGenerationConfig=image_generation_config)
if task_type == "BACKGROUND_REMOVAL":
Copy link
Contributor

Choose a reason for hiding this comment

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

same for this - this should also be on image edit - https://platform.openai.com/docs/api-reference/images/createEdit

@krrishdholakia
Copy link
Contributor

Please reduce the scope of this PR to just focus on text -> image generation,

We can then address the ability to do

  • text -> video
  • image edit

on separate PR's

Signed-off-by: omrishiv <327609+omrishiv@users.noreply.github.com>
"n": 1,
"size": "320x320",
"imageGenerationConfig": {"cfgScale":6.5,"seed":12},
"taskType": "TEXT_IMAGE"}
Copy link
Contributor

Choose a reason for hiding this comment

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

does tasktype always need to be specified?

I would assume if i'm calling the image_generation endpoint, this is implicit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would you put Color Guided Image Generation into the Edit endpoint? If it's still in image_generation, the task is COLOR_GUIDED_GENERATION

"""
Transform the request body for Amazon Nova Canvas model
"""
task_type = optional_params.pop("taskType", "TEXT_IMAGE")
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @omrishiv can you handle the case where tastType is set in params and is = None

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is handled by raising the error. None is not a supported taskType. I think if it's set as a parameter, it would be appropriate to expect a valid one. What do you think?

task_type = optional_params.pop("taskType", "TEXT_IMAGE")
image_generation_config = optional_params.pop("imageGenerationConfig", {})
image_generation_config = {**image_generation_config, **optional_params}
if task_type == "TEXT_IMAGE":
Copy link
Contributor

@krrishdholakia krrishdholakia Mar 6, 2025

Choose a reason for hiding this comment

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

nit: is there a need for an if-block here? why not just check earlier on if tasktype != "TEXT_IMAGE" and raise an exception there

Reduces the amount of code inside an if-block

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This goes back to the COLOR_GUIDED_GENERATION question. I can remove it for now, but may need it back later

@krrishdholakia
Copy link
Contributor

LGTM - planning on merging this into a dev branch later today for further testing

@tierfour
Copy link

tierfour commented Mar 7, 2025

Please merge this!

@krrishdholakia krrishdholakia changed the base branch from main to litellm_dev_contributor_prs_03_10_2025_p1 March 10, 2025 15:00
…-support-for-nova-canvas
@krrishdholakia krrishdholakia merged commit 0674491 into BerriAI:litellm_dev_contributor_prs_03_10_2025_p1 Mar 10, 2025
1 of 2 checks passed
krrishdholakia added a commit that referenced this pull request Mar 12, 2025
…10_2025_p1

add support for Amazon Nova Canvas model (#7838)
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.

None yet

4 participants