diff --git a/CHANGELOG.md b/CHANGELOG.md index d0b162a..af076f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.0.58 + +- Split large style consensus requests into grouped multi-image analysis plus a compact final merge to reduce provider timeouts. + ## 1.0.57 - Make the persisted plugin-data selection authoritative for the dedicated cross-analysis route. diff --git a/backend/services/advanced_style_set_service.py b/backend/services/advanced_style_set_service.py index c284e9d..74503e0 100644 --- a/backend/services/advanced_style_set_service.py +++ b/backend/services/advanced_style_set_service.py @@ -1427,40 +1427,151 @@ class AdvancedStyleSetService: ) if provider is None: raise ApiError(ErrorCode.MODEL_CAPABILITY_UNCONFIRMED, "advanced style consensus route is unavailable", {"route_name": route_name}) - request = VisionRecognitionRequest( - display_name=f"{record.display_name} / cross-image style consensus", - image_uri=image_urls[0], - image_uris=tuple(image_urls[1:]), - prompt=json.dumps( - { - "source_reports": source_reports, - "image_manifest": image_manifest, - "previous_validation": comparison_payload, - "automatic_review_feedback": automatic_review_feedback, - "style_adjustment_plan": style_adjustment_plan, - "human_style_feedback": style_adjustment, - }, - ensure_ascii=False, - ), - metadata={ - "recognition_instruction": _consensus_instruction( - source_ids=[item.source_id for item in sources], - style_adjustment=style_adjustment, - style_adjustment_plan=style_adjustment_plan, - validation_instruction=_optional_text(consensus.metadata.get("validation_instruction")), - has_previous_validation=bool(previous_cases), - ), - "style_set": True, - "consensus_id": consensus_id, - "comparison_attempt_id": comparison_attempt_id, - "comparison_consensus_id": comparison_consensus_id, - "image_manifest": image_manifest, - "style_adjustment_plan": style_adjustment_plan, - "automatic_review_feedback": automatic_review_feedback, - }, - ) + analysis_strategy = "single_pass" try: - recognition = provider.recognize_material(request) + if len(sources) <= 4 or previous_cases: + request = VisionRecognitionRequest( + display_name=f"{record.display_name} / cross-image style consensus", + image_uri=image_urls[0], + image_uris=tuple(image_urls[1:]), + prompt=json.dumps( + { + "source_reports": source_reports, + "image_manifest": image_manifest, + "previous_validation": comparison_payload, + "automatic_review_feedback": automatic_review_feedback, + "style_adjustment_plan": style_adjustment_plan, + "human_style_feedback": style_adjustment, + }, + ensure_ascii=False, + ), + metadata={ + "recognition_instruction": _consensus_instruction( + source_ids=[item.source_id for item in sources], + style_adjustment=style_adjustment, + style_adjustment_plan=style_adjustment_plan, + validation_instruction=_optional_text(consensus.metadata.get("validation_instruction")), + has_previous_validation=bool(previous_cases), + ), + "style_set": True, + "consensus_id": consensus_id, + "comparison_attempt_id": comparison_attempt_id, + "comparison_consensus_id": comparison_consensus_id, + "image_manifest": image_manifest, + "style_adjustment_plan": style_adjustment_plan, + "automatic_review_feedback": automatic_review_feedback, + }, + ) + recognition = provider.recognize_material(request) + else: + analysis_strategy = "grouped_two_stage" + groups = [sources[index:index + 4] for index in range(0, len(sources), 4)] + partial_analyses: list[dict[str, Any]] = [] + for group_index, group in enumerate(groups): + group_reports = [item for item in source_reports if item["source_id"] in {source.source_id for source in group}] + group_urls = [ + _storage_image_data_url(source.source_image_uri, {}, self.storage)[0] + for source in group + ] + partial_request = VisionRecognitionRequest( + display_name=f"{record.display_name} / style consensus group {group_index + 1}", + image_uri=group_urls[0], + image_uris=tuple(group_urls[1:]), + prompt=json.dumps( + { + "analysis_mode": "partial_style_consensus", + "source_reports": group_reports, + "source_ids": [source.source_id for source in group], + }, + ensure_ascii=False, + ), + metadata={ + "recognition_instruction": _consensus_instruction( + source_ids=[source.source_id for source in group], + style_adjustment=style_adjustment, + style_adjustment_plan=style_adjustment_plan, + validation_instruction=None, + has_previous_validation=False, + ), + "style_set": True, + "consensus_id": consensus_id, + "analysis_mode": "partial_style_consensus", + }, + ) + partial = provider.recognize_material(partial_request) + structured = partial.structured_data if isinstance(partial.structured_data, dict) else {} + partial_analyses.append( + { + "group_index": group_index, + "source_ids": [source.source_id for source in group], + "prompt": partial.prompt, + "negative_prompt": partial.negative_prompt, + "tags": partial.tags, + "confidence": partial.confidence, + "description": partial.description, + "analysis": { + key: structured.get(key) + for key in ( + "consensus_style", + "artist_signature", + "variable_style_features", + "source_content_features", + "content_leakage_exclusions", + "feature_evidence", + "generation_capsules", + "prompt_priority_groups", + "scale_capsules", + "semantic_risk_audit", + ) + if key in structured + }, + } + ) + + representative_sources = [group[0] for group in groups[:2]] + final_urls = [ + _storage_image_data_url(source.source_image_uri, {}, self.storage)[0] + for source in representative_sources + ] + image_manifest = [ + { + "image_index": index, + "kind": "representative_source_reference", + "source_id": source.source_id, + "image_uri": source.source_image_uri, + } + for index, source in enumerate(representative_sources) + ] + request = VisionRecognitionRequest( + display_name=f"{record.display_name} / final style consensus", + image_uri=final_urls[0], + image_uris=tuple(final_urls[1:]), + prompt=json.dumps( + { + "analysis_mode": "final_style_consensus", + "source_ids": [source.source_id for source in sources], + "partial_analyses": partial_analyses, + "style_adjustment_plan": style_adjustment_plan, + "human_style_feedback": style_adjustment, + }, + ensure_ascii=False, + ), + metadata={ + "recognition_instruction": _consensus_instruction( + source_ids=[item.source_id for item in sources], + style_adjustment=style_adjustment, + style_adjustment_plan=style_adjustment_plan, + validation_instruction=_optional_text(consensus.metadata.get("validation_instruction")), + has_previous_validation=False, + ), + "style_set": True, + "consensus_id": consensus_id, + "analysis_mode": "final_style_consensus", + "image_manifest": image_manifest, + "style_adjustment_plan": style_adjustment_plan, + }, + ) + recognition = provider.recognize_material(request) except VisionProviderError as exc: raise ApiError(ErrorCode.GENERATION_FAILED, "advanced style cross-image analysis failed", _vision_provider_error(exc)) from None try: @@ -1526,6 +1637,7 @@ class AdvancedStyleSetService: }, "comparison_context": comparison_payload, "automatic_review_feedback": automatic_review_feedback, + "analysis_strategy": analysis_strategy, "image_manifest": image_manifest, "effective_style_prompt": effective_prompt, "effective_style_negative_prompt": effective_negative_prompt, diff --git a/config.yaml b/config.yaml index 66c10a0..0be878b 100644 --- a/config.yaml +++ b/config.yaml @@ -1,7 +1,7 @@ plugin: name: astrbot_plugin_imagestudio display_name: ImageStudio - version: 1.0.57 + version: 1.0.58 features: quick_profile: true diff --git a/core/config_service.py b/core/config_service.py index 2609dcf..94d2759 100644 --- a/core/config_service.py +++ b/core/config_service.py @@ -10,7 +10,7 @@ from core.runtime_paths import resolve_config_path from database.db_helper import load_config_payload -PLUGIN_VERSION = "1.0.57" +PLUGIN_VERSION = "1.0.58" @dataclass(frozen=True) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 2bc3d99..c438439 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -1,12 +1,12 @@ { "name": "astrbot-plugin-imagestudio-frontend", - "version": "1.0.57", + "version": "1.0.58", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "astrbot-plugin-imagestudio-frontend", - "version": "1.0.57", + "version": "1.0.58", "dependencies": { "@vitejs/plugin-vue": "^5.2.0", "pinia": "^2.3.0", diff --git a/frontend/package.json b/frontend/package.json index c317361..d50bcb5 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "astrbot-plugin-imagestudio-frontend", - "version": "1.0.57", + "version": "1.0.58", "private": true, "type": "module", "scripts": { diff --git a/metadata.yaml b/metadata.yaml index d3cda9b..ccbc9ed 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -2,7 +2,7 @@ name: astrbot_plugin_imagestudio display_name: ImageStudio desc: AstrBot >=4.25 ImageStudio role asset and image-generation workspace for Windows, Linux, macOS and Docker. short_desc: AstrBot 鍐呯殑瑙掕壊璧勪骇銆佸伐浣滄祦涓庡浘鐗囩敓鎴愮鐞嗗伐浣滃彴銆? -version: 1.0.57 +version: 1.0.58 author: YokiiroBW repo: "http://192.168.31.210:18085/YokiiroBW/astrbot_plugin_imagestudio" astrbot_version: ">=4.25.0,<5" diff --git a/tests/test_advanced_style_set_workflow.py b/tests/test_advanced_style_set_workflow.py index 7c081a0..87fa38f 100644 --- a/tests/test_advanced_style_set_workflow.py +++ b/tests/test_advanced_style_set_workflow.py @@ -123,7 +123,11 @@ class _StyleVisionProvider: structured_data=_style_structures(prompt), ) - reports = json.loads(str(request.prompt or "{}"))["source_reports"] + payload = json.loads(str(request.prompt or "{}")) + reports = payload.get("source_reports") or [ + {"source_id": source_id} + for source_id in payload.get("source_ids", []) + ] source_ids = [str(item["source_id"]) for item in reports] instruction = str(request.metadata.get("recognition_instruction") or "") adjustment = "cooler shadows" if "cooler shadows" in instruction else "" @@ -554,6 +558,23 @@ class AdvancedStyleSetWorkflowTests(unittest.TestCase): self.assertIsNotNone(record) self.assertEqual(record.status, "awaiting_review") + def test_large_consensus_uses_grouped_two_stage_vision_requests(self) -> None: + fixture = _fixture(self.root) + _import_id, consensus = _execute_source_stage(fixture, 8) + + _execute_consensus(fixture, consensus) + + consensus_requests = fixture.vision.requests[8:] + self.assertEqual(len(consensus_requests), 3) + self.assertEqual([1 + len(item.image_uris) for item in consensus_requests], [4, 4, 2]) + self.assertEqual( + [json.loads(str(item.prompt)).get("analysis_mode") for item in consensus_requests], + ["partial_style_consensus", "partial_style_consensus", "final_style_consensus"], + ) + completed = fixture.advanced.get_style_consensus_run(consensus.consensus_id) + self.assertIsNotNone(completed) + self.assertEqual(completed.result.get("analysis_strategy"), "grouped_two_stage") + def test_style_normalization_preserves_profile_attributes_and_intact_capsule_phrases(self) -> None: service = MaterialNormalizationService() phrase = "highly glossy, sharp specular highlights on hair, skin, and eyes"