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,140 @@
|
|
|
1
|
+
"""Handler for SeedVR2 image upscale via mflux."""
|
|
2
|
+
|
|
3
|
+
import gc
|
|
4
|
+
import time
|
|
5
|
+
from types import SimpleNamespace
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from PIL import Image
|
|
9
|
+
|
|
10
|
+
from kiapi.capabilities import attach_mflux_progress
|
|
11
|
+
from kiapi.core.file import FileStore
|
|
12
|
+
from kiapi.core.model import ModelSpec
|
|
13
|
+
from kiapi.core.workdir import create_work_dir
|
|
14
|
+
|
|
15
|
+
from .._views.upscale_params import UpscaleParams
|
|
16
|
+
|
|
17
|
+
FEATURES = {"image", "upscale"}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _variant(spec: ModelSpec) -> str:
|
|
21
|
+
return spec.name
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _repo_base(spec: ModelSpec) -> str:
|
|
25
|
+
base, _sep, _variant_name = spec.repo.partition("#")
|
|
26
|
+
return base
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _model_config(spec: ModelSpec) -> Any:
|
|
30
|
+
from mflux.models.common.config import ModelConfig # type: ignore
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
ModelConfig.seedvr2_7b() if _variant(spec) == "7b" else ModelConfig.seedvr2_3b()
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _resolution(value: int | str) -> int | Any:
|
|
38
|
+
if isinstance(value, int):
|
|
39
|
+
return value
|
|
40
|
+
if value.endswith("x"):
|
|
41
|
+
from mflux.utils.scale_factor import ScaleFactor # type: ignore
|
|
42
|
+
|
|
43
|
+
return ScaleFactor.parse(value)
|
|
44
|
+
return int(value)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def build_model(spec: ModelSpec, *, quantize: int | None) -> Any:
|
|
48
|
+
from mflux.models.seedvr2 import SeedVR2 # type: ignore
|
|
49
|
+
|
|
50
|
+
model_config = _model_config(spec)
|
|
51
|
+
return SeedVR2(
|
|
52
|
+
quantize=quantize, model_path=_repo_base(spec), model_config=model_config
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def load(spec: ModelSpec) -> SimpleNamespace:
|
|
57
|
+
from .._settings import settings_manager
|
|
58
|
+
|
|
59
|
+
quantize = settings_manager.get_settings().default_quantize
|
|
60
|
+
model = build_model(spec, quantize=quantize)
|
|
61
|
+
return SimpleNamespace(model=model, spec=spec, quantize=quantize)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _store_image(
|
|
65
|
+
generated: Any,
|
|
66
|
+
*,
|
|
67
|
+
params: UpscaleParams,
|
|
68
|
+
files: FileStore,
|
|
69
|
+
meta: dict[str, Any],
|
|
70
|
+
) -> dict[str, Any]:
|
|
71
|
+
pil = generated.image if hasattr(generated, "image") else generated
|
|
72
|
+
fmt = params.format
|
|
73
|
+
ext = "jpg" if fmt == "jpeg" else fmt
|
|
74
|
+
tmp_dir = create_work_dir("image/seedvr2")
|
|
75
|
+
out_path = tmp_dir / f"image.{ext}"
|
|
76
|
+
save_kwargs: dict[str, Any] = {}
|
|
77
|
+
if fmt in ("jpeg", "webp"):
|
|
78
|
+
save_kwargs["quality"] = params.quality
|
|
79
|
+
if fmt == "jpeg":
|
|
80
|
+
pil = pil.convert("RGB")
|
|
81
|
+
pil.save(out_path, format=fmt.upper(), **save_kwargs)
|
|
82
|
+
if not out_path.exists():
|
|
83
|
+
raise RuntimeError("upscale finished but no image file was produced")
|
|
84
|
+
rec = files.put_path(
|
|
85
|
+
out_path,
|
|
86
|
+
filename=f"seedvr2_{int(time.time())}.{ext}",
|
|
87
|
+
content_type=f"image/{fmt}",
|
|
88
|
+
meta=meta,
|
|
89
|
+
move=True,
|
|
90
|
+
)
|
|
91
|
+
return {"file_id": rec.file_id, "image_bytes": rec.size, **meta}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _upscale(model: Any, params: UpscaleParams, files: FileStore) -> dict[str, Any]:
|
|
95
|
+
resolution = _resolution(params.resolution)
|
|
96
|
+
with Image.open(params.image_path) as src:
|
|
97
|
+
input_size = src.size
|
|
98
|
+
|
|
99
|
+
t0 = time.time()
|
|
100
|
+
attach_mflux_progress(model)
|
|
101
|
+
image = model.generate_image(
|
|
102
|
+
seed=params.seed,
|
|
103
|
+
image_path=params.image_path,
|
|
104
|
+
resolution=resolution,
|
|
105
|
+
softness=params.softness,
|
|
106
|
+
)
|
|
107
|
+
total_s = round(time.time() - t0, 2)
|
|
108
|
+
|
|
109
|
+
pil = image.image if hasattr(image, "image") else image
|
|
110
|
+
output_size = pil.size
|
|
111
|
+
meta = {
|
|
112
|
+
"model": params.model,
|
|
113
|
+
"params": params.model_dump(exclude={"image_path"}),
|
|
114
|
+
"input_width": input_size[0],
|
|
115
|
+
"input_height": input_size[1],
|
|
116
|
+
"width": output_size[0],
|
|
117
|
+
"height": output_size[1],
|
|
118
|
+
"timings": {"total_s": total_s},
|
|
119
|
+
}
|
|
120
|
+
return _store_image(image, params=params, files=files, meta=meta)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def run(
|
|
124
|
+
payload: SimpleNamespace, params: UpscaleParams, files: FileStore
|
|
125
|
+
) -> dict[str, Any]:
|
|
126
|
+
return _upscale(payload.model, params, files)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def run_transient(
|
|
130
|
+
spec: ModelSpec, params: UpscaleParams, files: FileStore
|
|
131
|
+
) -> dict[str, Any]:
|
|
132
|
+
model = build_model(spec, quantize=params.quantize)
|
|
133
|
+
try:
|
|
134
|
+
return _upscale(model, params, files)
|
|
135
|
+
finally:
|
|
136
|
+
del model
|
|
137
|
+
gc.collect()
|
|
138
|
+
import mlx.core as mx
|
|
139
|
+
|
|
140
|
+
mx.clear_cache()
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""SeedVR2 service entry: resolve input image → run resident/transient model.
|
|
2
|
+
|
|
3
|
+
Body of the seedvr2 job's worker-thread thunk. Stores the upscaled image in the
|
|
4
|
+
global file store; the job's ``artifacts`` is the produced file_id.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from kiapi.capabilities import resolve_file_ref
|
|
8
|
+
from kiapi.core.app import AppContext
|
|
9
|
+
from kiapi.core.file import FileID
|
|
10
|
+
from kiapi.core.job import JobResult
|
|
11
|
+
from kiapi.core.model import model_registry
|
|
12
|
+
|
|
13
|
+
from .._settings import settings_manager
|
|
14
|
+
from .._views.upscale_request import UpscaleRequest
|
|
15
|
+
from .is_quantize_override import is_quantize_override
|
|
16
|
+
from .resolve_upscale_params import resolve_upscale_params
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def handle_upscale(
|
|
20
|
+
ctx: AppContext, req: UpscaleRequest
|
|
21
|
+
) -> tuple[JobResult, list[FileID]]:
|
|
22
|
+
settings = settings_manager.get_settings()
|
|
23
|
+
spec = model_registry.resolve("seedvr2", req.model)
|
|
24
|
+
ctx.ensure_model_ready(spec)
|
|
25
|
+
image = resolve_file_ref(ctx.file_store, req.image, kind="image")
|
|
26
|
+
override = is_quantize_override(settings, req)
|
|
27
|
+
params = resolve_upscale_params(
|
|
28
|
+
settings,
|
|
29
|
+
req,
|
|
30
|
+
variant=spec.name,
|
|
31
|
+
image_file_id=image.file_id,
|
|
32
|
+
image_path=image.path,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
if override:
|
|
36
|
+
ctx.memory_manager.reserve(spec.weight_gb + spec.peak_headroom_gb)
|
|
37
|
+
result = spec.module.run_transient(spec, params, ctx.file_store)
|
|
38
|
+
else:
|
|
39
|
+
payload = ctx.memory_manager.acquire(spec)
|
|
40
|
+
result = spec.module.run(payload, params, ctx.file_store)
|
|
41
|
+
|
|
42
|
+
return result, [result["file_id"]]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""Decide whether a request's quantize differs from the default.
|
|
2
|
+
|
|
3
|
+
A True result means the resident model (quantized at its default) can't serve the
|
|
4
|
+
request, so ``handle_upscale`` runs a one-off transient model instead.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .._settings import SeedVR2Settings
|
|
8
|
+
from .._views.upscale_request import UpscaleRequest
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def is_quantize_override(settings: SeedVR2Settings, req: UpscaleRequest) -> bool:
|
|
12
|
+
return req.quantize is not None and req.quantize != settings.default_quantize
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Merge an upscale request with settings defaults into the complete UpscaleParams."""
|
|
2
|
+
|
|
3
|
+
import random
|
|
4
|
+
|
|
5
|
+
from .._settings import SeedVR2Settings
|
|
6
|
+
from .._views.upscale_params import UpscaleParams
|
|
7
|
+
from .._views.upscale_request import UpscaleRequest
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def resolve_upscale_params(
|
|
11
|
+
settings: SeedVR2Settings,
|
|
12
|
+
req: UpscaleRequest,
|
|
13
|
+
*,
|
|
14
|
+
variant: str,
|
|
15
|
+
image_file_id: str,
|
|
16
|
+
image_path: str,
|
|
17
|
+
) -> UpscaleParams:
|
|
18
|
+
return UpscaleParams(
|
|
19
|
+
model=variant,
|
|
20
|
+
image_file_id=image_file_id,
|
|
21
|
+
image_path=image_path,
|
|
22
|
+
resolution=req.resolution,
|
|
23
|
+
softness=req.softness,
|
|
24
|
+
seed=req.seed if req.seed is not None else random.randint(0, 2**31 - 1),
|
|
25
|
+
quantize=req.quantize
|
|
26
|
+
if req.quantize is not None
|
|
27
|
+
else settings.default_quantize,
|
|
28
|
+
format=req.format,
|
|
29
|
+
quality=req.quality,
|
|
30
|
+
)
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""SeedVR2 capability defaults + caps, read from ``KIAPI_SEEDVR2_`` env vars."""
|
|
2
|
+
|
|
3
|
+
from pydantic import Field
|
|
4
|
+
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
5
|
+
from pydantic_settings_manager import SettingsManager
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SeedVR2Settings(BaseSettings):
|
|
9
|
+
"""Settings for the SeedVR2 upscaling model, scale factors, and resolution limits."""
|
|
10
|
+
|
|
11
|
+
model_config = SettingsConfigDict(
|
|
12
|
+
env_prefix="KIAPI_SEEDVR2_",
|
|
13
|
+
extra="ignore",
|
|
14
|
+
protected_namespaces=(),
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
model_repo: str = Field(
|
|
18
|
+
default="numz/SeedVR2_comfyUI",
|
|
19
|
+
title="SeedVR2 model repo",
|
|
20
|
+
description="Hugging Face repo ID for the SeedVR2 model used for video and image upscaling.",
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
# --------------------------------------------------
|
|
24
|
+
# upscale
|
|
25
|
+
# --------------------------------------------------
|
|
26
|
+
|
|
27
|
+
default_resolution: str = Field(
|
|
28
|
+
default="2x",
|
|
29
|
+
title="Default output resolution",
|
|
30
|
+
description=(
|
|
31
|
+
"Upscaling resolution used when a request omits resolution.\n"
|
|
32
|
+
"Use a scale notation such as 2x, or another resolution value "
|
|
33
|
+
"accepted by the implementation."
|
|
34
|
+
),
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
default_softness: float = Field(
|
|
38
|
+
default=0.0,
|
|
39
|
+
title="Default softness",
|
|
40
|
+
description=(
|
|
41
|
+
"Correction amount used when a request omits softness.\n"
|
|
42
|
+
"0.0 is the baseline; higher values produce softer results."
|
|
43
|
+
),
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
default_quantize: int | None = Field(
|
|
47
|
+
default=8,
|
|
48
|
+
title="Default quantization bits",
|
|
49
|
+
description=(
|
|
50
|
+
"Default quantization bit count used when loading the SeedVR2 model.\n"
|
|
51
|
+
"Use a bit count such as 8, or None to disable quantization."
|
|
52
|
+
),
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
max_scale: float = Field(
|
|
56
|
+
default=4.0,
|
|
57
|
+
title="Maximum scale factor",
|
|
58
|
+
description="Upper limit for the upscaling scale factor accepted in a request.",
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
max_resolution: int = Field(
|
|
62
|
+
default=2048,
|
|
63
|
+
title="Maximum output resolution",
|
|
64
|
+
description="Upper pixel limit for the output width or height accepted in a request.",
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
min_resolution: int = Field(
|
|
68
|
+
default=16,
|
|
69
|
+
title="Minimum output resolution",
|
|
70
|
+
description="Lower pixel limit for the output width or height accepted in a request.",
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
settings_manager = SettingsManager(SeedVR2Settings)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""The complete contract for one SeedVR2 image upscale run.
|
|
2
|
+
|
|
3
|
+
Built from settings + request by ``resolve_upscale_params``; the model needs
|
|
4
|
+
nothing else to produce the image and its metadata. ``image_path`` is the locally
|
|
5
|
+
resolved input file, kept out of the recorded metadata in favour of
|
|
6
|
+
``image_file_id``. ``resolution`` keeps the request value (an int shortest-edge
|
|
7
|
+
target or a scale like ``"2x"``); the model layer parses the scale form.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from typing import Literal
|
|
11
|
+
|
|
12
|
+
from pydantic import BaseModel
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class UpscaleParams(BaseModel):
|
|
16
|
+
kind: Literal["upscale"] = "upscale"
|
|
17
|
+
model: str
|
|
18
|
+
|
|
19
|
+
image_file_id: str
|
|
20
|
+
image_path: str
|
|
21
|
+
resolution: int | str
|
|
22
|
+
softness: float
|
|
23
|
+
seed: int
|
|
24
|
+
quantize: int | None
|
|
25
|
+
|
|
26
|
+
format: Literal["png", "jpeg", "webp"]
|
|
27
|
+
quality: int
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""SeedVR2 upscale request model.
|
|
2
|
+
|
|
3
|
+
Image → upscaled image (diffusion super-resolution). One endpoint serves both
|
|
4
|
+
sync and async via ``mode``. The input image is referenced by ``image``
|
|
5
|
+
(FileRef). A ``quantize`` override runs a one-off transient model; otherwise the
|
|
6
|
+
resident model is used.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from typing import Literal
|
|
10
|
+
|
|
11
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
12
|
+
|
|
13
|
+
from kiapi.core.file import FileRef
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class UpscaleRequest(BaseModel):
|
|
17
|
+
model_config = ConfigDict(extra="allow")
|
|
18
|
+
|
|
19
|
+
model: str | None = Field(
|
|
20
|
+
default=None,
|
|
21
|
+
description=(
|
|
22
|
+
"Model variant (see GET /v1/image/seedvr2/models). Omit for the "
|
|
23
|
+
"default `3b`; `7b` is the larger, higher-quality variant. Aliases "
|
|
24
|
+
"`seedvr2-3b` / `seedvr2-7b` are also accepted."
|
|
25
|
+
),
|
|
26
|
+
)
|
|
27
|
+
mode: Literal["sync", "async"] = Field(
|
|
28
|
+
default="sync",
|
|
29
|
+
description=(
|
|
30
|
+
"`sync` waits for the image (504 on timeout); `async` returns 202 with "
|
|
31
|
+
"a job_id immediately — poll GET /v1/jobs/{job_id}."
|
|
32
|
+
),
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
image: FileRef = Field(
|
|
36
|
+
...,
|
|
37
|
+
description=(
|
|
38
|
+
"Input image to upscale (Files-API file id, http(s) URL, or data URL)."
|
|
39
|
+
),
|
|
40
|
+
)
|
|
41
|
+
resolution: int | str = Field(
|
|
42
|
+
default="2x",
|
|
43
|
+
description=(
|
|
44
|
+
"Target size: an integer shortest-edge pixel target (16..2048), or a "
|
|
45
|
+
"scale factor string like `2x` / `1.5x` (> 0 and at most 4.0x). "
|
|
46
|
+
"Default `2x`."
|
|
47
|
+
),
|
|
48
|
+
)
|
|
49
|
+
softness: float = Field(
|
|
50
|
+
default=0.0,
|
|
51
|
+
ge=0.0,
|
|
52
|
+
le=1.0,
|
|
53
|
+
description=(
|
|
54
|
+
"Detail smoothing in 0..1. 0 keeps maximum sharpness; higher values "
|
|
55
|
+
"soften the result. Default 0.0."
|
|
56
|
+
),
|
|
57
|
+
)
|
|
58
|
+
seed: int | None = Field(
|
|
59
|
+
default=None,
|
|
60
|
+
description=(
|
|
61
|
+
"Random seed for reproducibility. Omit for a random seed (the resolved "
|
|
62
|
+
"seed is recorded in the result `params`)."
|
|
63
|
+
),
|
|
64
|
+
)
|
|
65
|
+
quantize: int | None = Field(
|
|
66
|
+
default=None,
|
|
67
|
+
description=(
|
|
68
|
+
"Quantization bits, one of {3, 4, 5, 6, 8}. Omit to use the resident "
|
|
69
|
+
"model's quantization (q8). A differing value builds a one-off "
|
|
70
|
+
"transient model (slower, not reused)."
|
|
71
|
+
),
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
format: Literal["png", "jpeg", "webp"] = Field(
|
|
75
|
+
default="png",
|
|
76
|
+
description="Output image encoding for the produced file.",
|
|
77
|
+
)
|
|
78
|
+
quality: int = Field(
|
|
79
|
+
default=90,
|
|
80
|
+
ge=1,
|
|
81
|
+
le=100,
|
|
82
|
+
description="Encoder quality 1..100 (used for jpeg/webp; ignored for png).",
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
def gen_params(self) -> dict:
|
|
86
|
+
return {
|
|
87
|
+
"image": self.image.model_dump(mode="json"),
|
|
88
|
+
"resolution": self.resolution,
|
|
89
|
+
"softness": self.softness,
|
|
90
|
+
"seed": self.seed,
|
|
91
|
+
"quantize": self.quantize,
|
|
92
|
+
"format": self.format,
|
|
93
|
+
"quality": self.quality,
|
|
94
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# web
|
|
2
|
+
|
|
3
|
+
**日本語**
|
|
4
|
+
|
|
5
|
+
SearXNG と Crawl4AI を kiapi から使うための **web capability** です。
|
|
6
|
+
|
|
7
|
+
- **search**: SearXNG で Web 検索し、JSON の検索結果を返す。
|
|
8
|
+
- **fetch**: Crawl4AI で単一 URL をレンダリングし、Markdown または PDF を返す。
|
|
9
|
+
|
|
10
|
+
web は、SearXNG / Crawl4AI を **resident subprocess model** として扱います。
|
|
11
|
+
初回リクエスト時に `docker run --rm` を foreground subprocess として起動し、
|
|
12
|
+
空いている localhost port を割り当て、以降は resident backend として再利用します。
|
|
13
|
+
search / fetch も Job として single-flight worker に投入されます。
|
|
14
|
+
|
|
15
|
+
## API
|
|
16
|
+
|
|
17
|
+
| Endpoint | Name | Description |
|
|
18
|
+
|---|---|---|
|
|
19
|
+
| `POST /v1/web/search` | Web 検索 | SearXNG の `/search?format=json` を呼び、検索結果を返す。 |
|
|
20
|
+
| `GET /v1/web/fetch?url=...` | ページ取得 | Crawl4AI で HTML ページをレンダリングし、Markdown または PDF を返す。 |
|
|
21
|
+
| `GET /v1/web/openapi.json` | OpenAPI | 詳細な入出力仕様、使い方、TIPS を返す。 |
|
|
22
|
+
|
|
23
|
+
## API Docs
|
|
24
|
+
|
|
25
|
+
- [OpenAPI JSON](https://kiarina.github.io/kiapi/v1/web/openapi.json)
|
|
26
|
+
- [Swagger UI](https://kiarina.github.io/kiapi/v1/web/docs.html)
|
|
27
|
+
- [ReDoc](https://kiarina.github.io/kiapi/v1/web/redoc.html)
|
|
28
|
+
|
|
29
|
+
## Dependencies
|
|
30
|
+
|
|
31
|
+
| バックエンド | License | Description |
|
|
32
|
+
|---|---|---|
|
|
33
|
+
| [SearXNG](https://github.com/searxng/searxng) | AGPL-3.0 | メタ検索エンジン。kiapi が `docker run --rm` subprocess として起動する。 |
|
|
34
|
+
| [Crawl4AI](https://github.com/unclecode/crawl4ai) | Apache-2.0 | ブラウザレンダリング + Markdown/PDF 変換。kiapi が `docker run --rm` subprocess として起動する。 |
|
|
35
|
+
|
|
36
|
+
## Notes
|
|
37
|
+
|
|
38
|
+
- **resident subprocess model**:
|
|
39
|
+
SearXNG と Crawl4AI は `ModelSpec(family="web")` として登録されます。`load()` は
|
|
40
|
+
foreground の `docker run --rm` subprocess を起動し、`release()` は subprocess を停止します。
|
|
41
|
+
- **Job / single-flight**:
|
|
42
|
+
search / fetch はどちらも Job として single-flight worker で実行されます。
|
|
43
|
+
- **search の query**:
|
|
44
|
+
`query` は SearXNG へそのまま渡します。`site:`、`!wp`、`!images`、`:ja` などの
|
|
45
|
+
SearXNG インライン演算子をそのまま使えます。
|
|
46
|
+
- **search の結果数**:
|
|
47
|
+
SearXNG 自体に `max_results` はないため、kiapi が 1 ページ分の結果を受け取ったあと
|
|
48
|
+
client-side で切り詰めます。既定は `KIAPI_WEB_DEFAULT_MAX_RESULTS=10` です。
|
|
49
|
+
- **fetch の対象**:
|
|
50
|
+
`fetch` は HTML ページ専用です。画像、音声、動画、PDF、その他バイナリ URL は
|
|
51
|
+
バイト列として返さず、`not_html` で拒否します。
|
|
52
|
+
- **fetch の空コンテンツ保護**:
|
|
53
|
+
HTML として到達できても、レンダリング後に抽出できる本文がない場合は
|
|
54
|
+
`empty_content` を返します。
|
|
55
|
+
- **fetch の成果物**:
|
|
56
|
+
fetch の raw body は Files API に保存され、レスポンスヘッダに `X-Kiapi-File-Id` と
|
|
57
|
+
`X-Kiapi-Job-Id` が付きます。
|
|
58
|
+
- **主なエラー**:
|
|
59
|
+
validation は 422、`fetch` の `unsupported_accept` は 406、バックエンド到達不能や
|
|
60
|
+
HTTP エラーは 502、timeout は 504 です。
|
|
61
|
+
- **非決定性**:
|
|
62
|
+
`search` はライブの検索エンジン結果に依存するため、同じクエリでも結果は変わります。
|
|
63
|
+
|
|
64
|
+
## Settings
|
|
65
|
+
|
|
66
|
+
| 変数 | 既定値 | 意味 |
|
|
67
|
+
|---|---|---|
|
|
68
|
+
| `KIAPI_WEB_SEARCH_IMAGE` | `searxng/searxng:latest` | SearXNG backend の Docker image。 |
|
|
69
|
+
| `KIAPI_WEB_FETCH_IMAGE` | `unclecode/crawl4ai:latest` | Crawl4AI backend の Docker image。 |
|
|
70
|
+
| `KIAPI_WEB_BACKEND_READY_TIMEOUT_S` | `60.0` | backend subprocess の起動待ち timeout。 |
|
|
71
|
+
| `KIAPI_WEB_BACKEND_LOG_DIR` | `/tmp/kiapi/logs/web` | backend subprocess の stdout/stderr log 出力先。 |
|
|
72
|
+
| `KIAPI_WEB_TIMEOUT_S` | `10.0` | SearXNG への HTTP timeout。 |
|
|
73
|
+
| `KIAPI_WEB_DEFAULT_CATEGORIES` | `null` | `categories` 省略時の既定。`null` は SearXNG に任せる。 |
|
|
74
|
+
| `KIAPI_WEB_DEFAULT_ENGINES` | `null` | `engines` 省略時の既定。`null` は SearXNG に任せる。 |
|
|
75
|
+
| `KIAPI_WEB_DEFAULT_LANGUAGE` | `null` | `language` 省略時の既定。 |
|
|
76
|
+
| `KIAPI_WEB_DEFAULT_SAFESEARCH` | `null` | `safesearch` 省略時の既定。 |
|
|
77
|
+
| `KIAPI_WEB_DEFAULT_MAX_RESULTS` | `10` | `max_results` 省略時の client-side 切り詰め数。 |
|
|
78
|
+
| `KIAPI_WEB_FETCH_TIMEOUT_S` | `30.0` | Crawl4AI への HTTP timeout。 |
|
|
79
|
+
| `KIAPI_WEB_FETCH_MIN_CONTENT_CHARS` | `1` | これ未満の Markdown を `empty_content` とみなす。 |
|
|
80
|
+
| `KIAPI_WEB_FETCH_FILTER` | `fit` | Crawl4AI `/md` の filter。`fit` は readability-pruned、`raw` は DOM 全体。 |
|
|
81
|
+
| `KIAPI_WEB_FETCH_CACHE` | `0` | Crawl4AI `/md` の cache 指定。 |
|
|
82
|
+
|
|
83
|
+
## Quickstart
|
|
84
|
+
|
|
85
|
+
Docker Desktop など、`docker run` が使える状態で kiapi を起動します。SearXNG と
|
|
86
|
+
Crawl4AI は初回リクエスト時に自動起動されます。
|
|
87
|
+
|
|
88
|
+
### search — Web 検索
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
jq -n \
|
|
92
|
+
'{
|
|
93
|
+
query: "apple",
|
|
94
|
+
max_results: 5
|
|
95
|
+
}' |
|
|
96
|
+
curl -sS -X POST http://localhost:${PORT:-8000}/v1/web/search \
|
|
97
|
+
-H 'Content-Type: application/json' \
|
|
98
|
+
--data-binary @- |
|
|
99
|
+
jq .
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
カテゴリ、エンジン、言語、新しさで絞り込む:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
jq -n \
|
|
106
|
+
'{
|
|
107
|
+
query: "mlx quantization",
|
|
108
|
+
categories: ["it"],
|
|
109
|
+
engines: ["google", "duckduckgo"],
|
|
110
|
+
language: "en",
|
|
111
|
+
time_range: "month",
|
|
112
|
+
max_results: 10
|
|
113
|
+
}' |
|
|
114
|
+
curl -sS -X POST http://localhost:${PORT:-8000}/v1/web/search \
|
|
115
|
+
-H 'Content-Type: application/json' \
|
|
116
|
+
--data-binary @- |
|
|
117
|
+
jq .
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
SearXNG のインライン演算子を使う:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
jq -n \
|
|
124
|
+
'{
|
|
125
|
+
query: "site:github.com kiapi"
|
|
126
|
+
}' |
|
|
127
|
+
curl -sS -X POST http://localhost:${PORT:-8000}/v1/web/search \
|
|
128
|
+
-H 'Content-Type: application/json' \
|
|
129
|
+
--data-binary @- |
|
|
130
|
+
jq '.results[] | {title, url}'
|
|
131
|
+
|
|
132
|
+
jq -n \
|
|
133
|
+
'{
|
|
134
|
+
query: "!wp :ja Python"
|
|
135
|
+
}' |
|
|
136
|
+
curl -sS -X POST http://localhost:${PORT:-8000}/v1/web/search \
|
|
137
|
+
-H 'Content-Type: application/json' \
|
|
138
|
+
--data-binary @- |
|
|
139
|
+
jq '.results[] | {title, url}'
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
レスポンスには `query`、`results`、`answers`、`infoboxes`、`suggestions`、
|
|
143
|
+
`unresponsive_engines` が含まれます。
|
|
144
|
+
|
|
145
|
+
### fetch — Markdown 取得
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
curl -sS -o page.md \
|
|
149
|
+
"http://localhost:${PORT:-8000}/v1/web/fetch?url=https://github.com/kiarina"
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
`Accept: text/markdown` は既定なので省略できます。kiapi が検出した upstream の
|
|
153
|
+
content-type は `X-Kiapi-Content-Type` ヘッダで確認できます。
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
curl -sS -D - -o page.md \
|
|
157
|
+
"http://localhost:${PORT:-8000}/v1/web/fetch?url=https://github.com/kiarina" \
|
|
158
|
+
| grep -i x-kiapi
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### fetch — PDF 取得
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
curl -sS -H 'Accept: application/pdf' -o page.pdf \
|
|
165
|
+
"http://localhost:${PORT:-8000}/v1/web/fetch?url=https://github.com/kiarina"
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### fetch — 非 HTML URL の拒否
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
curl -sS \
|
|
172
|
+
"http://localhost:${PORT:-8000}/v1/web/fetch?url=https://www-media.blazeworks.jp/content/icon/miineko.png" \
|
|
173
|
+
| jq .
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
レスポンス例:
|
|
177
|
+
|
|
178
|
+
```json
|
|
179
|
+
{
|
|
180
|
+
"detail": {
|
|
181
|
+
"error": "not_html",
|
|
182
|
+
"message": "Resource is not an HTML page (content-type: image/png).",
|
|
183
|
+
"url": "https://www-media.blazeworks.jp/content/icon/miineko.png",
|
|
184
|
+
"content_type": "image/png"
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
```
|