Implement AI Host functionality with model caching and job management

- Added ai_host.py to handle AI tasks with FastAPI integration.
- Introduced HostState and ModelCache classes for managing client connections and model loading.
- Implemented job submission and cancellation endpoints in the AI host.
- Enhanced tests for AI host functionality, including client tracking and job cancellation.
- Updated existing tests to accommodate changes in the operator and command structure.
- Refactored runtime commands to use request-based architecture instead of command-line arguments.
- Improved model loading logic to handle CUDA memory management and reuse models efficiently.
This commit is contained in:
2026-08-04 07:35:40 +08:00
parent d694980da7
commit 838af0ee96
16 changed files with 2112 additions and 225 deletions

View File

@@ -1,5 +1,6 @@
import bpy
from . import runtime
from .image_depth import (
ApplyRemovedBackground,
BuildDepthPlane,
@@ -10,11 +11,18 @@ from .image_depth import (
)
from .operators import (
CancelJob,
ControlHost,
RunJob,
cancel_active_job,
close_active_job,
)
from .panel import DebugPanel, RuntimeModelsPanel
from .panel import (
Ben2DebugPanel,
Da3DebugPanel,
DebugPanel,
HostPanel,
ModelsPanel,
)
from .preferences import SnapFormPreferences
from .properties import SnapFormSettings
from .status_bar import draw_status_bar
@@ -25,13 +33,17 @@ CLASSES = (
SnapFormSettings,
RunJob,
CancelJob,
ControlHost,
ApplyRemovedBackground,
RemoveImageBackground,
BuildDepthPlane,
BuildOriginalDepthPlane,
ConvertImageToDepthPlane,
RuntimeModelsPanel,
HostPanel,
ModelsPanel,
DebugPanel,
Da3DebugPanel,
Ben2DebugPanel,
)
@@ -43,11 +55,14 @@ def register():
)
bpy.types.STATUSBAR_HT_header.append(draw_status_bar)
bpy.types.VIEW3D_MT_object_context_menu.append(draw_image_context_menu)
runtime.schedule_host_start()
def unregister():
cancel_active_job()
close_active_job()
runtime.unschedule_host()
runtime.detach_host_client()
bpy.types.VIEW3D_MT_object_context_menu.remove(draw_image_context_menu)
bpy.types.STATUSBAR_HT_header.remove(draw_status_bar)
if hasattr(bpy.types.Scene, "snapform_settings"):