Skip to content

OpenSenseNova/SenseNova-Skills / skills/sn-image-base

sn-image-base

Verified

Base-layer skill for the SenseNova-Skills project, providing low-level APIs for image generation, recognition (VLM), and text optimization (LLM). This skill does not preprocess inputs; it only calls backend services and returns results. This skill is not user-facing and is intended for upper-layer skills only.

FileKindSize
.gitattributesother219 B
.gitignoreother4.3 KB
README.mdmarkdown10.7 KB
README_CN.mdmarkdown10.4 KB
SKILL.mdskill md13.0 KB
references/api_spec.mdmarkdown14.0 KB
requirements.txtmanifest50 B
scripts/.python-versionother4 B
scripts/extract_json.pyscript3.6 KB
scripts/pyproject.tomlmanifest339 B
scripts/ruff.tomlconfig730 B
scripts/sn_agent_runner.pyscript25.1 KB
scripts/sn_image_base/__init__.pyscript24 B
scripts/sn_image_base/configs.pyscript12.5 KB
scripts/sn_image_base/exceptions.pyscript1.2 KB
scripts/sn_image_base/generation/__init__.pyscript358 B
scripts/sn_image_base/generation/atlas_cloud.pyscript9.6 KB
scripts/sn_image_base/generation/core/__init__.pyscript412 B
scripts/sn_image_base/generation/core/client_base.pyscript2.5 KB
scripts/sn_image_base/generation/nano_banana.pyscript11.6 KB
scripts/sn_image_base/generation/openai_image.pyscript12.3 KB
scripts/sn_image_base/generation/sensenova.pyscript19.5 KB
scripts/sn_image_base/llm/__init__.pyscript215 B
scripts/sn_image_base/llm/anthropic_adapter.pyscript5.0 KB
scripts/sn_image_base/llm/chat_completions_adapter.pyscript9.7 KB
scripts/sn_image_base/llm/llm_adapter.pyscript1.8 KB
scripts/sn_image_base/utils/__init__.pyscript0 B
scripts/sn_image_base/utils/error_utils.pyscript7.3 KB
scripts/sn_image_base/utils/httpx_client.pyscript7.0 KB
scripts/sn_image_base/vlm/__init__.pyscript100 B
scripts/sn_image_base/vlm/utils.pyscript3.0 KB
scripts/sn_image_base/vlm/vlm_adapter.pyscript2.1 KB
scripts/tests/test_atlas_cloud.pyscript6.9 KB
tests/conftest.pyscript375 B
tests/test_configs_env_fallthrough.pyscript2.8 KB

scripts/tests/test_atlas_cloud.py

View on GitHub
from __future__ import annotations

import json
import tempfile
import threading
import unittest
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from pathlib import Path

from sn_image_base.generation.atlas_cloud import (
    ATLAS_2K_SIZES,
    AtlasCloudText2ImageClient,
)

PNG = b"\x89PNG\r\n\x1a\n"


class AtlasHandler(BaseHTTPRequestHandler):
    polls = 0
    submitted: dict | None = None
    authorization: str | None = None
    download_authorization: str | None = None

    def log_message(self, _format: str, *_args: object) -> None:
        return

    def do_POST(self) -> None:
        if self.path != "/api/v1/model/generateImage":
            self.send_error(404)
            return
        length = int(self.headers.get("content-length", "0"))
        type(self).submitted = json.loads(self.rfile.read(length))
        type(self).authorization = self.headers.get("authorization")
        self._json({"code": 200, "data": {"id": "task-1", "status": "created"}})

    def do_GET(self) -> None:
        if self.path == "/api/v1/model/prediction/task-1":
            type(self).polls += 1
            if type(self).polls == 1:
                self._json({"id": "task-1", "status": "processing", "outputs": []})
            else:
                host = self.headers["host"]
                self._json(
                    {
                        "data": {
                            "id": "task-1",
                            "status": "completed",
                            "outputs": [f"http://{host}/image.png"],
                        }
                    }
                )
            return
        if self.path == "/image.png":
            type(self).download_authorization = self.headers.get("authorization")
            self.send_response(200)
            self.send_header("Content-Type", "image/png")
            self.send_header("Content-Length", str(len(PNG)))
            self.end_headers()
            self.wfile.write(PNG)
            return
        self.send_error(404)

    def _json(self, payload: dict) -> None:
        body = json.dumps(payload).encode()
        self.send_response(200)
        self.send_header("Content-Type", "application/json")
        self.send_header("Content-Length", str(len(body)))
        self.end_headers()
        self.wfile.write(body)


