fix(plugins): support OPENAI_IMAGE_API_MODEL env var + base_url config for third-party backends - #18796
Conversation
5992c0b to
815f9f2
Compare
|
Rebased and updated this PR against the current What changed in this revision:
Local verification: This should make the PR complementary to #21273 rather than conflicting with it: #21273 forwards CI note after the latest push:
This PR's changed files remain limited to: |
815f9f2 to
8788925
Compare
|
Rebased this PR and refreshed CI. Status after the refresh:
Local verification run before pushing: uv run --with ruff ruff check plugins/image_gen/openai/__init__.py tests/plugins/image_gen/test_openai_provider.py tests/tools/test_image_generation_plugin_dispatch.py
uv run --extra dev --with pytest-xdist python -m pytest tests/plugins/image_gen/test_openai_provider.py tests/tools/test_image_generation_plugin_dispatch.py tests/gateway/test_restart_drain.py::test_restart_command_while_busy_requests_drain_without_interrupt tests/hermes_cli/test_tencent_tokenhub_provider.py::TestTencentTokenhubContextLength::test_hy3_preview_has_registered_context_length -q --tb=short -n 0The previous red checks were from the stale branch state; the fork-comment permission issue in the lint summary path is no longer present on the refreshed run. |
teknium1
left a comment
There was a problem hiding this comment.
Thanks for separating the virtual quality-tier IDs from the API model; the underlying hard-coded-model problem is still present on current main.
Problems
- Blocking: this branch predates the image-to-image refactor in
c02192ff6(#48705). The submitted change configures onlyimages.generateatplugins/image_gen/openai/__init__.py:308-329(PR head87889255b). Current main also routes image inputs throughimages.editatplugins/image_gen/openai/__init__.py:298-305, where it still usesAPI_MODEL, while its shared client at line 273 has no configuredbase_url. A salvage of the current patch would therefore leave edit requests on the hard-coded model/default endpoint.
Suggested changes
- Apply the API-model and base-URL resolution before the current text/edit branch, instantiate one configured client, and use the resolved model for both
images.generateandimages.edit. - Add an edit-path regression covering a configured API model and base URL.
Automated hermes-sweeper review.
| client_kwargs: Dict[str, Any] = {} | ||
| if base_url: | ||
| client_kwargs["base_url"] = base_url | ||
| client = openai.OpenAI(**client_kwargs) |
There was a problem hiding this comment.
Blocking for salvage onto current main: #48705 added a shared client plus an images.edit() branch after this commit's parent. Apply this configured client before that branch and use the resolved API model for images.edit too; otherwise image-edit requests still use the hard-coded model and default endpoint.
8788925 to
6f77ad9
Compare
|
@teknium1 — I rebased this PR onto current What changed:
Validation:
CI is now running on the refreshed branch. Could you take another look when it is ready? |
Split the OpenAI image plugin's virtual quality-tier IDs from the actual API model sent in images.generate requests. This keeps gpt-image-2-low/medium/high as UI/config tier selectors while allowing OpenAI-compatible backends to set the real payload model via OPENAI_IMAGE_API_MODEL, image_gen.openai.api_model, or the dispatcher-provided image_gen.model from NousResearch#21273 when it is not one of the virtual tier IDs. Also pass OPENAI_BASE_URL or image_gen.openai.base_url into openai.OpenAI(), and cover the resolver, provider.generate, and dispatcher model forwarding paths with tests. Closes: NousResearch#18793
6f77ad9 to
6502312
Compare
|
@teknium1 — follow-up refresh complete on head
This is also the prerequisite contract for the image-provider fallback work in #32320. Could you take another look when convenient? |
Problem
The OpenAI image gen plugin hardcodes
API_MODEL = "gpt-image-2"in the API request payload, making it impossible to use third-party OpenAI-compatible backends (e.g., Krill AI, OpenRouter image endpoints) that expect different model identifiers.Closes #18793
Solution
Three new escape hatches, fully backward-compatible — defaults unchanged:
API model override
OPENAI_IMAGE_API_MODELenv varimage_gen.openai.api_modelconfig keyAPI_MODEL(default:gpt-image-2)Base URL
OPENAI_BASE_URLenv var (standard SDK behaviour)image_gen.openai.base_urlconfig keyNone→ api.openai.comUsage example (Krill AI)
Or via env var:
export OPENAI_IMAGE_API_MODEL=gpt-image-2-1k-mediumChanges
_resolve_api_model()— resolves the model name for the API request_resolve_base_url()— resolves the base URL for the OpenAI clientgenerate()to use resolved values instead of hardcoded constantsNo breaking changes. Default behaviour unchanged.