feat: add durable success-first modelhub agent

This commit is contained in:
CoolBoy
2026-08-15 19:24:26 +08:00
parent 91d1d3d87d
commit 4260793c03
22 changed files with 2420 additions and 86 deletions

View File

@@ -42,6 +42,7 @@ TASK_SPECS: tuple[TaskSpec, ...] = (
TASK_SPEC_BY_TYPE = {task.task_type: task for task in TASK_SPECS}
DYNAMIC_TASK_TYPES: list[str] = []
TASK_TYPE_BY_MODEL_TASK_LEVEL_ID = {
@@ -91,7 +92,55 @@ def task_type_from_history_task(task: dict) -> str | None:
def all_task_types() -> list[str]:
return [task.task_type for task in TASK_SPECS]
return [task.task_type for task in TASK_SPECS] + list(DYNAMIC_TASK_TYPES)
def register_dynamic_task_types(task_types: list[str]) -> list[str]:
"""Register API task identifiers that can be sourced by the same ModelScope tag."""
added: list[str] = []
next_priority = max(spec.priority for spec in TASK_SPEC_BY_TYPE.values()) + 10
for raw in task_types:
task_type = str(raw or "").strip()
if not task_type or task_type in TASK_SPEC_BY_TYPE:
continue
if any(not (character.isascii() and (character.isalnum() or character in "_-")) for character in task_type):
continue
TASK_SPEC_BY_TYPE[task_type] = TaskSpec(
task_type=task_type,
modality="generic",
pipeline_tags=(task_type,),
priority=next_priority,
)
next_priority += 10
DYNAMIC_TASK_TYPES.append(task_type)
added.append(task_type)
return added
def register_dynamic_task_route(task_type: str, pipeline_tag: str) -> None:
task_type = str(task_type or "").strip()
pipeline_tag = str(pipeline_tag or "").strip().lower()
if not task_type or not pipeline_tag:
return
existing = TASK_SPEC_BY_TYPE.get(task_type)
if existing is not None:
if pipeline_tag not in existing.pipeline_tags:
TASK_SPEC_BY_TYPE[task_type] = TaskSpec(
task_type=existing.task_type,
modality=existing.modality,
pipeline_tags=(*existing.pipeline_tags, pipeline_tag),
priority=existing.priority,
)
return
register_dynamic_task_types([task_type])
created = TASK_SPEC_BY_TYPE.get(task_type)
if created is not None:
TASK_SPEC_BY_TYPE[task_type] = TaskSpec(
task_type=created.task_type,
modality=created.modality,
pipeline_tags=(pipeline_tag,),
priority=created.priority,
)
def pipeline_tags_for_task_types(task_types: list[str]) -> list[str]:
@@ -106,7 +155,7 @@ def pipeline_tags_for_task_types(task_types: list[str]) -> list[str]:
def task_specs_for_model(model: HFModelSummary) -> list[TaskSpec]:
pipeline_tag = (model.pipeline_tag or "").strip().lower()
return [task for task in TASK_SPECS if pipeline_tag in task.pipeline_tags]
return [task for task in TASK_SPEC_BY_TYPE.values() if pipeline_tag in task.pipeline_tags]
def compatible_text_generation_frameworks(
@@ -170,6 +219,9 @@ def compatible_frameworks_for_task(
return ["diffusers"]
raise ValueError(f"No compatible diffusers template found for {target_gpu}")
if inspection.has_standard_weights and supported_frameworks:
return sorted(supported_frameworks)
raise ValueError(f"Unsupported task type for auto framework selection: {task_type}")