-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
add support for Amazon Nova Canvas model #7838
Conversation
Signed-off-by: omrishiv <327609+omrishiv@users.noreply.github.com>
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@omrishiv can you share a screenshot of it passing your testing |
@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 [] |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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:
- n -> numberOfImages
- quality -> quality [if quality="hd" => quality="premium"]
- size -> split into width x height
https://docs.aws.amazon.com/nova/latest/userguide/image-gen-req-resp-structure.html
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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>
I've added the rest of the image generation tasks:
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>
@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! |
There was a problem hiding this 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}, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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", {}) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
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 |
""" | ||
Transform the request body for Amazon Nova Canvas model | ||
""" | ||
task_type = optional_params.pop("taskType") |
There was a problem hiding this comment.
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": |
There was a problem hiding this comment.
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": |
There was a problem hiding this comment.
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": |
There was a problem hiding this comment.
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
Please reduce the scope of this PR to just focus on text -> image generation, We can then address the ability to do
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"} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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": |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
LGTM - planning on merging this into a dev branch later today for further testing |
Please merge this! |
…-support-for-nova-canvas
0674491
into
BerriAI:litellm_dev_contributor_prs_03_10_2025_p1
…10_2025_p1 add support for Amazon Nova Canvas model (#7838)
Title
Add initial support for Amazon Nova Canvas image generation
Relevant issues
Type
🆕 New Feature
Changes
[REQUIRED] Testing - Attach a screenshot of any new tests passing locally
Added new test

TestBedrockNova