kiapi 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kiapi/__init__.py +3 -0
- kiapi/__main__.py +4 -0
- kiapi/api/__init__.py +26 -0
- kiapi/api/_constants/require_auth.py +14 -0
- kiapi/api/_helpers/build_job_responses.py +73 -0
- kiapi/api/_helpers/build_openapi.py +55 -0
- kiapi/api/_helpers/build_train_responses.py +21 -0
- kiapi/api/_helpers/get_accept.py +20 -0
- kiapi/api/_helpers/get_ctx.py +7 -0
- kiapi/api/_helpers/get_worker.py +7 -0
- kiapi/api/_helpers/register_capability_endpoints.py +70 -0
- kiapi/api/_helpers/submit_and_maybe_wait.py +113 -0
- kiapi/api/_settings.py +50 -0
- kiapi/api/_views/async_job_response.py +21 -0
- kiapi/api/_views/capability_model_spec.py +49 -0
- kiapi/api/app.py +150 -0
- kiapi/api/audio/acestep/_views/extract_response.py +57 -0
- kiapi/api/audio/acestep/_views/track_response.py +57 -0
- kiapi/api/audio/acestep/router.py +190 -0
- kiapi/api/audio/audiogen/_views/audio_response.py +46 -0
- kiapi/api/audio/audiogen/router.py +77 -0
- kiapi/api/chat/_views/chat_completion_response.py +71 -0
- kiapi/api/chat/router.py +253 -0
- kiapi/api/embedding/_views/embedding_response.py +35 -0
- kiapi/api/embedding/router.py +82 -0
- kiapi/api/files/_operations/get_file.py +14 -0
- kiapi/api/files/_operations/get_file_id.py +18 -0
- kiapi/api/files/_views/file_delete_response.py +14 -0
- kiapi/api/files/_views/file_list_response.py +15 -0
- kiapi/api/files/router.py +105 -0
- kiapi/api/health/_views/health_response.py +26 -0
- kiapi/api/health/router.py +28 -0
- kiapi/api/image/depthpro/_views/estimate_response.py +70 -0
- kiapi/api/image/depthpro/router.py +81 -0
- kiapi/api/image/ernie/_views/image_response.py +50 -0
- kiapi/api/image/ernie/router.py +181 -0
- kiapi/api/image/flux2/_views/image_response.py +53 -0
- kiapi/api/image/flux2/router.py +197 -0
- kiapi/api/image/ideogram4/_views/image_response.py +55 -0
- kiapi/api/image/ideogram4/router.py +87 -0
- kiapi/api/image/qwen/_views/image_response.py +47 -0
- kiapi/api/image/qwen/router.py +141 -0
- kiapi/api/image/seedvr2/_views/image_response.py +50 -0
- kiapi/api/image/seedvr2/router.py +83 -0
- kiapi/api/image/zimage/_views/image_response.py +49 -0
- kiapi/api/image/zimage/router.py +131 -0
- kiapi/api/jobs/_operations/get_job_id.py +18 -0
- kiapi/api/jobs/_views/job_delete_response.py +19 -0
- kiapi/api/jobs/_views/job_list_response.py +15 -0
- kiapi/api/jobs/router.py +62 -0
- kiapi/api/models/_schemas/openai_model_spec.py +26 -0
- kiapi/api/models/_views/model_list_response.py +15 -0
- kiapi/api/models/router.py +29 -0
- kiapi/api/video/ltx2/_views/__init__.py +1 -0
- kiapi/api/video/ltx2/_views/video_response.py +59 -0
- kiapi/api/video/ltx2/router.py +89 -0
- kiapi/api/web/_views/__init__.py +7 -0
- kiapi/api/web/_views/fetch_api_request.py +26 -0
- kiapi/api/web/_views/fetch_error_response.py +25 -0
- kiapi/api/web/router.py +302 -0
- kiapi/capabilities/__init__.py +24 -0
- kiapi/capabilities/_exceptions/CapabilityError.py +2 -0
- kiapi/capabilities/_exceptions/ValidationError.py +2 -0
- kiapi/capabilities/_helpers/attach_mflux_progress.py +50 -0
- kiapi/capabilities/_helpers/get_file_path.py +20 -0
- kiapi/capabilities/_helpers/resolve_file_ref.py +16 -0
- kiapi/capabilities/acestep/README.ja.md +174 -0
- kiapi/capabilities/acestep/README.md +167 -0
- kiapi/capabilities/acestep/__init__.py +37 -0
- kiapi/capabilities/acestep/_constants/description.py +122 -0
- kiapi/capabilities/acestep/_exceptions/ace_step_engine_error.py +2 -0
- kiapi/capabilities/acestep/_helpers/register.py +96 -0
- kiapi/capabilities/acestep/_models/acestep.py +105 -0
- kiapi/capabilities/acestep/_operations/handle_cover.py +23 -0
- kiapi/capabilities/acestep/_operations/handle_extract.py +38 -0
- kiapi/capabilities/acestep/_operations/handle_generate.py +18 -0
- kiapi/capabilities/acestep/_operations/handle_repaint.py +25 -0
- kiapi/capabilities/acestep/_operations/resolve_ace_step_paths.py +30 -0
- kiapi/capabilities/acestep/_operations/resolve_cover_params.py +21 -0
- kiapi/capabilities/acestep/_operations/resolve_engine.py +10 -0
- kiapi/capabilities/acestep/_operations/resolve_extract_params.py +24 -0
- kiapi/capabilities/acestep/_operations/resolve_generate_params.py +18 -0
- kiapi/capabilities/acestep/_operations/resolve_repaint_params.py +22 -0
- kiapi/capabilities/acestep/_schemas/ace_step_paths.py +29 -0
- kiapi/capabilities/acestep/_services/ace_step_engine.py +143 -0
- kiapi/capabilities/acestep/_settings.py +82 -0
- kiapi/capabilities/acestep/_views/ace_step_base.py +61 -0
- kiapi/capabilities/acestep/_views/cover_params.py +26 -0
- kiapi/capabilities/acestep/_views/cover_request.py +49 -0
- kiapi/capabilities/acestep/_views/extract_params.py +24 -0
- kiapi/capabilities/acestep/_views/extract_request.py +33 -0
- kiapi/capabilities/acestep/_views/generate_params.py +25 -0
- kiapi/capabilities/acestep/_views/generate_request.py +54 -0
- kiapi/capabilities/acestep/_views/repaint_params.py +27 -0
- kiapi/capabilities/acestep/_views/repaint_request.py +51 -0
- kiapi/capabilities/acestep/_views/track_params.py +7 -0
- kiapi/capabilities/acestep/worker_subprocess.py +247 -0
- kiapi/capabilities/audiogen/README.ja.md +49 -0
- kiapi/capabilities/audiogen/README.md +48 -0
- kiapi/capabilities/audiogen/__init__.py +25 -0
- kiapi/capabilities/audiogen/_constants/description.py +60 -0
- kiapi/capabilities/audiogen/_helpers/attach_audiogen_progress.py +27 -0
- kiapi/capabilities/audiogen/_helpers/register.py +42 -0
- kiapi/capabilities/audiogen/_helpers/validate_generate.py +14 -0
- kiapi/capabilities/audiogen/_models/audiogen.py +98 -0
- kiapi/capabilities/audiogen/_operations/handle_generate.py +27 -0
- kiapi/capabilities/audiogen/_operations/resolve_generate_params.py +25 -0
- kiapi/capabilities/audiogen/_settings.py +34 -0
- kiapi/capabilities/audiogen/_views/generate_params.py +14 -0
- kiapi/capabilities/audiogen/_views/generate_request.py +96 -0
- kiapi/capabilities/chat/README.ja.md +822 -0
- kiapi/capabilities/chat/README.md +806 -0
- kiapi/capabilities/chat/__init__.py +25 -0
- kiapi/capabilities/chat/_constants/description.py +163 -0
- kiapi/capabilities/chat/_helpers/register.py +67 -0
- kiapi/capabilities/chat/_models/qwen3_5.py +183 -0
- kiapi/capabilities/chat/_models/qwen3_omni.py +242 -0
- kiapi/capabilities/chat/_operations/apply_template.py +74 -0
- kiapi/capabilities/chat/_operations/completed_hermes_tool_call_text.py +9 -0
- kiapi/capabilities/chat/_operations/emit_streaming_response.py +297 -0
- kiapi/capabilities/chat/_operations/ensure_streaming_detokenizer_compat.py +49 -0
- kiapi/capabilities/chat/_operations/format_response.py +72 -0
- kiapi/capabilities/chat/_operations/handle_chat.py +25 -0
- kiapi/capabilities/chat/_operations/parse_hermes_tool_calls.py +63 -0
- kiapi/capabilities/chat/_operations/parse_json_tool_calls.py +66 -0
- kiapi/capabilities/chat/_operations/parse_messages.py +326 -0
- kiapi/capabilities/chat/_operations/resolve_chat_params.py +50 -0
- kiapi/capabilities/chat/_operations/stream_text_from_tokens.py +32 -0
- kiapi/capabilities/chat/_operations/strip_tool_calls.py +15 -0
- kiapi/capabilities/chat/_settings.py +74 -0
- kiapi/capabilities/chat/_utils/apply_parallel_tool_call_policy.py +17 -0
- kiapi/capabilities/chat/_utils/apply_seed.py +8 -0
- kiapi/capabilities/chat/_utils/load_audio_mono.py +31 -0
- kiapi/capabilities/chat/_utils/load_mlx_vlm.py +12 -0
- kiapi/capabilities/chat/_utils/warmup_params.py +26 -0
- kiapi/capabilities/chat/_views/chat_params.py +34 -0
- kiapi/capabilities/chat/_views/chat_request.py +153 -0
- kiapi/capabilities/depthpro/README.ja.md +131 -0
- kiapi/capabilities/depthpro/README.md +124 -0
- kiapi/capabilities/depthpro/__init__.py +23 -0
- kiapi/capabilities/depthpro/_constants/description.py +39 -0
- kiapi/capabilities/depthpro/_helpers/register.py +46 -0
- kiapi/capabilities/depthpro/_helpers/validate_estimate.py +32 -0
- kiapi/capabilities/depthpro/_models/depthpro.py +144 -0
- kiapi/capabilities/depthpro/_operations/handle_estimate.py +50 -0
- kiapi/capabilities/depthpro/_operations/is_quantize_override.py +12 -0
- kiapi/capabilities/depthpro/_operations/resolve_estimate_params.py +24 -0
- kiapi/capabilities/depthpro/_settings.py +46 -0
- kiapi/capabilities/depthpro/_views/estimate_params.py +21 -0
- kiapi/capabilities/depthpro/_views/estimate_request.py +63 -0
- kiapi/capabilities/embedding/README.ja.md +137 -0
- kiapi/capabilities/embedding/README.md +128 -0
- kiapi/capabilities/embedding/__init__.py +24 -0
- kiapi/capabilities/embedding/_constants/description.py +47 -0
- kiapi/capabilities/embedding/_helpers/register.py +66 -0
- kiapi/capabilities/embedding/_models/qwen3_text.py +53 -0
- kiapi/capabilities/embedding/_models/qwen3_vl.py +97 -0
- kiapi/capabilities/embedding/_operations/format_response.py +24 -0
- kiapi/capabilities/embedding/_operations/handle_embed.py +24 -0
- kiapi/capabilities/embedding/_operations/parse_inputs.py +108 -0
- kiapi/capabilities/embedding/_operations/resolve_embed_params.py +18 -0
- kiapi/capabilities/embedding/_settings.py +27 -0
- kiapi/capabilities/embedding/_utils/to_vector.py +20 -0
- kiapi/capabilities/embedding/_views/embed_params.py +17 -0
- kiapi/capabilities/embedding/_views/embed_request.py +39 -0
- kiapi/capabilities/ernie/README.ja.md +242 -0
- kiapi/capabilities/ernie/README.md +223 -0
- kiapi/capabilities/ernie/__init__.py +34 -0
- kiapi/capabilities/ernie/_constants/description.py +71 -0
- kiapi/capabilities/ernie/_helpers/register.py +60 -0
- kiapi/capabilities/ernie/_helpers/validate_edit.py +19 -0
- kiapi/capabilities/ernie/_helpers/validate_generate.py +8 -0
- kiapi/capabilities/ernie/_models/ernie.py +356 -0
- kiapi/capabilities/ernie/_operations/handle_edit.py +39 -0
- kiapi/capabilities/ernie/_operations/handle_generate.py +38 -0
- kiapi/capabilities/ernie/_operations/handle_train.py +77 -0
- kiapi/capabilities/ernie/_operations/is_quantize_override.py +16 -0
- kiapi/capabilities/ernie/_operations/resolve_edit_params.py +44 -0
- kiapi/capabilities/ernie/_operations/resolve_generate_params.py +40 -0
- kiapi/capabilities/ernie/_operations/resolve_lora_params.py +23 -0
- kiapi/capabilities/ernie/_operations/resolve_train_params.py +43 -0
- kiapi/capabilities/ernie/_operations/validate_common.py +33 -0
- kiapi/capabilities/ernie/_schemas/lora_ref.py +27 -0
- kiapi/capabilities/ernie/_settings.py +151 -0
- kiapi/capabilities/ernie/_views/edit_params.py +36 -0
- kiapi/capabilities/ernie/_views/edit_request.py +142 -0
- kiapi/capabilities/ernie/_views/generate_params.py +32 -0
- kiapi/capabilities/ernie/_views/generate_request.py +127 -0
- kiapi/capabilities/ernie/_views/train_params.py +28 -0
- kiapi/capabilities/ernie/_views/train_request.py +96 -0
- kiapi/capabilities/flux2/README.ja.md +260 -0
- kiapi/capabilities/flux2/README.md +241 -0
- kiapi/capabilities/flux2/__init__.py +36 -0
- kiapi/capabilities/flux2/_constants/description.py +81 -0
- kiapi/capabilities/flux2/_helpers/register.py +98 -0
- kiapi/capabilities/flux2/_helpers/validate_edit.py +12 -0
- kiapi/capabilities/flux2/_helpers/validate_generate.py +8 -0
- kiapi/capabilities/flux2/_models/flux2.py +396 -0
- kiapi/capabilities/flux2/_operations/handle_edit.py +44 -0
- kiapi/capabilities/flux2/_operations/handle_generate.py +46 -0
- kiapi/capabilities/flux2/_operations/handle_train.py +105 -0
- kiapi/capabilities/flux2/_operations/is_quantize_override.py +16 -0
- kiapi/capabilities/flux2/_operations/resolve_edit_params.py +43 -0
- kiapi/capabilities/flux2/_operations/resolve_generate_params.py +44 -0
- kiapi/capabilities/flux2/_operations/resolve_lora_params.py +23 -0
- kiapi/capabilities/flux2/_operations/resolve_train_params.py +42 -0
- kiapi/capabilities/flux2/_operations/role_spec.py +13 -0
- kiapi/capabilities/flux2/_operations/split_repo.py +11 -0
- kiapi/capabilities/flux2/_operations/validate_common.py +35 -0
- kiapi/capabilities/flux2/_schemas/lora_ref.py +27 -0
- kiapi/capabilities/flux2/_settings.py +181 -0
- kiapi/capabilities/flux2/_views/edit_params.py +36 -0
- kiapi/capabilities/flux2/_views/edit_request.py +145 -0
- kiapi/capabilities/flux2/_views/generate_params.py +36 -0
- kiapi/capabilities/flux2/_views/generate_request.py +150 -0
- kiapi/capabilities/flux2/_views/train_params.py +32 -0
- kiapi/capabilities/flux2/_views/train_request.py +102 -0
- kiapi/capabilities/ideogram4/README.ja.md +230 -0
- kiapi/capabilities/ideogram4/README.md +219 -0
- kiapi/capabilities/ideogram4/__init__.py +24 -0
- kiapi/capabilities/ideogram4/_constants/description.py +65 -0
- kiapi/capabilities/ideogram4/_helpers/register.py +44 -0
- kiapi/capabilities/ideogram4/_helpers/validate_generate.py +31 -0
- kiapi/capabilities/ideogram4/_models/ideogram4.py +120 -0
- kiapi/capabilities/ideogram4/_operations/handle_generate.py +30 -0
- kiapi/capabilities/ideogram4/_operations/is_quantize_override.py +12 -0
- kiapi/capabilities/ideogram4/_operations/resolve_generate_params.py +30 -0
- kiapi/capabilities/ideogram4/_settings.py +89 -0
- kiapi/capabilities/ideogram4/_views/generate_params.py +27 -0
- kiapi/capabilities/ideogram4/_views/generate_request.py +118 -0
- kiapi/capabilities/ltx2/README.ja.md +287 -0
- kiapi/capabilities/ltx2/README.md +274 -0
- kiapi/capabilities/ltx2/__init__.py +26 -0
- kiapi/capabilities/ltx2/_constants/description.py +81 -0
- kiapi/capabilities/ltx2/_helpers/register.py +58 -0
- kiapi/capabilities/ltx2/_helpers/validate_generate.py +42 -0
- kiapi/capabilities/ltx2/_models/ltx2.py +106 -0
- kiapi/capabilities/ltx2/_operations/detect_mode.py +19 -0
- kiapi/capabilities/ltx2/_operations/handle_generate.py +52 -0
- kiapi/capabilities/ltx2/_operations/resolve_generate_params.py +31 -0
- kiapi/capabilities/ltx2/_settings.py +93 -0
- kiapi/capabilities/ltx2/_views/generate_params.py +34 -0
- kiapi/capabilities/ltx2/_views/generate_request.py +151 -0
- kiapi/capabilities/qwen/README.ja.md +251 -0
- kiapi/capabilities/qwen/README.md +235 -0
- kiapi/capabilities/qwen/__init__.py +30 -0
- kiapi/capabilities/qwen/_constants/description.py +53 -0
- kiapi/capabilities/qwen/_helpers/register.py +60 -0
- kiapi/capabilities/qwen/_helpers/validate_edit.py +12 -0
- kiapi/capabilities/qwen/_helpers/validate_generate.py +12 -0
- kiapi/capabilities/qwen/_models/qwen.py +224 -0
- kiapi/capabilities/qwen/_operations/handle_edit.py +44 -0
- kiapi/capabilities/qwen/_operations/handle_generate.py +46 -0
- kiapi/capabilities/qwen/_operations/is_quantize_override.py +15 -0
- kiapi/capabilities/qwen/_operations/resolve_edit_params.py +35 -0
- kiapi/capabilities/qwen/_operations/resolve_generate_params.py +39 -0
- kiapi/capabilities/qwen/_operations/resolve_lora_params.py +23 -0
- kiapi/capabilities/qwen/_operations/validate_common.py +32 -0
- kiapi/capabilities/qwen/_schemas/lora_ref.py +27 -0
- kiapi/capabilities/qwen/_settings.py +107 -0
- kiapi/capabilities/qwen/_views/edit_params.py +36 -0
- kiapi/capabilities/qwen/_views/edit_request.py +138 -0
- kiapi/capabilities/qwen/_views/generate_params.py +37 -0
- kiapi/capabilities/qwen/_views/generate_request.py +149 -0
- kiapi/capabilities/seedvr2/README.ja.md +234 -0
- kiapi/capabilities/seedvr2/README.md +219 -0
- kiapi/capabilities/seedvr2/__init__.py +24 -0
- kiapi/capabilities/seedvr2/_constants/description.py +46 -0
- kiapi/capabilities/seedvr2/_helpers/register.py +60 -0
- kiapi/capabilities/seedvr2/_helpers/validate_upscale.py +52 -0
- kiapi/capabilities/seedvr2/_models/seedvr2.py +140 -0
- kiapi/capabilities/seedvr2/_operations/handle_upscale.py +42 -0
- kiapi/capabilities/seedvr2/_operations/is_quantize_override.py +12 -0
- kiapi/capabilities/seedvr2/_operations/resolve_upscale_params.py +30 -0
- kiapi/capabilities/seedvr2/_settings.py +74 -0
- kiapi/capabilities/seedvr2/_views/upscale_params.py +27 -0
- kiapi/capabilities/seedvr2/_views/upscale_request.py +94 -0
- kiapi/capabilities/web/README.ja.md +187 -0
- kiapi/capabilities/web/README.md +171 -0
- kiapi/capabilities/web/__init__.py +30 -0
- kiapi/capabilities/web/_constants/description.py +38 -0
- kiapi/capabilities/web/_exceptions/FetchError.py +24 -0
- kiapi/capabilities/web/_exceptions/SearchBackendError.py +11 -0
- kiapi/capabilities/web/_helpers/register.py +59 -0
- kiapi/capabilities/web/_models/crawl4ai.py +32 -0
- kiapi/capabilities/web/_models/searxng.py +44 -0
- kiapi/capabilities/web/_operations/handle_fetch.py +145 -0
- kiapi/capabilities/web/_operations/handle_search.py +56 -0
- kiapi/capabilities/web/_operations/resolve_fetch_params.py +19 -0
- kiapi/capabilities/web/_operations/resolve_search_params.py +34 -0
- kiapi/capabilities/web/_operations/resolve_searxng_config_dir.py +21 -0
- kiapi/capabilities/web/_services/__init__.py +1 -0
- kiapi/capabilities/web/_services/web_backend_process.py +144 -0
- kiapi/capabilities/web/_settings.py +138 -0
- kiapi/capabilities/web/_views/fetch_params.py +27 -0
- kiapi/capabilities/web/_views/fetch_request.py +29 -0
- kiapi/capabilities/web/_views/fetch_result.py +20 -0
- kiapi/capabilities/web/_views/search_params.py +43 -0
- kiapi/capabilities/web/_views/search_request.py +93 -0
- kiapi/capabilities/web/_views/search_response.py +49 -0
- kiapi/capabilities/web/resources/__init__.py +0 -0
- kiapi/capabilities/web/resources/searxng/__init__.py +0 -0
- kiapi/capabilities/web/resources/searxng/settings.yml +11 -0
- kiapi/capabilities/zimage/README.ja.md +249 -0
- kiapi/capabilities/zimage/README.md +231 -0
- kiapi/capabilities/zimage/__init__.py +34 -0
- kiapi/capabilities/zimage/_constants/description.py +73 -0
- kiapi/capabilities/zimage/_helpers/register.py +62 -0
- kiapi/capabilities/zimage/_helpers/validate_generate.py +37 -0
- kiapi/capabilities/zimage/_models/zimage.py +278 -0
- kiapi/capabilities/zimage/_operations/handle_generate.py +38 -0
- kiapi/capabilities/zimage/_operations/handle_train.py +78 -0
- kiapi/capabilities/zimage/_operations/is_quantize_override.py +11 -0
- kiapi/capabilities/zimage/_operations/resolve_generate_params.py +39 -0
- kiapi/capabilities/zimage/_operations/resolve_lora_params.py +23 -0
- kiapi/capabilities/zimage/_operations/resolve_train_params.py +38 -0
- kiapi/capabilities/zimage/_schemas/lora_ref.py +27 -0
- kiapi/capabilities/zimage/_settings.py +166 -0
- kiapi/capabilities/zimage/_views/generate_params.py +23 -0
- kiapi/capabilities/zimage/_views/generate_request.py +127 -0
- kiapi/capabilities/zimage/_views/train_params.py +22 -0
- kiapi/capabilities/zimage/_views/train_request.py +101 -0
- kiapi/cli/__init__.py +11 -0
- kiapi/cli/_helpers/dedupe_resources.py +12 -0
- kiapi/cli/_helpers/register_all_capabilities.py +36 -0
- kiapi/cli/_helpers/run_resources.py +24 -0
- kiapi/cli/_helpers/select_specs.py +67 -0
- kiapi/cli/activate/_operations/preflight_hf_access.py +129 -0
- kiapi/cli/activate/cli.py +37 -0
- kiapi/cli/check/_helpers/check_audio_acestep_turbo.py +22 -0
- kiapi/cli/check/_helpers/check_audio_acestep_xl_base.py +22 -0
- kiapi/cli/check/_helpers/check_audio_audiogen_medium.py +24 -0
- kiapi/cli/check/_helpers/check_chat_chat_qwen3_6_27b.py +19 -0
- kiapi/cli/check/_helpers/check_chat_chat_qwen3_omni.py +19 -0
- kiapi/cli/check/_helpers/check_embedding_embedding_qwen3_embedding_8b.py +14 -0
- kiapi/cli/check/_helpers/check_embedding_embedding_qwen3_vl_embedding_2b.py +19 -0
- kiapi/cli/check/_helpers/check_image_depthpro_base.py +21 -0
- kiapi/cli/check/_helpers/check_image_ernie_base.py +23 -0
- kiapi/cli/check/_helpers/check_image_ernie_turbo.py +23 -0
- kiapi/cli/check/_helpers/check_image_flux2_klein_9b.py +23 -0
- kiapi/cli/check/_helpers/check_image_flux2_klein_base_4b.py +23 -0
- kiapi/cli/check/_helpers/check_image_flux2_klein_base_9b.py +23 -0
- kiapi/cli/check/_helpers/check_image_ideogram4_fp8.py +23 -0
- kiapi/cli/check/_helpers/check_image_qwen_edit_2509.py +27 -0
- kiapi/cli/check/_helpers/check_image_qwen_image.py +23 -0
- kiapi/cli/check/_helpers/check_image_seedvr2_3b.py +23 -0
- kiapi/cli/check/_helpers/check_image_seedvr2_7b.py +23 -0
- kiapi/cli/check/_helpers/check_image_zimage_base.py +23 -0
- kiapi/cli/check/_helpers/check_image_zimage_turbo.py +23 -0
- kiapi/cli/check/_helpers/check_video_ltx2_distilled.py +26 -0
- kiapi/cli/check/_helpers/check_web_web_fetch.py +14 -0
- kiapi/cli/check/_helpers/check_web_web_search.py +14 -0
- kiapi/cli/check/_operations/build_check_result.py +20 -0
- kiapi/cli/check/_operations/check_context.py +10 -0
- kiapi/cli/check/_operations/create_sample_image.py +46 -0
- kiapi/cli/check/_schemas/check_result.py +12 -0
- kiapi/cli/check/cli.py +89 -0
- kiapi/cli/cli.py +29 -0
- kiapi/cli/config/cli.py +17 -0
- kiapi/cli/config/edit/cli.py +32 -0
- kiapi/cli/config/init/cli.py +33 -0
- kiapi/cli/config/show/cli.py +13 -0
- kiapi/cli/config/template/cli.py +36 -0
- kiapi/cli/deactivate/cli.py +49 -0
- kiapi/cli/run/asgi.py +16 -0
- kiapi/cli/run/cli.py +59 -0
- kiapi/cli/service/__init__.py +5 -0
- kiapi/cli/service/_services/service_manager.py +107 -0
- kiapi/cli/service/cli.py +19 -0
- kiapi/cli/service/install/cli.py +17 -0
- kiapi/cli/service/start/cli.py +22 -0
- kiapi/cli/service/status/cli.py +81 -0
- kiapi/cli/service/stop/cli.py +19 -0
- kiapi/cli/service/uninstall/cli.py +16 -0
- kiapi/cli/status/cli.py +226 -0
- kiapi/core/app/__init__.py +16 -0
- kiapi/core/app/_schemas/app_context.py +28 -0
- kiapi/core/app/_services/user_directory.py +59 -0
- kiapi/core/app/_settings.py +46 -0
- kiapi/core/capability/__init__.py +11 -0
- kiapi/core/capability/_schemas/capability_spec.py +17 -0
- kiapi/core/capability/_services/capability_spec_registry.py +21 -0
- kiapi/core/config/__init__.py +11 -0
- kiapi/core/config/_exceptions/user_config_error.py +2 -0
- kiapi/core/config/_helpers/get_user_settings_path.py +7 -0
- kiapi/core/config/_helpers/load_user_settings.py +54 -0
- kiapi/core/file/__init__.py +37 -0
- kiapi/core/file/_helpers/create_file_store.py +7 -0
- kiapi/core/file/_helpers/resolve_file_ref.py +90 -0
- kiapi/core/file/_schemas/file_data_url_ref.py +19 -0
- kiapi/core/file/_schemas/file_id_ref.py +16 -0
- kiapi/core/file/_schemas/file_record.py +46 -0
- kiapi/core/file/_schemas/file_url_ref.py +16 -0
- kiapi/core/file/_services/file_store.py +138 -0
- kiapi/core/file/_settings.py +22 -0
- kiapi/core/file/_types/file_id.py +2 -0
- kiapi/core/file/_types/file_ref.py +12 -0
- kiapi/core/file/_views/resolved_file_ref.py +16 -0
- kiapi/core/job/__init__.py +24 -0
- kiapi/core/job/_enums/job_status.py +9 -0
- kiapi/core/job/_helpers/creep_progress.py +123 -0
- kiapi/core/job/_models/job.py +121 -0
- kiapi/core/job/_services/job_store.py +33 -0
- kiapi/core/job/_services/progress_reporter.py +79 -0
- kiapi/core/job/_types/job_id.py +3 -0
- kiapi/core/job/_types/job_result.py +5 -0
- kiapi/core/job/_types/job_type.py +4 -0
- kiapi/core/logging/__init__.py +14 -0
- kiapi/core/logging/_helpers/get_log_level.py +8 -0
- kiapi/core/logging/_helpers/setup_logger.py +14 -0
- kiapi/core/logging/_settings.py +34 -0
- kiapi/core/logging/_types/log_level.py +3 -0
- kiapi/core/memory/__init__.py +21 -0
- kiapi/core/memory/_exceptions/memory_budget_error.py +2 -0
- kiapi/core/memory/_helpers/create_memory_manager.py +17 -0
- kiapi/core/memory/_operations/log_memory_limit.py +29 -0
- kiapi/core/memory/_operations/resolve_effective_memory_limit_gb.py +13 -0
- kiapi/core/memory/_operations/resolve_framework_strategy.py +42 -0
- kiapi/core/memory/_schemas/framework_strategy.py +14 -0
- kiapi/core/memory/_schemas/memory_stats.py +24 -0
- kiapi/core/memory/_schemas/resident_model.py +14 -0
- kiapi/core/memory/_schemas/resident_model_stats.py +49 -0
- kiapi/core/memory/_services/memory_manager.py +257 -0
- kiapi/core/memory/_settings.py +36 -0
- kiapi/core/memory/_types/framework_name.py +4 -0
- kiapi/core/memory/_types/resident_key.py +4 -0
- kiapi/core/model/__init__.py +36 -0
- kiapi/core/model/_exceptions/unknown_model_error.py +2 -0
- kiapi/core/model/_schemas/model_spec.py +145 -0
- kiapi/core/model/_services/model_registry.py +85 -0
- kiapi/core/model/_types/model_alias.py +2 -0
- kiapi/core/model/_types/model_domain.py +6 -0
- kiapi/core/model/_types/model_family.py +5 -0
- kiapi/core/model/_types/model_key.py +8 -0
- kiapi/core/model/_types/model_name.py +4 -0
- kiapi/core/model/_types/model_repo.py +3 -0
- kiapi/core/net/__init__.py +16 -0
- kiapi/core/net/_exceptions/unsafe_url_error.py +7 -0
- kiapi/core/net/_helpers/verify_public_url.py +68 -0
- kiapi/core/net/_settings.py +28 -0
- kiapi/core/setup/__init__.py +25 -0
- kiapi/core/setup/_exceptions/setup_required_error.py +2 -0
- kiapi/core/setup/_schemas/docker_image_resource.py +37 -0
- kiapi/core/setup/_schemas/hf_snapshot_resource.py +50 -0
- kiapi/core/setup/_schemas/local_path_resource.py +43 -0
- kiapi/core/setup/_schemas/python_package_resource.py +58 -0
- kiapi/core/setup/_schemas/python_venv_resource.py +63 -0
- kiapi/core/setup/_schemas/setup_status.py +7 -0
- kiapi/core/setup/_schemas/url_file_resource.py +43 -0
- kiapi/core/setup/_services/setup_manager.py +331 -0
- kiapi/core/setup/_types/setup_resource.py +21 -0
- kiapi/core/setup/_types/setup_target.py +11 -0
- kiapi/core/workdir/__init__.py +8 -0
- kiapi/core/workdir/_helpers/create_work_dir.py +11 -0
- kiapi/core/workdir/_settings.py +21 -0
- kiapi/core/worker/__init__.py +23 -0
- kiapi/core/worker/_helpers/create_worker.py +9 -0
- kiapi/core/worker/_services/worker.py +165 -0
- kiapi/core/worker/_settings.py +36 -0
- kiapi/core/worker/_types/job_thunk.py +6 -0
- kiapi-0.1.0.dist-info/METADATA +337 -0
- kiapi-0.1.0.dist-info/RECORD +465 -0
- kiapi-0.1.0.dist-info/WHEEL +4 -0
- kiapi-0.1.0.dist-info/entry_points.txt +2 -0
- kiapi-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""Image API (ideogram4): Ideogram 4 txt2img."""
|
|
2
|
+
|
|
3
|
+
from fastapi import APIRouter, Depends, HTTPException
|
|
4
|
+
from fastapi.responses import Response
|
|
5
|
+
|
|
6
|
+
from kiapi.api import (
|
|
7
|
+
REQUIRE_AUTH,
|
|
8
|
+
build_job_responses,
|
|
9
|
+
get_accept,
|
|
10
|
+
get_ctx,
|
|
11
|
+
get_worker,
|
|
12
|
+
register_capability_endpoints,
|
|
13
|
+
submit_and_maybe_wait,
|
|
14
|
+
)
|
|
15
|
+
from kiapi.capabilities.ideogram4 import (
|
|
16
|
+
GenerateRequest,
|
|
17
|
+
ValidationError,
|
|
18
|
+
handle_generate,
|
|
19
|
+
validate_generate,
|
|
20
|
+
)
|
|
21
|
+
from kiapi.core.app import AppContext
|
|
22
|
+
from kiapi.core.model import UnknownModelError, model_registry
|
|
23
|
+
from kiapi.core.worker import Worker
|
|
24
|
+
|
|
25
|
+
from ._views.image_response import ImageResponse
|
|
26
|
+
|
|
27
|
+
router = APIRouter(dependencies=REQUIRE_AUTH)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@router.post(
|
|
31
|
+
"/v1/image/ideogram4/generate",
|
|
32
|
+
responses=build_job_responses(
|
|
33
|
+
"image/png", "image/jpeg", "image/webp", result_model=ImageResponse
|
|
34
|
+
),
|
|
35
|
+
)
|
|
36
|
+
async def generate(
|
|
37
|
+
req: GenerateRequest,
|
|
38
|
+
accept: str | None = Depends(get_accept),
|
|
39
|
+
ctx: AppContext = Depends(get_ctx),
|
|
40
|
+
worker: Worker = Depends(get_worker),
|
|
41
|
+
) -> Response:
|
|
42
|
+
"""Generate one image from a text prompt or JSON caption (Ideogram 4, text-to-image).
|
|
43
|
+
|
|
44
|
+
Ideogram 4 is typography-focused txt2img — there is no image-to-image or
|
|
45
|
+
training. Prefer a structured JSON `prompt` (high_level_description,
|
|
46
|
+
optional style_description, compositional_deconstruction with element
|
|
47
|
+
`bbox`/`text`) for crisp lettering; plain text works but is usually weaker.
|
|
48
|
+
The same endpoint serves both `sync` and `async` via `mode`. Pick the
|
|
49
|
+
speed/quality tradeoff with `preset` (V4_TURBO_12 → V4_DEFAULT_20 →
|
|
50
|
+
V4_QUALITY_48).
|
|
51
|
+
|
|
52
|
+
Sync content negotiation: a single image is produced, so unless the client
|
|
53
|
+
asks for JSON the raw image bytes are returned with `X-Kiapi-File-Id` /
|
|
54
|
+
`X-Kiapi-Job-Id` headers — `curl -o out.png` just works. With
|
|
55
|
+
`Accept: application/json` (or async) the Job JSON is returned, whose
|
|
56
|
+
`result` follows ImageResponse.
|
|
57
|
+
|
|
58
|
+
A `quantize` differing from the resident model runs a one-off transient
|
|
59
|
+
model (slower, not reused). Ideogram 4 may return an 'Image blocked by safety
|
|
60
|
+
filter' image (including false positives); kiapi stores it as the artifact
|
|
61
|
+
rather than raising an error. Async returns 202 immediately; poll
|
|
62
|
+
GET /v1/jobs/{job_id} and fetch the artifact via GET /v1/files/{file_id}.
|
|
63
|
+
"""
|
|
64
|
+
try:
|
|
65
|
+
spec = model_registry.resolve("ideogram4", req.model)
|
|
66
|
+
except UnknownModelError as exc:
|
|
67
|
+
raise HTTPException(status_code=400, detail=str(exc)) # noqa: B904
|
|
68
|
+
try:
|
|
69
|
+
validate_generate(req)
|
|
70
|
+
except ValidationError as exc:
|
|
71
|
+
raise HTTPException(status_code=422, detail=str(exc)) # noqa: B904
|
|
72
|
+
|
|
73
|
+
def thunk(): # type: ignore
|
|
74
|
+
return handle_generate(ctx, req)
|
|
75
|
+
|
|
76
|
+
return await submit_and_maybe_wait(
|
|
77
|
+
ctx,
|
|
78
|
+
worker,
|
|
79
|
+
type="ideogram4",
|
|
80
|
+
params=req.gen_params() | {"model": spec.name, "mode": req.mode},
|
|
81
|
+
thunk=thunk,
|
|
82
|
+
mode=req.mode,
|
|
83
|
+
accept=accept,
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
register_capability_endpoints(router, name="ideogram4", base_path="/v1/image/ideogram4")
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""``/v1/image/qwen/{generate,edit}`` result payload (the Job ``result`` shape).
|
|
2
|
+
|
|
3
|
+
Mirrors the dict returned by ``capabilities/qwen/_models/qwen._store_image`` so the
|
|
4
|
+
produced image result is self-describing in OpenAPI. It is an output-side
|
|
5
|
+
projection of the model result (not a model-coupled view), so it lives under
|
|
6
|
+
``api/image/qwen/_views``. The same shape is returned by both generate and edit.
|
|
7
|
+
|
|
8
|
+
``ImageResponse`` is the sole public element; nested pieces stay private.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
from pydantic import BaseModel, Field
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class _Timings(BaseModel):
|
|
17
|
+
total_s: float = Field(
|
|
18
|
+
description="Wall-clock generation time in seconds (model run only)."
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ImageResponse(BaseModel):
|
|
23
|
+
"""Capability-specific ``result`` for a succeeded qwen generate/edit job."""
|
|
24
|
+
|
|
25
|
+
model: str = Field(description="Resolved model variant that produced the image.")
|
|
26
|
+
prompt: str = Field(description="The prompt used for the run.")
|
|
27
|
+
|
|
28
|
+
file_id: str = Field(
|
|
29
|
+
description=(
|
|
30
|
+
"Files-API id of the produced image. Fetch metadata at "
|
|
31
|
+
"GET /v1/files/{id} or bytes at /download. This is also the artifact "
|
|
32
|
+
"returned as raw bytes by a single-artifact sync call."
|
|
33
|
+
)
|
|
34
|
+
)
|
|
35
|
+
image_bytes: int = Field(description="Size of the produced image in bytes.")
|
|
36
|
+
|
|
37
|
+
width: int = Field(description="Width in pixels of the produced image.")
|
|
38
|
+
height: int = Field(description="Height in pixels of the produced image.")
|
|
39
|
+
|
|
40
|
+
params: dict[str, Any] = Field(
|
|
41
|
+
description=(
|
|
42
|
+
"Resolved parameters actually used for the run (model, prompt, seed, "
|
|
43
|
+
"width, height, steps, guidance, quantize, scheduler, format, quality, "
|
|
44
|
+
"loras, …), so the result is reproducible."
|
|
45
|
+
)
|
|
46
|
+
)
|
|
47
|
+
timings: _Timings = Field(description="kiapi extension: server-side timing.")
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"""Image API (qwen): Qwen Image generate/edit."""
|
|
2
|
+
|
|
3
|
+
from fastapi import APIRouter, Depends, HTTPException
|
|
4
|
+
from fastapi.responses import Response
|
|
5
|
+
|
|
6
|
+
from kiapi.api import (
|
|
7
|
+
REQUIRE_AUTH,
|
|
8
|
+
build_job_responses,
|
|
9
|
+
get_accept,
|
|
10
|
+
get_ctx,
|
|
11
|
+
get_worker,
|
|
12
|
+
register_capability_endpoints,
|
|
13
|
+
submit_and_maybe_wait,
|
|
14
|
+
)
|
|
15
|
+
from kiapi.capabilities.qwen import (
|
|
16
|
+
EditRequest,
|
|
17
|
+
GenerateRequest,
|
|
18
|
+
ValidationError,
|
|
19
|
+
handle_edit,
|
|
20
|
+
handle_generate,
|
|
21
|
+
validate_edit,
|
|
22
|
+
validate_generate,
|
|
23
|
+
)
|
|
24
|
+
from kiapi.core.app import AppContext
|
|
25
|
+
from kiapi.core.model import UnknownModelError, model_registry
|
|
26
|
+
from kiapi.core.worker import Worker
|
|
27
|
+
|
|
28
|
+
from ._views.image_response import ImageResponse
|
|
29
|
+
|
|
30
|
+
router = APIRouter(dependencies=REQUIRE_AUTH)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@router.post(
|
|
34
|
+
"/v1/image/qwen/generate",
|
|
35
|
+
responses=build_job_responses(
|
|
36
|
+
"image/png", "image/jpeg", "image/webp", result_model=ImageResponse
|
|
37
|
+
),
|
|
38
|
+
)
|
|
39
|
+
async def generate_qwen_endpoint(
|
|
40
|
+
req: GenerateRequest,
|
|
41
|
+
accept: str | None = Depends(get_accept),
|
|
42
|
+
ctx: AppContext = Depends(get_ctx),
|
|
43
|
+
worker: Worker = Depends(get_worker),
|
|
44
|
+
) -> Response:
|
|
45
|
+
"""Generate an image from a text prompt (Qwen Image, text-to-image / img2img).
|
|
46
|
+
|
|
47
|
+
Plain text-to-image by default; supply `init_image` (+ optional
|
|
48
|
+
`image_strength`) to run img2img instead — use `/v1/image/qwen/edit` for
|
|
49
|
+
natural-language single/multi-image editing. The same endpoint serves both
|
|
50
|
+
`sync` and `async` via `mode`. This endpoint only accepts the `image` model
|
|
51
|
+
variant.
|
|
52
|
+
|
|
53
|
+
Sync content negotiation: a single image is produced, so unless the client
|
|
54
|
+
asks for JSON the raw image bytes are returned with `X-Kiapi-File-Id` /
|
|
55
|
+
`X-Kiapi-Job-Id` headers — `curl -o out.png` just works. With
|
|
56
|
+
`Accept: application/json` (or async) the Job JSON is returned, whose
|
|
57
|
+
`result` follows ImageResponse.
|
|
58
|
+
|
|
59
|
+
Any `loras` or a `quantize` differing from the resident model runs a one-off
|
|
60
|
+
transient model (slower, not reused). Async returns 202 immediately; poll
|
|
61
|
+
GET /v1/jobs/{job_id} and fetch the artifact via GET /v1/files/{file_id}.
|
|
62
|
+
"""
|
|
63
|
+
try:
|
|
64
|
+
spec = model_registry.resolve("qwen", req.model or "image")
|
|
65
|
+
except UnknownModelError as exc:
|
|
66
|
+
raise HTTPException(status_code=400, detail=str(exc)) # noqa: B904
|
|
67
|
+
if spec.name != "image":
|
|
68
|
+
raise HTTPException(
|
|
69
|
+
status_code=400, detail="qwen generate requires model 'image'"
|
|
70
|
+
)
|
|
71
|
+
try:
|
|
72
|
+
validate_generate(req)
|
|
73
|
+
except ValidationError as exc:
|
|
74
|
+
raise HTTPException(status_code=422, detail=str(exc)) # noqa: B904
|
|
75
|
+
|
|
76
|
+
def thunk(): # type: ignore
|
|
77
|
+
return handle_generate(ctx, req)
|
|
78
|
+
|
|
79
|
+
return await submit_and_maybe_wait(
|
|
80
|
+
ctx,
|
|
81
|
+
worker,
|
|
82
|
+
type="qwen",
|
|
83
|
+
params=req.gen_params() | {"model": spec.name, "mode": req.mode},
|
|
84
|
+
thunk=thunk,
|
|
85
|
+
mode=req.mode,
|
|
86
|
+
accept=accept,
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
@router.post(
|
|
91
|
+
"/v1/image/qwen/edit",
|
|
92
|
+
responses=build_job_responses(
|
|
93
|
+
"image/png", "image/jpeg", "image/webp", result_model=ImageResponse
|
|
94
|
+
),
|
|
95
|
+
)
|
|
96
|
+
async def edit_qwen_endpoint(
|
|
97
|
+
req: EditRequest,
|
|
98
|
+
accept: str | None = Depends(get_accept),
|
|
99
|
+
ctx: AppContext = Depends(get_ctx),
|
|
100
|
+
worker: Worker = Depends(get_worker),
|
|
101
|
+
) -> Response:
|
|
102
|
+
"""Edit / combine one or more reference images with a prompt (Qwen Image Edit).
|
|
103
|
+
|
|
104
|
+
Takes a list of `images` (FileRefs, single or multi-image) plus a
|
|
105
|
+
natural-language `prompt`. For plain image-to-image from a single seed image,
|
|
106
|
+
use `init_image` on `/v1/image/qwen/generate` instead. The same endpoint
|
|
107
|
+
serves both `sync` and `async` via `mode`. This endpoint only accepts the
|
|
108
|
+
`edit-2509` model variant.
|
|
109
|
+
|
|
110
|
+
Sync content negotiation, transient-model behavior (`loras` / `quantize`
|
|
111
|
+
override), and the ImageResponse `result` shape match
|
|
112
|
+
`/v1/image/qwen/generate`.
|
|
113
|
+
"""
|
|
114
|
+
try:
|
|
115
|
+
spec = model_registry.resolve("qwen", req.model or "edit-2509")
|
|
116
|
+
except UnknownModelError as exc:
|
|
117
|
+
raise HTTPException(status_code=400, detail=str(exc)) # noqa: B904
|
|
118
|
+
if spec.name != "edit-2509":
|
|
119
|
+
raise HTTPException(
|
|
120
|
+
status_code=400, detail="qwen edit requires model 'edit-2509'"
|
|
121
|
+
)
|
|
122
|
+
try:
|
|
123
|
+
validate_edit(req)
|
|
124
|
+
except ValidationError as exc:
|
|
125
|
+
raise HTTPException(status_code=422, detail=str(exc)) # noqa: B904
|
|
126
|
+
|
|
127
|
+
def thunk(): # type: ignore
|
|
128
|
+
return handle_edit(ctx, req)
|
|
129
|
+
|
|
130
|
+
return await submit_and_maybe_wait(
|
|
131
|
+
ctx,
|
|
132
|
+
worker,
|
|
133
|
+
type="qwen-edit",
|
|
134
|
+
params=req.gen_params() | {"model": spec.name, "mode": req.mode},
|
|
135
|
+
thunk=thunk,
|
|
136
|
+
mode=req.mode,
|
|
137
|
+
accept=accept,
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
register_capability_endpoints(router, name="qwen", base_path="/v1/image/qwen")
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""``/v1/image/seedvr2/upscale`` result payload (the Job ``result`` shape).
|
|
2
|
+
|
|
3
|
+
Mirrors the dict returned by ``capabilities/seedvr2/_models/seedvr2._store_image``
|
|
4
|
+
so the upscaled image result is self-describing in OpenAPI. It is an output-side
|
|
5
|
+
projection of the model result (not a model-coupled view), so it lives under
|
|
6
|
+
``api/image/seedvr2/_views``.
|
|
7
|
+
|
|
8
|
+
``ImageResponse`` is the sole public element; nested pieces stay private.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
from pydantic import BaseModel, Field
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class _Timings(BaseModel):
|
|
17
|
+
total_s: float = Field(
|
|
18
|
+
description="Wall-clock upscale time in seconds (model run only)."
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ImageResponse(BaseModel):
|
|
23
|
+
"""Capability-specific ``result`` for a succeeded seedvr2 upscale job."""
|
|
24
|
+
|
|
25
|
+
model: str = Field(
|
|
26
|
+
description="Resolved model variant that produced the image (3b or 7b)."
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
file_id: str = Field(
|
|
30
|
+
description=(
|
|
31
|
+
"Files-API id of the upscaled image. Fetch metadata at "
|
|
32
|
+
"GET /v1/files/{id} or bytes at /download. This is also the artifact "
|
|
33
|
+
"returned as raw bytes by a single-artifact sync call."
|
|
34
|
+
)
|
|
35
|
+
)
|
|
36
|
+
image_bytes: int = Field(description="Size of the produced image in bytes.")
|
|
37
|
+
|
|
38
|
+
input_width: int = Field(description="Width in pixels of the input image.")
|
|
39
|
+
input_height: int = Field(description="Height in pixels of the input image.")
|
|
40
|
+
width: int = Field(description="Width in pixels of the upscaled image.")
|
|
41
|
+
height: int = Field(description="Height in pixels of the upscaled image.")
|
|
42
|
+
|
|
43
|
+
params: dict[str, Any] = Field(
|
|
44
|
+
description=(
|
|
45
|
+
"Resolved parameters actually used for the run (model, resolution, "
|
|
46
|
+
"softness, seed, quantize, format, quality), so the result is "
|
|
47
|
+
"reproducible."
|
|
48
|
+
)
|
|
49
|
+
)
|
|
50
|
+
timings: _Timings = Field(description="kiapi extension: server-side timing.")
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""Image API (seedvr2): ``POST /v1/image/seedvr2/upscale``."""
|
|
2
|
+
|
|
3
|
+
from fastapi import APIRouter, Depends, HTTPException
|
|
4
|
+
from fastapi.responses import Response
|
|
5
|
+
|
|
6
|
+
from kiapi.api import (
|
|
7
|
+
REQUIRE_AUTH,
|
|
8
|
+
build_job_responses,
|
|
9
|
+
get_accept,
|
|
10
|
+
get_ctx,
|
|
11
|
+
get_worker,
|
|
12
|
+
register_capability_endpoints,
|
|
13
|
+
submit_and_maybe_wait,
|
|
14
|
+
)
|
|
15
|
+
from kiapi.capabilities.seedvr2 import (
|
|
16
|
+
UpscaleRequest,
|
|
17
|
+
ValidationError,
|
|
18
|
+
handle_upscale,
|
|
19
|
+
validate_upscale,
|
|
20
|
+
)
|
|
21
|
+
from kiapi.core.app import AppContext
|
|
22
|
+
from kiapi.core.model import UnknownModelError, model_registry
|
|
23
|
+
from kiapi.core.worker import Worker
|
|
24
|
+
|
|
25
|
+
from ._views.image_response import ImageResponse
|
|
26
|
+
|
|
27
|
+
router = APIRouter(dependencies=REQUIRE_AUTH)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@router.post(
|
|
31
|
+
"/v1/image/seedvr2/upscale",
|
|
32
|
+
responses=build_job_responses(
|
|
33
|
+
"image/png", "image/jpeg", "image/webp", result_model=ImageResponse
|
|
34
|
+
),
|
|
35
|
+
)
|
|
36
|
+
async def upscale_seedvr2_endpoint(
|
|
37
|
+
req: UpscaleRequest,
|
|
38
|
+
accept: str | None = Depends(get_accept),
|
|
39
|
+
ctx: AppContext = Depends(get_ctx),
|
|
40
|
+
worker: Worker = Depends(get_worker),
|
|
41
|
+
) -> Response:
|
|
42
|
+
"""Upscale one image with diffusion super-resolution (SeedVR2 via mflux).
|
|
43
|
+
|
|
44
|
+
Takes an input `image` (FileRef) and produces a higher-resolution version.
|
|
45
|
+
SeedVR2 is super-resolution, not prompt-driven generation — there is no
|
|
46
|
+
prompt. The target size is set by `resolution`: an integer shortest-edge
|
|
47
|
+
pixel target (16..2048) or a scale factor like `"2x"` (up to `4.0x`). The
|
|
48
|
+
same endpoint serves both `sync` and `async` via `mode`.
|
|
49
|
+
|
|
50
|
+
Sync content negotiation: a single image is produced, so unless the client
|
|
51
|
+
asks for JSON the raw image bytes are returned with `X-Kiapi-File-Id` /
|
|
52
|
+
`X-Kiapi-Job-Id` headers — `curl -o out.png` just works. With
|
|
53
|
+
`Accept: application/json` (or async) the Job JSON is returned, whose
|
|
54
|
+
`result` follows ImageResponse.
|
|
55
|
+
|
|
56
|
+
A `quantize` differing from the resident model's quantization runs a one-off
|
|
57
|
+
transient model (slower, not reused). Async returns 202 immediately; poll
|
|
58
|
+
GET /v1/jobs/{job_id} and fetch the artifact via GET /v1/files/{file_id}.
|
|
59
|
+
"""
|
|
60
|
+
try:
|
|
61
|
+
spec = model_registry.resolve("seedvr2", req.model)
|
|
62
|
+
except UnknownModelError as exc:
|
|
63
|
+
raise HTTPException(status_code=400, detail=str(exc)) # noqa: B904
|
|
64
|
+
try:
|
|
65
|
+
validate_upscale(req)
|
|
66
|
+
except ValidationError as exc:
|
|
67
|
+
raise HTTPException(status_code=422, detail=str(exc)) # noqa: B904
|
|
68
|
+
|
|
69
|
+
def thunk(): # type: ignore
|
|
70
|
+
return handle_upscale(ctx, req)
|
|
71
|
+
|
|
72
|
+
return await submit_and_maybe_wait(
|
|
73
|
+
ctx,
|
|
74
|
+
worker,
|
|
75
|
+
type="seedvr2",
|
|
76
|
+
params=req.gen_params() | {"model": spec.name, "mode": req.mode},
|
|
77
|
+
thunk=thunk,
|
|
78
|
+
mode=req.mode,
|
|
79
|
+
accept=accept,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
register_capability_endpoints(router, name="seedvr2", base_path="/v1/image/seedvr2")
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""``/v1/image/zimage/generate`` result payload (the Job ``result`` shape).
|
|
2
|
+
|
|
3
|
+
Mirrors the dict returned by ``capabilities/zimage/_models/zimage._store_image``
|
|
4
|
+
so the produced image result is self-describing in OpenAPI. It is an output-side
|
|
5
|
+
projection of the model result (not a model-coupled view), so it lives under
|
|
6
|
+
``api/image/zimage/_views``.
|
|
7
|
+
|
|
8
|
+
``ImageResponse`` is the sole public element; nested pieces stay private.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
from pydantic import BaseModel, Field
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class _Timings(BaseModel):
|
|
17
|
+
total_s: float = Field(
|
|
18
|
+
description="Wall-clock generation time in seconds (model run only)."
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ImageResponse(BaseModel):
|
|
23
|
+
"""Capability-specific ``result`` for a succeeded zimage generate job."""
|
|
24
|
+
|
|
25
|
+
model: str = Field(
|
|
26
|
+
description="Resolved model variant that produced the image (turbo | base)."
|
|
27
|
+
)
|
|
28
|
+
prompt: str = Field(description="The prompt used for the run.")
|
|
29
|
+
|
|
30
|
+
file_id: str = Field(
|
|
31
|
+
description=(
|
|
32
|
+
"Files-API id of the produced image. Fetch metadata at "
|
|
33
|
+
"GET /v1/files/{id} or bytes at /download. This is also the artifact "
|
|
34
|
+
"returned as raw bytes by a single-artifact sync call."
|
|
35
|
+
)
|
|
36
|
+
)
|
|
37
|
+
image_bytes: int = Field(description="Size of the produced image in bytes.")
|
|
38
|
+
|
|
39
|
+
width: int = Field(description="Width in pixels of the produced image.")
|
|
40
|
+
height: int = Field(description="Height in pixels of the produced image.")
|
|
41
|
+
|
|
42
|
+
params: dict[str, Any] = Field(
|
|
43
|
+
description=(
|
|
44
|
+
"Resolved parameters actually used for the run (model, prompt, seed, "
|
|
45
|
+
"width, height, steps, guidance, quantize, format, quality, loras), so "
|
|
46
|
+
"the result is reproducible."
|
|
47
|
+
)
|
|
48
|
+
)
|
|
49
|
+
timings: _Timings = Field(description="kiapi extension: server-side timing.")
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"""Image API (zimage): ``POST /v1/image/zimage/generate`` (JSON; sync or async)."""
|
|
2
|
+
|
|
3
|
+
from fastapi import APIRouter, Depends, HTTPException
|
|
4
|
+
from fastapi.responses import Response
|
|
5
|
+
|
|
6
|
+
from kiapi.api import (
|
|
7
|
+
REQUIRE_AUTH,
|
|
8
|
+
build_job_responses,
|
|
9
|
+
build_train_responses,
|
|
10
|
+
get_accept,
|
|
11
|
+
get_ctx,
|
|
12
|
+
get_worker,
|
|
13
|
+
register_capability_endpoints,
|
|
14
|
+
submit_and_maybe_wait,
|
|
15
|
+
)
|
|
16
|
+
from kiapi.capabilities.zimage import (
|
|
17
|
+
GenerateRequest,
|
|
18
|
+
TrainRequest,
|
|
19
|
+
ValidationError,
|
|
20
|
+
handle_generate,
|
|
21
|
+
handle_train,
|
|
22
|
+
validate_generate,
|
|
23
|
+
)
|
|
24
|
+
from kiapi.core.app import AppContext
|
|
25
|
+
from kiapi.core.file import FileIDRef
|
|
26
|
+
from kiapi.core.model import UnknownModelError, model_registry
|
|
27
|
+
from kiapi.core.worker import Worker
|
|
28
|
+
|
|
29
|
+
from ._views.image_response import ImageResponse
|
|
30
|
+
|
|
31
|
+
router = APIRouter(dependencies=REQUIRE_AUTH)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@router.post(
|
|
35
|
+
"/v1/image/zimage/generate",
|
|
36
|
+
responses=build_job_responses(
|
|
37
|
+
"image/png", "image/jpeg", "image/webp", result_model=ImageResponse
|
|
38
|
+
),
|
|
39
|
+
)
|
|
40
|
+
async def generate_image_endpoint(
|
|
41
|
+
req: GenerateRequest,
|
|
42
|
+
accept: str | None = Depends(get_accept),
|
|
43
|
+
ctx: AppContext = Depends(get_ctx),
|
|
44
|
+
worker: Worker = Depends(get_worker),
|
|
45
|
+
) -> Response:
|
|
46
|
+
"""Generate an image from a text prompt (Z-Image, text-to-image).
|
|
47
|
+
|
|
48
|
+
No input image — Z-Image is txt2img only. The same endpoint serves both
|
|
49
|
+
`sync` and `async` via `mode`. Variant defaults differ: `turbo` (default) is
|
|
50
|
+
distilled, few-step and fast; `base` is the full model — more steps and
|
|
51
|
+
guidance, higher quality but slower.
|
|
52
|
+
|
|
53
|
+
Sync content negotiation: a single image is produced, so unless the client
|
|
54
|
+
asks for JSON the raw image bytes are returned with `X-Kiapi-File-Id` /
|
|
55
|
+
`X-Kiapi-Job-Id` headers — `curl -o out.png` just works. With
|
|
56
|
+
`Accept: application/json` (or async) the Job JSON is returned, whose
|
|
57
|
+
`result` follows ImageResponse.
|
|
58
|
+
|
|
59
|
+
Any `loras` or a `quantize` differing from the resident model runs a one-off
|
|
60
|
+
transient model (slower, not reused). Async returns 202 immediately; poll
|
|
61
|
+
GET /v1/jobs/{job_id} and fetch the artifact via GET /v1/files/{file_id}.
|
|
62
|
+
"""
|
|
63
|
+
try:
|
|
64
|
+
spec = model_registry.resolve("zimage", req.model)
|
|
65
|
+
except UnknownModelError as exc:
|
|
66
|
+
raise HTTPException(status_code=400, detail=str(exc)) # noqa: B904
|
|
67
|
+
try:
|
|
68
|
+
validate_generate(req, variant=spec.name)
|
|
69
|
+
except ValidationError as exc:
|
|
70
|
+
raise HTTPException(status_code=422, detail=str(exc)) # noqa: B904
|
|
71
|
+
|
|
72
|
+
def thunk(): # type: ignore
|
|
73
|
+
return handle_generate(ctx, req)
|
|
74
|
+
|
|
75
|
+
return await submit_and_maybe_wait(
|
|
76
|
+
ctx,
|
|
77
|
+
worker,
|
|
78
|
+
type="zimage",
|
|
79
|
+
params=req.gen_params() | {"model": spec.name, "mode": req.mode},
|
|
80
|
+
thunk=thunk,
|
|
81
|
+
mode=req.mode,
|
|
82
|
+
accept=accept,
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@router.post("/v1/image/zimage/train", responses=build_train_responses())
|
|
87
|
+
async def train_zimage_endpoint(
|
|
88
|
+
req: TrainRequest,
|
|
89
|
+
ctx: AppContext = Depends(get_ctx),
|
|
90
|
+
worker: Worker = Depends(get_worker),
|
|
91
|
+
) -> Response:
|
|
92
|
+
"""Train a LoRA adapter on a captioned image set (Z-Image, always async).
|
|
93
|
+
|
|
94
|
+
Long-running, so this endpoint is always async: it returns 202 with a
|
|
95
|
+
job_id — poll GET /v1/jobs/{job_id}. The `dataset` is a Files-API ZIP whose
|
|
96
|
+
images each have a same-stem `.txt` caption. On success the job's `result`
|
|
97
|
+
holds `adapter_file_id` (the trained `.safetensors`, also the artifact),
|
|
98
|
+
`adapter_bytes`, `num_images`, the resolved `config`, `lora_targets`,
|
|
99
|
+
`checkpoint`, and `timings`; the adapter can then be passed back via `loras`
|
|
100
|
+
on generate."""
|
|
101
|
+
try:
|
|
102
|
+
spec = model_registry.resolve("zimage", req.model)
|
|
103
|
+
except UnknownModelError as exc:
|
|
104
|
+
raise HTTPException(status_code=400, detail=str(exc)) # noqa: B904
|
|
105
|
+
if (
|
|
106
|
+
isinstance(req.dataset, FileIDRef)
|
|
107
|
+
and ctx.file_store.get(req.dataset.file_id) is None
|
|
108
|
+
):
|
|
109
|
+
raise HTTPException(
|
|
110
|
+
status_code=400, detail=f"unknown dataset file_id {req.dataset.file_id!r}"
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
def thunk(): # type: ignore
|
|
114
|
+
return handle_train(ctx, req)
|
|
115
|
+
|
|
116
|
+
return await submit_and_maybe_wait(
|
|
117
|
+
ctx,
|
|
118
|
+
worker,
|
|
119
|
+
type="zimage-train",
|
|
120
|
+
params={
|
|
121
|
+
"model": spec.name,
|
|
122
|
+
"dataset": req.dataset.model_dump(mode="json"),
|
|
123
|
+
"num_epochs": req.num_epochs,
|
|
124
|
+
"lora_rank": req.lora_rank,
|
|
125
|
+
},
|
|
126
|
+
thunk=thunk,
|
|
127
|
+
mode="async",
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
register_capability_endpoints(router, name="zimage", base_path="/v1/image/zimage")
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from typing import Annotated
|
|
2
|
+
|
|
3
|
+
from fastapi import Path
|
|
4
|
+
|
|
5
|
+
from kiapi.core.job import JobID
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def get_job_id(
|
|
9
|
+
job_id: Annotated[
|
|
10
|
+
str,
|
|
11
|
+
Path(
|
|
12
|
+
pattern=r"^job_[0-9a-f]+$",
|
|
13
|
+
description="In-memory job id returned by async or sync inference requests.",
|
|
14
|
+
examples=["job_0123456789abcdef"],
|
|
15
|
+
),
|
|
16
|
+
],
|
|
17
|
+
) -> JobID:
|
|
18
|
+
return job_id
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from pydantic import BaseModel, Field
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class JobDeleteResponse(BaseModel):
|
|
5
|
+
deleted: bool = Field(
|
|
6
|
+
...,
|
|
7
|
+
description="True when the job was removed from the in-memory job store.",
|
|
8
|
+
examples=[True],
|
|
9
|
+
)
|
|
10
|
+
job_id: str = Field(
|
|
11
|
+
...,
|
|
12
|
+
description="Deleted job id.",
|
|
13
|
+
examples=["job_0123456789abcdef"],
|
|
14
|
+
)
|
|
15
|
+
was_running: bool = Field(
|
|
16
|
+
...,
|
|
17
|
+
description="True if the job was running when deleted. Running jobs cannot be interrupted; deletion only forgets the record.",
|
|
18
|
+
examples=[False],
|
|
19
|
+
)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from pydantic import BaseModel, Field
|
|
2
|
+
|
|
3
|
+
from kiapi.core.job import Job
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class JobListResponse(BaseModel):
|
|
7
|
+
object: str = Field(
|
|
8
|
+
default="list",
|
|
9
|
+
description="OpenAI-style list envelope marker.",
|
|
10
|
+
examples=["list"],
|
|
11
|
+
)
|
|
12
|
+
data: list[Job] = Field(
|
|
13
|
+
default_factory=list,
|
|
14
|
+
description="Jobs currently retained in the in-memory job store.",
|
|
15
|
+
)
|