Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)
Python
Migrate deprecated OpenAI image fallback
Abi Raja2ec3914a63d8
diff --git a/README.md b/README.mdindex ada0a63d..fb623ca8 100644--- a/README.md+++ b/README.md@@ -16,7 +16,7 @@ Supported stacks:Default AI models:- Gemini 3 Flash Preview and Gemini 3.1 Pro Preview - the best models-- GPT-5.5, GPT-5.2 Codex, and GPT-5.4 Mini+- GPT-5.5 and GPT-5.4 Mini- Claude Opus 4.6, Claude Opus 4.8- z-image-turbo (using Replicate) for image generation@@ -46,7 +46,7 @@ the best results and lets you compare multiple models per generation.| Key | Required? | What it unlocks ||-----|-----------|-----------------|-| `OPENAI_API_KEY` | One of these three | GPT code-gen variants (GPT-5.5, GPT-5.2 Codex) |+| `OPENAI_API_KEY` | One of these three | GPT code-gen variants (GPT-5.5, GPT-5.4 Mini) || `ANTHROPIC_API_KEY` | One of these three | Claude code-gen variants (Opus 4.8, Fable 5, Sonnet 4.6) || `GEMINI_API_KEY` | One of these three — **strongly recommended** | Gemini code-gen variants (3 Flash, 3.1 Pro); extracts real assets from the screenshot; required for video mode || `REPLICATE_API_KEY` | **Strongly recommended** | Image editing, background removal, and Replicate-backed image generation — without it, `edit_image` and `remove_background` are unavailable, and image generation falls back to OpenAI if configured |diff --git a/backend/agent/tools/runtime.py b/backend/agent/tools/runtime.pyindex e7483ec5..91bfd662 100644--- a/backend/agent/tools/runtime.py+++ b/backend/agent/tools/runtime.py@@ -283,7 +283,7 @@ class AgentToolRuntime:result={"error": "No API key available for image generation."},summary={"error": "Missing image generation API key"},)- model = "dalle3"+ model = "gpt_image_2"api_key = self.openai_api_keybase_url = self.openai_base_urldiff --git a/backend/image_generation/core.py b/backend/image_generation/core.pyindex 98b81e7d..86bf2f22 100644--- a/backend/image_generation/core.py+++ b/backend/image_generation/core.py@@ -1,5 +1,5 @@from image_generation.generation import (- generate_image_dalle,+ generate_image_openai,generate_image_replicate,process_tasks,)@@ -7,6 +7,6 @@ from image_generation.generation import (__all__ = ["process_tasks",- "generate_image_dalle",+ "generate_image_openai","generate_image_replicate",]diff --git a/backend/image_generation/generation.py b/backend/image_generation/generation.pyindex 1aadb6f0..3def42cc 100644--- a/backend/image_generation/generation.py+++ b/backend/image_generation/generation.py@@ -19,12 +19,12 @@ async def process_tasks(prompts: List[str],api_key: str,base_url: str | None,- model: Literal["dalle3", "flux"],+ model: Literal["gpt_image_2", "flux"],) -> List[Union[str, None]]:start_time = time.time()results: list[str | BaseException | None]- if model == "dalle3":- tasks = [generate_image_dalle(prompt, api_key, base_url) for prompt in prompts]+ if model == "gpt_image_2":+ tasks = [generate_image_openai(prompt, api_key, base_url) for prompt in prompts]results = await asyncio.gather(*tasks, return_exceptions=True)else:results = []@@ -47,14 +47,14 @@ async def process_tasks(return processed_results-async def generate_image_dalle(+async def generate_image_openai(prompt: str, api_key: str, base_url: str | None) -> Union[str, None]:client = AsyncOpenAI(api_key=api_key, base_url=base_url)res = await client.images.generate(- model="dall-e-3",- quality="standard",- style="natural",+ model="gpt-image-2",+ quality="medium",+ output_format="png",n=1,size="1024x1024",prompt=prompt,@@ -62,7 +62,12 @@ async def generate_image_dalle(await client.close()if not res.data:return None- return res.data[0].url+ image = res.data[0]+ if image.url:+ return image.url+ if image.b64_json:+ return f"data:image/png;base64,{image.b64_json}"+ return Noneasync def generate_image_replicate(prompt: str, api_key: str) -> str:diff --git a/backend/tests/test_image_generation_openai.py b/backend/tests/test_image_generation_openai.pynew file mode 100644index 00000000..57d6009a--- /dev/null+++ b/backend/tests/test_image_generation_openai.py@@ -0,0 +1,80 @@+from types import SimpleNamespace+from typing import Any++import pytest++from image_generation import generation+++class FakeImages:+ def __init__(self) -> None:+ self.kwargs: dict[str, Any] = {}++ async def generate(self, **kwargs: Any) -> Any:+ self.kwargs = kwargs+ return SimpleNamespace(+ data=[SimpleNamespace(url=None, b64_json="aW1hZ2UtYnl0ZXM=")]+ )+++class FakeOpenAIClient:+ last_client: "FakeOpenAIClient | None" = None++ def __init__(self, api_key: str, base_url: str | None) -> None:+ self.api_key = api_key+ self.base_url = base_url+ self.images = FakeImages()+ self.closed = False+ FakeOpenAIClient.last_client = self++ async def close(self) -> None:+ self.closed = True+++async def test_generate_image_openai_uses_gpt_image_2_and_returns_data_url(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ monkeypatch.setattr(generation, "AsyncOpenAI", FakeOpenAIClient)++ result = await generation.generate_image_openai(+ "a clean product hero", "sk-test", "https://proxy.example/v1"+ )++ client = FakeOpenAIClient.last_client+ assert client is not None+ assert result == "data:image/png;base64,aW1hZ2UtYnl0ZXM="+ assert client.closed is True+ assert client.api_key == "sk-test"+ assert client.base_url == "https://proxy.example/v1"+ assert client.images.kwargs == {+ "model": "gpt-image-2",+ "quality": "medium",+ "output_format": "png",+ "n": 1,+ "size": "1024x1024",+ "prompt": "a clean product hero",+ }+++async def test_generate_image_openai_preserves_url_response(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ class UrlImages(FakeImages):+ async def generate(self, **kwargs: Any) -> Any:+ self.kwargs = kwargs+ return SimpleNamespace(+ data=[SimpleNamespace(url="https://example.com/image.png", b64_json=None)]+ )++ class UrlOpenAIClient(FakeOpenAIClient):+ def __init__(self, api_key: str, base_url: str | None) -> None:+ super().__init__(api_key, base_url)+ self.images = UrlImages()++ monkeypatch.setattr(generation, "AsyncOpenAI", UrlOpenAIClient)++ result = await generation.generate_image_openai("a logo", "sk-test", None)++ assert result == "https://example.com/image.png"