-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add OpenRouter image generation support #3599
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
base: main
Are you sure you want to change the base?
Conversation
Replaced Generator with Iterable in several methods to improve compatibility and maintainability.
95fb961 to
cfbcb51
Compare
| ... | ||
| ``` | ||
|
|
||
| ## Image 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.
We should also make this work with builtin_tools=[ImageGenerationTool()] and document it here: https://ai.pydantic.dev/builtin-tools/#image-generation-tool
As with Google, which doesn't expose that as a tool, using that tool or BinaryImage in output_type should automatically enable the modality.
|
|
||
| settings = OpenRouterModelSettings( | ||
| openrouter_modalities=['image', 'text'], | ||
| openrouter_image_config={'aspect_ratio': '3:2'} |
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 want this to be an option on ImageGenerationTool as in #3412.
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 OK with it also being a model setting if it supports more keys than ImageGenerationTool does currently (or really: after that PR), but if this is the only field supported so far I'd prefer to leave that and the modality settings off.
If you want, you can finish that PR as we're at it to make your life here easier.
|
|
||
| async with agent.run_stream('A dog') as result: | ||
| async for output in result.stream_output(): | ||
| if isinstance(output, str): |
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 means we may never actually get to the image assertions!
Closes #3258
This PR enables using OpenRouter for image generation.
It also adds a couple of new hooks to
OpenAIChatModel._process_responseto make it easier for subclasses to implement their own logic forFilePartresponses, whichOpenAIChatModeldoesn't support.