feat: configurable image generation model and timeout#66
Conversation
Allow GEOAGENT_IMAGE_MODEL and GEOAGENT_IMAGE_TIMEOUT to override the defaults so QGIS settings and slower networks can steer the generate_image tool without code changes.
Embed the YouTube walkthrough in the README, the docs landing page, and the QGIS plugin guide so new users have a guided introduction.
|
🚀 Deployed on https://69f4c8c4c1ae95363f86a62d--opengeos.netlify.app |
There was a problem hiding this comment.
Pull request overview
This PR makes the generate_image tool configurable at runtime via environment variables (model + request timeout) and adds a YouTube walkthrough link to user-facing docs.
Changes:
- Add
GEOAGENT_IMAGE_MODELandGEOAGENT_IMAGE_TIMEOUTsupport ingenerate_image, including surfacing the timeout in tool outputs. - Extend image tool tests to validate timeout propagation and env-driven defaults.
- Add a YouTube walkthrough thumbnail/link to the README and docs pages.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
geoagent/tools/images.py |
Adds env-configured model selection and OpenAI client timeout handling; includes timeout in results/errors. |
tests/test_image_tools.py |
Updates existing tests for timeout passing and adds a new test for env-configured model/timeout. |
README.md |
Adds YouTube walkthrough thumbnail/link near the top. |
docs/index.md |
Adds YouTube walkthrough thumbnail/link on the docs landing page. |
docs/qgis-plugin.md |
Adds a “Video Tutorial” section with the YouTube thumbnail/link. |
Comments suppressed due to low confidence (2)
tests/test_image_tools.py:90
- This test assumes the default model selection path; if GEOAGENT_IMAGE_MODEL is set in the environment, requested_model/model assertions can change. Consider clearing GEOAGENT_IMAGE_MODEL (and GEOAGENT_IMAGE_TIMEOUT if needed) via monkeypatch.delenv to make the test hermetic.
def __init__(self, **kwargs) -> None:
self.images = _Images()
monkeypatch.setenv("OPENAI_API_KEY", "test-key")
monkeypatch.setitem(sys.modules, "openai", types.SimpleNamespace(OpenAI=_Client))
tests/test_image_tools.py:33
- These assertions depend on GEOAGENT_IMAGE_MODEL / GEOAGENT_IMAGE_TIMEOUT not being set in the outer test environment. Since generate_image now reads those env vars, explicitly clear them (monkeypatch.delenv(..., raising=False)) in this test to avoid CI/local flakiness.
calls["timeout"] = kwargs.get("timeout")
self.images = _Images()
monkeypatch.setenv("OPENAI_API_KEY", "test-key")
monkeypatch.setitem(sys.modules, "openai", types.SimpleNamespace(OpenAI=_Client))
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| try: | ||
| timeout = float(raw) | ||
| except ValueError: | ||
| return DEFAULT_IMAGE_TIMEOUT | ||
| return timeout if timeout > 0 else DEFAULT_IMAGE_TIMEOUT |
There was a problem hiding this comment.
_image_timeout() accepts any float; values like 'inf' parse successfully and would effectively disable timeouts (or may cause downstream client errors). Consider rejecting non-finite values (e.g., using math.isfinite) and falling back to DEFAULT_IMAGE_TIMEOUT.
| "error": ( | ||
| f"Image generation failed with {model} " | ||
| f"within {timeout:g}s: {exc}" | ||
| ), | ||
| "model": model, | ||
| "timeout": timeout, | ||
| } |
There was a problem hiding this comment.
The failure response includes a "timeout" field here, but other error paths in generate_image return "model" without "timeout" (e.g., when the API returns no images). Consider making the error payload schema consistent by including "timeout" on all model-related failures.
| adapters, provider configuration, and confirmation hooks for operations that | ||
| should not run silently. | ||
|
|
||
| [](https://youtu.be/5zkXQlHUsu8) |
There was a problem hiding this comment.
The linked thumbnail uses an empty alt text ("![]"); add descriptive alt text for screen readers (e.g., "Video walkthrough") to improve accessibility.
| [](https://youtu.be/5zkXQlHUsu8) | |
| [](https://youtu.be/5zkXQlHUsu8) |
| while packages contribute focused tool adapters for their own objects and | ||
| workflows. | ||
|
|
||
| [](https://youtu.be/5zkXQlHUsu8) |
There was a problem hiding this comment.
The linked thumbnail uses an empty alt text ("![]"); add descriptive alt text for screen readers (e.g., "Video walkthrough") to improve accessibility.
| [](https://youtu.be/5zkXQlHUsu8) | |
| [](https://youtu.be/5zkXQlHUsu8) |
|
|
||
| ## Video Tutorial | ||
|
|
||
| [](https://youtu.be/5zkXQlHUsu8) |
There was a problem hiding this comment.
The linked thumbnail uses an empty alt text ("![]"); add descriptive alt text for screen readers (e.g., "Video tutorial") to improve accessibility.
| [](https://youtu.be/5zkXQlHUsu8) | |
| [](https://youtu.be/5zkXQlHUsu8) |
Summary
GEOAGENT_IMAGE_MODELandGEOAGENT_IMAGE_TIMEOUTso thegenerate_imagetool can be steered without code changes, and surface the timeout in error messages and the success payload.Test plan
pre-commit run --all-filespytest tests/test_image_tools.py -q