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,46 @@
|
|
|
1
|
+
"""Qwen Image generate service entry (worker-thread thunk body)."""
|
|
2
|
+
|
|
3
|
+
from kiapi.capabilities import get_file_path
|
|
4
|
+
from kiapi.core.app import AppContext
|
|
5
|
+
from kiapi.core.file import FileID
|
|
6
|
+
from kiapi.core.job import JobResult
|
|
7
|
+
from kiapi.core.model import model_registry
|
|
8
|
+
|
|
9
|
+
from .._settings import settings_manager
|
|
10
|
+
from .._views.generate_request import GenerateRequest
|
|
11
|
+
from .is_quantize_override import is_quantize_override
|
|
12
|
+
from .resolve_generate_params import resolve_generate_params
|
|
13
|
+
from .resolve_lora_params import resolve_lora_params
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def handle_generate(
|
|
17
|
+
ctx: AppContext, req: GenerateRequest
|
|
18
|
+
) -> tuple[JobResult, list[FileID]]:
|
|
19
|
+
settings = settings_manager.get_settings()
|
|
20
|
+
spec = model_registry.resolve("qwen", req.model or "image")
|
|
21
|
+
ctx.ensure_model_ready(spec)
|
|
22
|
+
init_image_path = (
|
|
23
|
+
get_file_path(ctx.file_store, req.init_image, kind="init_image")
|
|
24
|
+
if req.init_image is not None
|
|
25
|
+
else None
|
|
26
|
+
)
|
|
27
|
+
lora_params = resolve_lora_params(ctx, req.loras)
|
|
28
|
+
override = is_quantize_override(settings, req)
|
|
29
|
+
params = resolve_generate_params(
|
|
30
|
+
settings, req, variant=spec.name, init_image_path=init_image_path
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
if lora_params.paths or override:
|
|
34
|
+
ctx.memory_manager.reserve(spec.weight_gb + spec.peak_headroom_gb)
|
|
35
|
+
result = spec.module.run_generate_transient(
|
|
36
|
+
spec,
|
|
37
|
+
params,
|
|
38
|
+
ctx.file_store,
|
|
39
|
+
lora_paths=lora_params.paths,
|
|
40
|
+
lora_scales=lora_params.scales,
|
|
41
|
+
)
|
|
42
|
+
else:
|
|
43
|
+
payload = ctx.memory_manager.acquire(spec)
|
|
44
|
+
result = spec.module.run_generate(payload, params, ctx.file_store)
|
|
45
|
+
|
|
46
|
+
return result, [result["file_id"]]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""Decide whether a request's quantize differs from the variant default.
|
|
2
|
+
|
|
3
|
+
A True result means the resident model (quantized at its default) can't serve the
|
|
4
|
+
request, so ``handle_*`` runs a one-off transient model instead.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .._settings import QwenSettings
|
|
8
|
+
from .._views.edit_request import EditRequest
|
|
9
|
+
from .._views.generate_request import GenerateRequest
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def is_quantize_override(
|
|
13
|
+
settings: QwenSettings, req: GenerateRequest | EditRequest
|
|
14
|
+
) -> bool:
|
|
15
|
+
return req.quantize is not None and req.quantize != settings.default_quantize
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""Merge an edit request with settings defaults into the complete EditParams."""
|
|
2
|
+
|
|
3
|
+
import random
|
|
4
|
+
|
|
5
|
+
from .._settings import QwenSettings
|
|
6
|
+
from .._views.edit_params import EditParams
|
|
7
|
+
from .._views.edit_request import EditRequest
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def resolve_edit_params(
|
|
11
|
+
settings: QwenSettings,
|
|
12
|
+
req: EditRequest,
|
|
13
|
+
*,
|
|
14
|
+
variant: str,
|
|
15
|
+
image_paths: list[str],
|
|
16
|
+
) -> EditParams:
|
|
17
|
+
return EditParams(
|
|
18
|
+
model=variant,
|
|
19
|
+
prompt=req.prompt,
|
|
20
|
+
negative_prompt=req.negative_prompt,
|
|
21
|
+
image_file_ids=[],
|
|
22
|
+
image_paths=image_paths,
|
|
23
|
+
seed=req.seed if req.seed is not None else random.randint(0, 2**31 - 1),
|
|
24
|
+
width=req.width if req.width is not None else settings.default_width,
|
|
25
|
+
height=req.height if req.height is not None else settings.default_height,
|
|
26
|
+
steps=req.steps if req.steps is not None else settings.edit_steps,
|
|
27
|
+
guidance=req.guidance if req.guidance is not None else settings.edit_guidance,
|
|
28
|
+
quantize=req.quantize
|
|
29
|
+
if req.quantize is not None
|
|
30
|
+
else settings.default_quantize,
|
|
31
|
+
scheduler=req.scheduler,
|
|
32
|
+
format=req.format,
|
|
33
|
+
quality=req.quality,
|
|
34
|
+
loras=req.loras,
|
|
35
|
+
)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""Merge a generate request with settings defaults into the complete GenerateParams."""
|
|
2
|
+
|
|
3
|
+
import random
|
|
4
|
+
|
|
5
|
+
from .._settings import QwenSettings
|
|
6
|
+
from .._views.generate_params import GenerateParams
|
|
7
|
+
from .._views.generate_request import GenerateRequest
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def resolve_generate_params(
|
|
11
|
+
settings: QwenSettings,
|
|
12
|
+
req: GenerateRequest,
|
|
13
|
+
*,
|
|
14
|
+
variant: str,
|
|
15
|
+
init_image_path: str | None,
|
|
16
|
+
) -> GenerateParams:
|
|
17
|
+
return GenerateParams(
|
|
18
|
+
kind="img2img" if init_image_path is not None else "txt2img",
|
|
19
|
+
model=variant,
|
|
20
|
+
prompt=req.prompt,
|
|
21
|
+
negative_prompt=req.negative_prompt,
|
|
22
|
+
init_image_file_id=None,
|
|
23
|
+
image_path=init_image_path,
|
|
24
|
+
image_strength=req.image_strength,
|
|
25
|
+
seed=req.seed if req.seed is not None else random.randint(0, 2**31 - 1),
|
|
26
|
+
width=req.width if req.width is not None else settings.default_width,
|
|
27
|
+
height=req.height if req.height is not None else settings.default_height,
|
|
28
|
+
steps=req.steps if req.steps is not None else settings.generate_steps,
|
|
29
|
+
guidance=req.guidance
|
|
30
|
+
if req.guidance is not None
|
|
31
|
+
else settings.generate_guidance,
|
|
32
|
+
quantize=req.quantize
|
|
33
|
+
if req.quantize is not None
|
|
34
|
+
else settings.default_quantize,
|
|
35
|
+
scheduler=req.scheduler,
|
|
36
|
+
format=req.format,
|
|
37
|
+
quality=req.quality,
|
|
38
|
+
loras=req.loras,
|
|
39
|
+
)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from collections.abc import Iterable
|
|
2
|
+
from dataclasses import dataclass, field
|
|
3
|
+
|
|
4
|
+
from kiapi.capabilities import get_file_path
|
|
5
|
+
from kiapi.core.app import AppContext
|
|
6
|
+
|
|
7
|
+
from .._schemas.lora_ref import LoraRef
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass
|
|
11
|
+
class LoraParams:
|
|
12
|
+
paths: list[str] = field(default_factory=list)
|
|
13
|
+
scales: list[float] = field(default_factory=list)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def resolve_lora_params(ctx: AppContext, loras: Iterable[LoraRef]) -> LoraParams:
|
|
17
|
+
params = LoraParams()
|
|
18
|
+
|
|
19
|
+
for lr in loras:
|
|
20
|
+
params.paths.append(get_file_path(ctx.file_store, lr.file, kind="lora"))
|
|
21
|
+
params.scales.append(lr.scale)
|
|
22
|
+
|
|
23
|
+
return params
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from kiapi.capabilities import ValidationError
|
|
2
|
+
|
|
3
|
+
from .._settings import QwenSettings
|
|
4
|
+
from .._views.edit_request import EditRequest
|
|
5
|
+
from .._views.generate_request import GenerateRequest
|
|
6
|
+
|
|
7
|
+
_MULTIPLE = 16
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def validate_common(
|
|
11
|
+
req: GenerateRequest | EditRequest, settings: QwenSettings, *, role: str
|
|
12
|
+
) -> None:
|
|
13
|
+
width = req.width if req.width is not None else settings.default_width
|
|
14
|
+
height = req.height if req.height is not None else settings.default_height
|
|
15
|
+
|
|
16
|
+
if width <= 0 or height <= 0:
|
|
17
|
+
raise ValidationError("width and height must be positive")
|
|
18
|
+
if width % _MULTIPLE or height % _MULTIPLE:
|
|
19
|
+
raise ValidationError(f"width and height must be multiples of {_MULTIPLE}")
|
|
20
|
+
if width > settings.max_width or height > settings.max_height:
|
|
21
|
+
raise ValidationError(
|
|
22
|
+
f"size {width}x{height} exceeds the cap {settings.max_width}x{settings.max_height}"
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
default_steps = settings.edit_steps if role == "edit" else settings.generate_steps
|
|
26
|
+
steps = req.steps if req.steps is not None else default_steps
|
|
27
|
+
if steps < 1 or steps > settings.max_steps:
|
|
28
|
+
raise ValidationError(f"steps must be in 1..{settings.max_steps}")
|
|
29
|
+
if req.quantize is not None and req.quantize not in (3, 4, 5, 6, 8):
|
|
30
|
+
raise ValidationError("quantize must be one of 3, 4, 5, 6, 8")
|
|
31
|
+
if len(req.loras) > settings.max_loras:
|
|
32
|
+
raise ValidationError(f"at most {settings.max_loras} loras may be applied")
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""A single LoRA adapter reference (file + scale) applied to a qwen run."""
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel, Field
|
|
4
|
+
|
|
5
|
+
from kiapi.core.file import FileRef
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class LoraRef(BaseModel):
|
|
9
|
+
"""One LoRA adapter to apply, by Files-API reference and blend scale.
|
|
10
|
+
|
|
11
|
+
Any lora forces a one-off transient model (slower, not reused). Up to 4 may
|
|
12
|
+
be passed in a request's ``loras`` list.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
file: FileRef = Field(
|
|
16
|
+
description=(
|
|
17
|
+
"The LoRA adapter (`.safetensors`) to apply, as a Files-API file id, "
|
|
18
|
+
"http(s) URL, or data URL."
|
|
19
|
+
),
|
|
20
|
+
)
|
|
21
|
+
scale: float = Field(
|
|
22
|
+
default=1.0,
|
|
23
|
+
description=(
|
|
24
|
+
"Blend strength for this adapter. 1.0 applies it at full weight; lower "
|
|
25
|
+
"values weaken its effect, higher values exaggerate it."
|
|
26
|
+
),
|
|
27
|
+
)
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"""Qwen Image capability defaults + caps, read from ``KIAPI_QWEN_`` 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 QwenSettings(BaseSettings):
|
|
9
|
+
"""Settings for Qwen Image models, generation defaults, and LoRA limits."""
|
|
10
|
+
|
|
11
|
+
model_config = SettingsConfigDict(
|
|
12
|
+
env_prefix="KIAPI_QWEN_",
|
|
13
|
+
extra="ignore",
|
|
14
|
+
protected_namespaces=(),
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
image_model: str = Field(
|
|
18
|
+
default="Qwen/Qwen-Image",
|
|
19
|
+
title="Image generation model repo",
|
|
20
|
+
description="Hugging Face repo ID used for Qwen Image text-to-image generation.",
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
edit_model: str = Field(
|
|
24
|
+
default="Qwen/Qwen-Image-Edit-2509",
|
|
25
|
+
title="Image editing model repo",
|
|
26
|
+
description="Hugging Face repo ID used for Qwen Image editing.",
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
default_quantize: int | None = Field(
|
|
30
|
+
default=8,
|
|
31
|
+
title="Default quantization bits",
|
|
32
|
+
description=(
|
|
33
|
+
"Default quantization bit count used when loading the Qwen Image model.\n"
|
|
34
|
+
"Use a bit count such as 8, or None to disable quantization."
|
|
35
|
+
),
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
# --------------------------------------------------
|
|
39
|
+
# generate
|
|
40
|
+
# --------------------------------------------------
|
|
41
|
+
|
|
42
|
+
default_width: int = Field(
|
|
43
|
+
default=1024,
|
|
44
|
+
title="Default width",
|
|
45
|
+
description="Output image width in pixels used when a request omits width.",
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
default_height: int = Field(
|
|
49
|
+
default=1024,
|
|
50
|
+
title="Default height",
|
|
51
|
+
description="Output image height in pixels used when a request omits height.",
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
max_width: int = Field(
|
|
55
|
+
default=2048,
|
|
56
|
+
title="Maximum width",
|
|
57
|
+
description="Upper pixel limit for the output image width accepted in a request.",
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
max_height: int = Field(
|
|
61
|
+
default=2048,
|
|
62
|
+
title="Maximum height",
|
|
63
|
+
description="Upper pixel limit for the output image height accepted in a request.",
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
max_steps: int = Field(
|
|
67
|
+
default=100,
|
|
68
|
+
title="Maximum inference steps",
|
|
69
|
+
description="Upper limit for the diffusion step count accepted in a request.",
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
max_loras: int = Field(
|
|
73
|
+
default=4,
|
|
74
|
+
title="Maximum LoRA count",
|
|
75
|
+
description="Maximum number of LoRA adapters that can be applied in one generation or edit request.",
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
generate_steps: int = Field(
|
|
79
|
+
default=30,
|
|
80
|
+
title="Default generation steps",
|
|
81
|
+
description="Diffusion step count used when a text-to-image request omits steps.",
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
generate_guidance: float = Field(
|
|
85
|
+
default=4.0,
|
|
86
|
+
title="Default generation guidance",
|
|
87
|
+
description="Guidance strength used when a text-to-image request omits guidance.",
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
# --------------------------------------------------
|
|
91
|
+
# edit
|
|
92
|
+
# --------------------------------------------------
|
|
93
|
+
|
|
94
|
+
edit_steps: int = Field(
|
|
95
|
+
default=30,
|
|
96
|
+
title="Default editing steps",
|
|
97
|
+
description="Diffusion step count used when an image editing request omits steps.",
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
edit_guidance: float = Field(
|
|
101
|
+
default=2.5,
|
|
102
|
+
title="Default editing guidance",
|
|
103
|
+
description="Guidance strength used when an image editing request omits guidance.",
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
settings_manager = SettingsManager(QwenSettings)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""The complete contract for one Qwen Image edit run.
|
|
2
|
+
|
|
3
|
+
Built from settings + request by ``resolve_edit_params``; the model needs nothing
|
|
4
|
+
else to produce the image and its metadata. ``image_paths`` are the locally
|
|
5
|
+
resolved input files, kept out of the recorded metadata in favour of
|
|
6
|
+
``image_file_ids``.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from typing import Literal
|
|
10
|
+
|
|
11
|
+
from pydantic import BaseModel
|
|
12
|
+
|
|
13
|
+
from .._schemas.lora_ref import LoraRef
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class EditParams(BaseModel):
|
|
17
|
+
kind: Literal["edit"] = "edit"
|
|
18
|
+
model: str
|
|
19
|
+
|
|
20
|
+
prompt: str
|
|
21
|
+
negative_prompt: str | None
|
|
22
|
+
image_file_ids: list[str]
|
|
23
|
+
image_paths: list[str]
|
|
24
|
+
|
|
25
|
+
seed: int
|
|
26
|
+
width: int
|
|
27
|
+
height: int
|
|
28
|
+
steps: int
|
|
29
|
+
guidance: float
|
|
30
|
+
quantize: int | None
|
|
31
|
+
scheduler: str
|
|
32
|
+
|
|
33
|
+
format: Literal["png", "jpeg", "webp"]
|
|
34
|
+
quality: int
|
|
35
|
+
|
|
36
|
+
loras: list[LoraRef]
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"""Qwen Image edit request model. Natural-language single/multi-image editing.
|
|
2
|
+
|
|
3
|
+
One endpoint serves both sync and async via ``mode``. Takes one or more reference
|
|
4
|
+
``images`` plus a ``prompt``; defaults for ``width`` / ``height`` / ``steps`` /
|
|
5
|
+
``guidance`` / ``quantize`` are resolved server-side when omitted. A ``quantize``
|
|
6
|
+
override or any ``loras`` builds a one-off transient model (slower, not reused).
|
|
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
|
+
from .._schemas.lora_ref import LoraRef
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class EditRequest(BaseModel):
|
|
19
|
+
model_config = ConfigDict(extra="allow")
|
|
20
|
+
|
|
21
|
+
model: str | None = Field(
|
|
22
|
+
default=None,
|
|
23
|
+
description=(
|
|
24
|
+
"Model variant (see GET /v1/image/qwen/models). Omit for the default "
|
|
25
|
+
"`edit-2509`; `/edit` only accepts `edit-2509` (use `/generate` for "
|
|
26
|
+
"`image`)."
|
|
27
|
+
),
|
|
28
|
+
)
|
|
29
|
+
mode: Literal["sync", "async"] = Field(
|
|
30
|
+
default="sync",
|
|
31
|
+
description=(
|
|
32
|
+
"`sync` waits for the image (504 on timeout); `async` returns 202 with "
|
|
33
|
+
"a job_id immediately — poll GET /v1/jobs/{job_id}."
|
|
34
|
+
),
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
prompt: str = Field(
|
|
38
|
+
...,
|
|
39
|
+
min_length=1,
|
|
40
|
+
description="Natural-language instruction describing the edit (required).",
|
|
41
|
+
)
|
|
42
|
+
negative_prompt: str | None = Field(
|
|
43
|
+
default=None,
|
|
44
|
+
description="Optional text describing what to avoid in the result.",
|
|
45
|
+
)
|
|
46
|
+
images: list[FileRef] = Field(
|
|
47
|
+
...,
|
|
48
|
+
min_length=1,
|
|
49
|
+
description=(
|
|
50
|
+
"One or more reference images (Files-API file ids, http(s) URLs, or data "
|
|
51
|
+
"URLs) to edit / compose under the prompt. At least one is required."
|
|
52
|
+
),
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
width: int | None = Field(
|
|
56
|
+
default=None,
|
|
57
|
+
description=(
|
|
58
|
+
"Output width in pixels. Omit for the server default (1024). Must be a "
|
|
59
|
+
"multiple of 16 and at most 2048."
|
|
60
|
+
),
|
|
61
|
+
)
|
|
62
|
+
height: int | None = Field(
|
|
63
|
+
default=None,
|
|
64
|
+
description=(
|
|
65
|
+
"Output height in pixels. Omit for the server default (1024). Must be a "
|
|
66
|
+
"multiple of 16 and at most 2048."
|
|
67
|
+
),
|
|
68
|
+
)
|
|
69
|
+
steps: int | None = Field(
|
|
70
|
+
default=None,
|
|
71
|
+
ge=1,
|
|
72
|
+
description=(
|
|
73
|
+
"Number of denoising steps (1..100). Omit for the server default (30). "
|
|
74
|
+
"More steps = slower, sometimes higher quality."
|
|
75
|
+
),
|
|
76
|
+
)
|
|
77
|
+
guidance: float | None = Field(
|
|
78
|
+
default=None,
|
|
79
|
+
description=(
|
|
80
|
+
"Classifier-free guidance scale. Omit for the server default (2.5); "
|
|
81
|
+
"higher follows the prompt more strictly."
|
|
82
|
+
),
|
|
83
|
+
)
|
|
84
|
+
seed: int | None = Field(
|
|
85
|
+
default=None,
|
|
86
|
+
description=(
|
|
87
|
+
"Random seed for reproducibility. Omit for a random seed (the resolved "
|
|
88
|
+
"seed is recorded in the result `params`)."
|
|
89
|
+
),
|
|
90
|
+
)
|
|
91
|
+
quantize: int | None = Field(
|
|
92
|
+
default=None,
|
|
93
|
+
description=(
|
|
94
|
+
"Quantization bits, one of {3, 4, 5, 6, 8}. Omit to use the resident "
|
|
95
|
+
"model's quantization (q8). A differing value builds a one-off transient "
|
|
96
|
+
"model (slower, not reused)."
|
|
97
|
+
),
|
|
98
|
+
)
|
|
99
|
+
scheduler: str = Field(
|
|
100
|
+
default="linear",
|
|
101
|
+
description="Noise scheduler. `linear` is the default and tested value.",
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
format: Literal["png", "jpeg", "webp"] = Field(
|
|
105
|
+
default="png",
|
|
106
|
+
description="Output image encoding for the produced file.",
|
|
107
|
+
)
|
|
108
|
+
quality: int = Field(
|
|
109
|
+
default=90,
|
|
110
|
+
ge=1,
|
|
111
|
+
le=100,
|
|
112
|
+
description="Encoder quality 1..100 (used for jpeg/webp; ignored for png).",
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
loras: list[LoraRef] = Field(
|
|
116
|
+
default_factory=list,
|
|
117
|
+
description=(
|
|
118
|
+
"Up to 4 LoRA adapters [{file, scale}] referencing Files-API ids. Any "
|
|
119
|
+
"lora forces a one-off transient model (slower, not reused)."
|
|
120
|
+
),
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
def gen_params(self) -> dict:
|
|
124
|
+
return {
|
|
125
|
+
"prompt": self.prompt,
|
|
126
|
+
"negative_prompt": self.negative_prompt,
|
|
127
|
+
"images": [image.model_dump(mode="json") for image in self.images],
|
|
128
|
+
"width": self.width,
|
|
129
|
+
"height": self.height,
|
|
130
|
+
"steps": self.steps,
|
|
131
|
+
"guidance": self.guidance,
|
|
132
|
+
"seed": self.seed,
|
|
133
|
+
"quantize": self.quantize,
|
|
134
|
+
"scheduler": self.scheduler,
|
|
135
|
+
"format": self.format,
|
|
136
|
+
"quality": self.quality,
|
|
137
|
+
"loras": [lr.model_dump() for lr in self.loras],
|
|
138
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""The complete contract for one Qwen Image generate run.
|
|
2
|
+
|
|
3
|
+
Built from settings + request by ``resolve_generate_params``; the model needs
|
|
4
|
+
nothing else to produce the image and its metadata. ``kind`` is ``img2img`` when
|
|
5
|
+
``image_path`` is set (resolved from ``init_image_file_id``), else ``txt2img``;
|
|
6
|
+
``image_path`` is kept out of the recorded metadata in favour of the file id.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from typing import Literal
|
|
10
|
+
|
|
11
|
+
from pydantic import BaseModel
|
|
12
|
+
|
|
13
|
+
from .._schemas.lora_ref import LoraRef
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class GenerateParams(BaseModel):
|
|
17
|
+
kind: Literal["txt2img", "img2img"]
|
|
18
|
+
model: str
|
|
19
|
+
|
|
20
|
+
prompt: str
|
|
21
|
+
negative_prompt: str | None
|
|
22
|
+
init_image_file_id: str | None
|
|
23
|
+
image_path: str | None
|
|
24
|
+
image_strength: float | None
|
|
25
|
+
|
|
26
|
+
seed: int
|
|
27
|
+
width: int
|
|
28
|
+
height: int
|
|
29
|
+
steps: int
|
|
30
|
+
guidance: float
|
|
31
|
+
quantize: int | None
|
|
32
|
+
scheduler: str
|
|
33
|
+
|
|
34
|
+
format: Literal["png", "jpeg", "webp"]
|
|
35
|
+
quality: int
|
|
36
|
+
|
|
37
|
+
loras: list[LoraRef]
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"""Qwen Image generate request model. txt2img, or img2img when init_image is set.
|
|
2
|
+
|
|
3
|
+
One endpoint serves both sync and async via ``mode``. ``init_image`` is optional:
|
|
4
|
+
when present ``/generate`` runs img2img, otherwise txt2img. Defaults for
|
|
5
|
+
``width`` / ``height`` / ``steps`` / ``guidance`` / ``quantize`` are resolved
|
|
6
|
+
server-side when omitted. A ``quantize`` override or any ``loras`` builds a
|
|
7
|
+
one-off transient model (slower, not reused).
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from typing import Literal
|
|
11
|
+
|
|
12
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
13
|
+
|
|
14
|
+
from kiapi.core.file import FileRef
|
|
15
|
+
|
|
16
|
+
from .._schemas.lora_ref import LoraRef
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class GenerateRequest(BaseModel):
|
|
20
|
+
model_config = ConfigDict(extra="allow")
|
|
21
|
+
|
|
22
|
+
model: str | None = Field(
|
|
23
|
+
default=None,
|
|
24
|
+
description=(
|
|
25
|
+
"Model variant (see GET /v1/image/qwen/models). Omit for the default "
|
|
26
|
+
"`image`; `/generate` only accepts `image` (use `/edit` for `edit-2509`)."
|
|
27
|
+
),
|
|
28
|
+
)
|
|
29
|
+
mode: Literal["sync", "async"] = Field(
|
|
30
|
+
default="sync",
|
|
31
|
+
description=(
|
|
32
|
+
"`sync` waits for the image (504 on timeout); `async` returns 202 with "
|
|
33
|
+
"a job_id immediately — poll GET /v1/jobs/{job_id}."
|
|
34
|
+
),
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
prompt: str = Field(
|
|
38
|
+
...,
|
|
39
|
+
min_length=1,
|
|
40
|
+
description="Text prompt describing the image to generate (required).",
|
|
41
|
+
)
|
|
42
|
+
negative_prompt: str | None = Field(
|
|
43
|
+
default=None,
|
|
44
|
+
description="Optional text describing what to avoid in the image.",
|
|
45
|
+
)
|
|
46
|
+
init_image: FileRef | None = Field(
|
|
47
|
+
default=None,
|
|
48
|
+
description=(
|
|
49
|
+
"Optional input image (Files-API file id, http(s) URL, or data URL). "
|
|
50
|
+
"When set, `/generate` runs img2img seeded from this image; omit for "
|
|
51
|
+
"plain txt2img."
|
|
52
|
+
),
|
|
53
|
+
)
|
|
54
|
+
image_strength: float | None = Field(
|
|
55
|
+
default=None,
|
|
56
|
+
description=(
|
|
57
|
+
"img2img only: how much the `init_image` is preserved, in 0..1. Lower "
|
|
58
|
+
"keeps more of the input; higher follows the prompt more freely. "
|
|
59
|
+
"Ignored when `init_image` is absent."
|
|
60
|
+
),
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
width: int | None = Field(
|
|
64
|
+
default=None,
|
|
65
|
+
description=(
|
|
66
|
+
"Output width in pixels. Omit for the server default (1024). Must be a "
|
|
67
|
+
"multiple of 16 and at most 2048."
|
|
68
|
+
),
|
|
69
|
+
)
|
|
70
|
+
height: int | None = Field(
|
|
71
|
+
default=None,
|
|
72
|
+
description=(
|
|
73
|
+
"Output height in pixels. Omit for the server default (1024). Must be a "
|
|
74
|
+
"multiple of 16 and at most 2048."
|
|
75
|
+
),
|
|
76
|
+
)
|
|
77
|
+
steps: int | None = Field(
|
|
78
|
+
default=None,
|
|
79
|
+
ge=1,
|
|
80
|
+
description=(
|
|
81
|
+
"Number of denoising steps (1..100). Omit for the server default (30). "
|
|
82
|
+
"More steps = slower, sometimes higher quality."
|
|
83
|
+
),
|
|
84
|
+
)
|
|
85
|
+
guidance: float | None = Field(
|
|
86
|
+
default=None,
|
|
87
|
+
description=(
|
|
88
|
+
"Classifier-free guidance scale. Omit for the server default (4.0); "
|
|
89
|
+
"higher follows the prompt more strictly."
|
|
90
|
+
),
|
|
91
|
+
)
|
|
92
|
+
seed: int | None = Field(
|
|
93
|
+
default=None,
|
|
94
|
+
description=(
|
|
95
|
+
"Random seed for reproducibility. Omit for a random seed (the resolved "
|
|
96
|
+
"seed is recorded in the result `params`)."
|
|
97
|
+
),
|
|
98
|
+
)
|
|
99
|
+
quantize: int | None = Field(
|
|
100
|
+
default=None,
|
|
101
|
+
description=(
|
|
102
|
+
"Quantization bits, one of {3, 4, 5, 6, 8}. Omit to use the resident "
|
|
103
|
+
"model's quantization (q8). A differing value builds a one-off transient "
|
|
104
|
+
"model (slower, not reused)."
|
|
105
|
+
),
|
|
106
|
+
)
|
|
107
|
+
scheduler: str = Field(
|
|
108
|
+
default="linear",
|
|
109
|
+
description="Noise scheduler. `linear` is the default and tested value.",
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
format: Literal["png", "jpeg", "webp"] = Field(
|
|
113
|
+
default="png",
|
|
114
|
+
description="Output image encoding for the produced file.",
|
|
115
|
+
)
|
|
116
|
+
quality: int = Field(
|
|
117
|
+
default=90,
|
|
118
|
+
ge=1,
|
|
119
|
+
le=100,
|
|
120
|
+
description="Encoder quality 1..100 (used for jpeg/webp; ignored for png).",
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
loras: list[LoraRef] = Field(
|
|
124
|
+
default_factory=list,
|
|
125
|
+
description=(
|
|
126
|
+
"Up to 4 LoRA adapters [{file, scale}] referencing Files-API ids. Any "
|
|
127
|
+
"lora forces a one-off transient model (slower, not reused)."
|
|
128
|
+
),
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
def gen_params(self) -> dict:
|
|
132
|
+
return {
|
|
133
|
+
"prompt": self.prompt,
|
|
134
|
+
"negative_prompt": self.negative_prompt,
|
|
135
|
+
"init_image": self.init_image.model_dump(mode="json")
|
|
136
|
+
if self.init_image is not None
|
|
137
|
+
else None,
|
|
138
|
+
"image_strength": self.image_strength,
|
|
139
|
+
"width": self.width,
|
|
140
|
+
"height": self.height,
|
|
141
|
+
"steps": self.steps,
|
|
142
|
+
"guidance": self.guidance,
|
|
143
|
+
"seed": self.seed,
|
|
144
|
+
"quantize": self.quantize,
|
|
145
|
+
"scheduler": self.scheduler,
|
|
146
|
+
"format": self.format,
|
|
147
|
+
"quality": self.quality,
|
|
148
|
+
"loras": [lr.model_dump() for lr in self.loras],
|
|
149
|
+
}
|