Files
agent-radar 1a3a4ccde1
Creator App Tests / PR Spam Gate (push) Skipped
Frontend Tests / PR Spam Gate (push) Skipped
NPM Format (website & console) / PR Spam Gate (push) Skipped
Pre-commit Checks / PR Spam Gate (push) Skipped
QwenPaw Creator Plugin Release / check-version (push) Canceled after 0s
QwenPaw Creator Plugin Release / upload-oss (push) Canceled after 0s
Tests / PR Spam Gate (push) Skipped
CodeQL / CodeQL (python) (push) Canceled after 0s
CodeQL / CodeQL (typescript) (push) Canceled after 0s
Creator App Tests / Creator Backend Tests (push) Canceled after 0s
Creator App Tests / Creator UI Build & Tests (push) Canceled after 0s
E2E Smoke Tests / Playwright UI Smoke (push) Canceled after 0s
Frontend Tests / Detect console changes (push) Canceled after 0s
NPM Format (website & console) / website format check (push) Canceled after 0s
NPM Format (website & console) / console format check (push) Canceled after 0s
Pre-commit Checks / Pre-commit (push) Canceled after 0s
QwenPaw Data Plugin Release / check-version (push) Canceled after 0s
Tests / Detect code changes (push) Canceled after 0s
Frontend Tests / Vitest Unit Tests (push) Canceled after 0s
Frontend Tests / Frontend Summary (push) Canceled after 0s
QwenPaw Data Plugin Release / upload-oss (push) Canceled after 0s
Tests / Maintainer Approval (push) Canceled after 0s
Tests / Unit Tests - py3.11 - macos-latest (push) Canceled after 0s
Tests / Unit Tests - py3.11 - ubuntu-latest (push) Canceled after 0s
Tests / Unit Tests - py3.13 - ubuntu-latest (push) Canceled after 0s
Tests / Unit Tests - py3.11 - windows-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - macos-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - ubuntu-latest (push) Canceled after 0s
Tests / Contract Tests - py3.13 - ubuntu-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - windows-latest (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - fallback (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p2 (push) Canceled after 0s
Tests / Coverage Report (push) Canceled after 0s
Tests / Test Summary (push) Canceled after 0s
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:01:50 +08:00

101 lines
3.1 KiB
Python

# -*- coding: utf-8 -*-
from __future__ import annotations
import asyncio
import io
from PIL import Image
from services import object_grounding
def _png_bytes(size=(100, 200), color="white") -> bytes:
output = io.BytesIO()
Image.new("RGB", size, color=color).save(output, format="PNG")
return output.getvalue()
def test_parse_object_grounding_maps_aliases_and_rejects_bad_boxes():
detections = object_grounding.parse_object_grounding(
"""```json
{"objects":[
{"label":"car","bbox_2d":[100,200,900,800]},
{"name":"cat","bounding_box":[0,0,500,1000]},
{"name":"invalid","bbox":[900,0,100,1000]},
{"name":"outside","bbox":[0,0,1001,1000]}
]}
```""",
80,
40,
)
assert [d["label"] for d in detections] == ["car", "cat"]
assert detections[0]["bbox_normalized"] == [100, 200, 900, 800]
assert detections[0]["bbox_pixel"] == [8, 8, 72, 32]
assert detections[1]["bbox_pixel"] == [0, 0, 40, 40]
def test_parse_object_grounding_supports_ref_box_fallback():
detections = object_grounding.parse_object_grounding(
"<ref>red car</ref><box>(10, 20), (500, 600)</box>",
1000,
500,
)
assert detections[0]["label"] == "red car"
assert detections[0]["bbox_pixel"] == [10, 10, 500, 300]
def test_render_object_grounding_annotation_returns_source_sized_png():
annotated = object_grounding.render_object_grounding_annotation(
_png_bytes(),
[
{
"label": "car",
"bbox_normalized": [100, 100, 900, 900],
"bbox_pixel": [10, 20, 90, 180],
},
],
)
with Image.open(io.BytesIO(annotated)) as image:
assert image.format == "PNG"
assert image.size == (100, 200)
assert image.getpixel((10, 20)) != (255, 255, 255)
def test_ground_image_objects_uses_creator_vlm_and_returns_raw_response(
tmp_path,
monkeypatch,
):
captured = {}
url = "/generated/projects/project-1/task-work/request-1/input.png"
image_path = tmp_path / "project-1/runtime/task-work/request-1/input.png"
image_path.parent.mkdir(parents=True)
image_path.write_bytes(_png_bytes())
monkeypatch.setenv("CREATOR_DATA_ROOT", str(tmp_path))
async def fake_chat_completion(content, **kwargs):
captured["content"] = content
captured["kwargs"] = kwargs
return '[{"label":"person","bbox_2d":[100,100,800,900]}]'
vm, mc = object_grounding.vlm_model, object_grounding.model_config
monkeypatch.setattr(vm, "chat_completion", fake_chat_completion)
monkeypatch.setattr(mc, "get_vlm_model_name", lambda: "qwen-test-vl")
result = asyncio.run(
object_grounding.ground_image_objects(_png_bytes(), url, "all people"),
)
assert captured["content"][0] == {
"type": "image_url",
"image_url": {"url": url},
}
assert captured["kwargs"]["temperature"] == 0.0
assert result["model"] == "qwen-test-vl"
assert result["imageSize"] == {"width": 100, "height": 200}
assert result["detections"][0]["bbox_pixel"] == [10, 20, 80, 180]
assert result["rawResponse"].startswith("[")