class AtlasCloudClientTest(unittest.IsolatedAsyncioTestCase):
    async def asyncSetUp(self) -> None:
        AtlasHandler.polls = 0
        AtlasHandler.submitted = None
        AtlasHandler.authorization = None
        AtlasHandler.download_authorization = None
        self.server = ThreadingHTTPServer(("127.0.0.1", 0), AtlasHandler)
        self.thread = threading.Thread(target=self.server.serve_forever, daemon=True)
        self.thread.start()
        host, port = self.server.server_address
        self.base_url = f"http://{host}:{port}/api/v1"

    async def asyncTearDown(self) -> None:
        self.server.shutdown()
        self.server.server_close()
        self.thread.join()

    async def test_generates_and_downloads_png(self) -> None:
        client = AtlasCloudText2ImageClient(
            api_key="test-key",
            base_url=self.base_url,
            model="bytedance/seedream-v5.0-lite",
            timeout=2,
        )
        with tempfile.TemporaryDirectory() as directory:
            output = Path(directory) / "portrait.png"
            try:
                result = await client.generate(
                    "editorial portrait",
                    image_size="2k",
                    aspect_ratio="3:4",
                    output_path=output,
                    poll_interval=0,
                )
            finally:
                await client.aclose()
            self.assertEqual(result["status"], "ok")
            self.assertEqual(result["task_id"], "task-1")
            self.assertEqual(output.read_bytes(), PNG)
        self.assertEqual(AtlasHandler.authorization, "Bearer test-key")
        self.assertIsNone(AtlasHandler.download_authorization)
        self.assertEqual(
            AtlasHandler.submitted,
            {
                "model": "bytedance/seedream-v5.0-lite",
                "prompt": "editorial portrait",
                "size": "1728*2304",
                "output_format": "png",
            },
        )
        self.assertEqual(AtlasHandler.polls, 2)

    def test_resolves_landscape_4k_size(self) -> None:
        self.assertEqual(
            AtlasCloudText2ImageClient._resolve_size("4K", "16:9"),
            "4096*2304",
        )

    def test_default_cli_size_is_an_accepted_preset(self) -> None:
        # `--image-size 2k --aspect-ratio 16:9` is the CLI default.
        self.assertEqual(
            AtlasCloudText2ImageClient._resolve_size("2K", "16:9"),
            "2848*1600",
        )

    def test_every_size_is_a_documented_seedream_v5_lite_preset(self) -> None:
        # Enum copied from the model's published schema.
        accepted = {
            "2048*2048",
            "2304*1728",
            "1728*2304",
            "2848*1600",
            "1600*2848",
            "2496*1664",
            "1664*2496",
            "3136*1344",
            "3072*3072",
            "3456*2592",
            "2592*3456",
            "4096*2304",
            "2304*4096",
            "2496*3744",
            "3744*2496",
            "4704*2016",
        }
        produced = set()
        for resolution in ("2K", "4K"):
            for aspect_ratio in ATLAS_2K_SIZES:
                produced.add(AtlasCloudText2ImageClient._resolve_size(resolution, aspect_ratio))
        self.assertTrue(produced <= accepted, produced - accepted)
        self.assertEqual(len(produced), 16)

    def test_2k_sizes_meet_atlas_minimum_pixel_count(self) -> None:
        for aspect_ratio in ATLAS_2K_SIZES:
            width, height = (
                int(value)
                for value in AtlasCloudText2ImageClient._resolve_size("2K", aspect_ratio).split("*")
            )
            self.assertGreaterEqual(width * height, 3_686_400)

    def test_rejects_aspect_ratios_without_a_preset(self) -> None:
        for aspect_ratio in ("4:5", "5:4", "9:21"):
            for resolution in ("2K", "4K"):
                with self.assertRaisesRegex(ValueError, "Invalid aspect ratio"):
                    AtlasCloudText2ImageClient._resolve_size(resolution, aspect_ratio)

    def test_rejects_invalid_aspect_ratio(self) -> None:
        with self.assertRaisesRegex(ValueError, "Invalid aspect ratio"):
            AtlasCloudText2ImageClient._resolve_size("2K", "wide")

    def test_build_payload_keeps_negative_prompt_optional(self) -> None:
        client = AtlasCloudText2ImageClient(
            api_key="test-key",
            base_url=self.base_url,
            model="model",
        )
        self.assertEqual(
            client.build_payload("prompt", "model", size="2048*2048"),
            {
                "model": "model",
                "prompt": "prompt",
                "size": "2048*2048",
                "output_format": "png",
            },
        )
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall