arkruntime 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.
- arkruntime/__init__.py +11 -0
- arkruntime/_base_client.py +1373 -0
- arkruntime/_client.py +585 -0
- arkruntime/_compat.py +265 -0
- arkruntime/_constants.py +55 -0
- arkruntime/_exceptions.py +188 -0
- arkruntime/_files.py +122 -0
- arkruntime/_legacy_response.py +438 -0
- arkruntime/_managed_agents_serialize.py +55 -0
- arkruntime/_models.py +733 -0
- arkruntime/_qs.py +164 -0
- arkruntime/_request_options.py +118 -0
- arkruntime/_resource.py +41 -0
- arkruntime/_response.py +599 -0
- arkruntime/_streaming.py +460 -0
- arkruntime/_types.py +207 -0
- arkruntime/_utils/__init__.py +144 -0
- arkruntime/_utils/_key_agreement.py +217 -0
- arkruntime/_utils/_logs.py +28 -0
- arkruntime/_utils/_model_breaker.py +87 -0
- arkruntime/_utils/_streams.py +17 -0
- arkruntime/_utils/_transform.py +463 -0
- arkruntime/_utils/_typing.py +157 -0
- arkruntime/_utils/_utils.py +473 -0
- arkruntime/common/__init__.py +6 -0
- arkruntime/common/_parsing/__init__.py +31 -0
- arkruntime/common/_parsing/_completions.py +272 -0
- arkruntime/common/_parsing/_responses.py +174 -0
- arkruntime/common/_pydantic.py +166 -0
- arkruntime/common/_tools.py +85 -0
- arkruntime/common/streaming/__init__.py +4 -0
- arkruntime/common/streaming/_deltas.py +68 -0
- arkruntime/common/streaming/chat/__init__.py +49 -0
- arkruntime/common/streaming/chat/_completions.py +732 -0
- arkruntime/common/streaming/chat/_events.py +96 -0
- arkruntime/common/streaming/chat/_types.py +28 -0
- arkruntime/pagination.py +128 -0
- arkruntime/resources/__init__.py +75 -0
- arkruntime/resources/agents/__init__.py +3 -0
- arkruntime/resources/agents/agents.py +372 -0
- arkruntime/resources/batch/__init__.py +6 -0
- arkruntime/resources/batch/_utils.py +156 -0
- arkruntime/resources/batch/batch.py +40 -0
- arkruntime/resources/batch/chat/__init__.py +6 -0
- arkruntime/resources/batch/chat/chat.py +22 -0
- arkruntime/resources/batch/chat/completions.py +217 -0
- arkruntime/resources/batch/embeddings.py +150 -0
- arkruntime/resources/batch/multimodal_embeddings.py +160 -0
- arkruntime/resources/beta/__init__.py +4 -0
- arkruntime/resources/beta/beta.py +73 -0
- arkruntime/resources/beta/chat/__init__.py +13 -0
- arkruntime/resources/beta/chat/chat.py +23 -0
- arkruntime/resources/beta/chat/completions.py +356 -0
- arkruntime/resources/chat/__init__.py +7 -0
- arkruntime/resources/chat/chat.py +23 -0
- arkruntime/resources/chat/completions.py +242 -0
- arkruntime/resources/content_generation/__init__.py +7 -0
- arkruntime/resources/content_generation/content_generation.py +21 -0
- arkruntime/resources/content_generation/tasks.py +331 -0
- arkruntime/resources/embeddings/__init__.py +6 -0
- arkruntime/resources/embeddings/embeddings.py +140 -0
- arkruntime/resources/encryption.py +187 -0
- arkruntime/resources/environments/__init__.py +3 -0
- arkruntime/resources/environments/environments.py +216 -0
- arkruntime/resources/files/__init__.py +6 -0
- arkruntime/resources/files/files.py +401 -0
- arkruntime/resources/images/__init__.py +10 -0
- arkruntime/resources/images/images.py +152 -0
- arkruntime/resources/memory_stores/__init__.py +7 -0
- arkruntime/resources/memory_stores/memories.py +262 -0
- arkruntime/resources/memory_stores/memory_stores.py +223 -0
- arkruntime/resources/multimodal_embeddings/__init__.py +9 -0
- arkruntime/resources/multimodal_embeddings/multimodal_embeddings.py +150 -0
- arkruntime/resources/responses/__init__.py +8 -0
- arkruntime/resources/responses/input_items.py +241 -0
- arkruntime/resources/responses/responses.py +467 -0
- arkruntime/resources/sessions/__init__.py +24 -0
- arkruntime/resources/sessions/session_events.py +336 -0
- arkruntime/resources/sessions/session_resources.py +89 -0
- arkruntime/resources/sessions/session_threads.py +275 -0
- arkruntime/resources/sessions/sessions.py +331 -0
- arkruntime/resources/skills/__init__.py +3 -0
- arkruntime/resources/skills/skills.py +112 -0
- arkruntime/resources/tokenization/__init__.py +9 -0
- arkruntime/resources/tokenization/tokenization.py +131 -0
- arkruntime/resources/vaults/__init__.py +4 -0
- arkruntime/resources/vaults/credentials.py +253 -0
- arkruntime/resources/vaults/vaults.py +197 -0
- arkruntime/types/__init__.py +7 -0
- arkruntime/types/agent/__init__.py +56 -0
- arkruntime/types/agent/_init_extras_shim.py +12 -0
- arkruntime/types/agent/agent.py +86 -0
- arkruntime/types/agent/agent_ref.py +32 -0
- arkruntime/types/agent/agent_ref_type.py +18 -0
- arkruntime/types/agent/agent_skill_ref.py +32 -0
- arkruntime/types/agent/create_agent_request.py +65 -0
- arkruntime/types/agent/delete_agent_response.py +20 -0
- arkruntime/types/agent/list_agents_response.py +32 -0
- arkruntime/types/agent/mcp_server.py +30 -0
- arkruntime/types/agent/mcp_server_type.py +16 -0
- arkruntime/types/agent/model_config.py +28 -0
- arkruntime/types/agent/model_speed.py +18 -0
- arkruntime/types/agent/multiagent_config.py +29 -0
- arkruntime/types/agent/multiagent_type.py +16 -0
- arkruntime/types/agent/permission_policy.py +22 -0
- arkruntime/types/agent/permission_policy_type.py +18 -0
- arkruntime/types/agent/skill_ref_type.py +19 -0
- arkruntime/types/agent/tag.py +26 -0
- arkruntime/types/agent/tool_config.py +32 -0
- arkruntime/types/agent/tool_default_config.py +28 -0
- arkruntime/types/agent/tool_item.py +57 -0
- arkruntime/types/agent/update_agent_request.py +70 -0
- arkruntime/types/chat/__init__.py +212 -0
- arkruntime/types/chat/_init_extras_shim.py +73 -0
- arkruntime/types/chat/chat_completion_choice_logprobs.py +20 -0
- arkruntime/types/chat/chat_completion_content_part.py +32 -0
- arkruntime/types/chat/chat_completion_content_part_audio.py +23 -0
- arkruntime/types/chat/chat_completion_content_part_audio_input_audio.py +30 -0
- arkruntime/types/chat/chat_completion_content_part_audio_input_audio_param.py +25 -0
- arkruntime/types/chat/chat_completion_content_part_audio_param.py +22 -0
- arkruntime/types/chat/chat_completion_content_part_file.py +21 -0
- arkruntime/types/chat/chat_completion_content_part_file_file.py +30 -0
- arkruntime/types/chat/chat_completion_content_part_file_file_param.py +25 -0
- arkruntime/types/chat/chat_completion_content_part_file_param.py +22 -0
- arkruntime/types/chat/chat_completion_content_part_image.py +23 -0
- arkruntime/types/chat/chat_completion_content_part_image_image_url.py +33 -0
- arkruntime/types/chat/chat_completion_content_part_image_image_url_param.py +28 -0
- arkruntime/types/chat/chat_completion_content_part_image_param.py +22 -0
- arkruntime/types/chat/chat_completion_content_part_param.py +29 -0
- arkruntime/types/chat/chat_completion_content_part_text.py +22 -0
- arkruntime/types/chat/chat_completion_content_part_text_param.py +19 -0
- arkruntime/types/chat/chat_completion_content_part_video.py +23 -0
- arkruntime/types/chat/chat_completion_content_part_video_param.py +22 -0
- arkruntime/types/chat/chat_completion_content_part_video_video_url.py +36 -0
- arkruntime/types/chat/chat_completion_content_part_video_video_url_param.py +30 -0
- arkruntime/types/chat/chat_completion_message_content.py +17 -0
- arkruntime/types/chat/chat_completion_message_content_param.py +15 -0
- arkruntime/types/chat/chat_completion_message_tool_call.py +29 -0
- arkruntime/types/chat/chat_completion_message_tool_call_chunk.py +31 -0
- arkruntime/types/chat/chat_completion_message_tool_call_chunk_function.py +16 -0
- arkruntime/types/chat/chat_completion_message_tool_call_function.py +23 -0
- arkruntime/types/chat/chat_completion_message_tool_call_function_param.py +22 -0
- arkruntime/types/chat/chat_completion_message_tool_call_param.py +26 -0
- arkruntime/types/chat/chat_completion_named_tool_choice.py +21 -0
- arkruntime/types/chat/chat_completion_named_tool_choice_param.py +22 -0
- arkruntime/types/chat/chat_completion_request.py +129 -0
- arkruntime/types/chat/chat_completion_request_assistant_message.py +39 -0
- arkruntime/types/chat/chat_completion_request_assistant_message_param.py +36 -0
- arkruntime/types/chat/chat_completion_request_message.py +32 -0
- arkruntime/types/chat/chat_completion_request_message_param.py +29 -0
- arkruntime/types/chat/chat_completion_request_param.py +122 -0
- arkruntime/types/chat/chat_completion_request_system_message.py +25 -0
- arkruntime/types/chat/chat_completion_request_system_message_param.py +23 -0
- arkruntime/types/chat/chat_completion_request_tool_message.py +29 -0
- arkruntime/types/chat/chat_completion_request_tool_message_param.py +26 -0
- arkruntime/types/chat/chat_completion_request_user_message.py +29 -0
- arkruntime/types/chat/chat_completion_request_user_message_param.py +27 -0
- arkruntime/types/chat/chat_completion_response.py +52 -0
- arkruntime/types/chat/chat_completion_response_choice.py +36 -0
- arkruntime/types/chat/chat_completion_response_format.py +28 -0
- arkruntime/types/chat/chat_completion_response_format_json_schema.py +33 -0
- arkruntime/types/chat/chat_completion_response_format_json_schema_param.py +31 -0
- arkruntime/types/chat/chat_completion_response_format_param.py +27 -0
- arkruntime/types/chat/chat_completion_response_message.py +37 -0
- arkruntime/types/chat/chat_completion_role.py +16 -0
- arkruntime/types/chat/chat_completion_service_status.py +17 -0
- arkruntime/types/chat/chat_completion_stop.py +13 -0
- arkruntime/types/chat/chat_completion_stop_param.py +11 -0
- arkruntime/types/chat/chat_completion_stream_choice_logprobs.py +17 -0
- arkruntime/types/chat/chat_completion_stream_options.py +22 -0
- arkruntime/types/chat/chat_completion_stream_options_param.py +19 -0
- arkruntime/types/chat/chat_completion_stream_response.py +34 -0
- arkruntime/types/chat/chat_completion_stream_response_choice.py +27 -0
- arkruntime/types/chat/chat_completion_stream_response_delta.py +36 -0
- arkruntime/types/chat/chat_completion_token_logprob.py +26 -0
- arkruntime/types/chat/chat_completion_token_logprob_top_logprob.py +17 -0
- arkruntime/types/chat/chat_completion_tool.py +20 -0
- arkruntime/types/chat/chat_completion_tool_choice.py +18 -0
- arkruntime/types/chat/chat_completion_tool_choice_function.py +13 -0
- arkruntime/types/chat/chat_completion_tool_choice_function_param.py +13 -0
- arkruntime/types/chat/chat_completion_tool_choice_param.py +16 -0
- arkruntime/types/chat/chat_completion_tool_param.py +20 -0
- arkruntime/types/chat/completion_tokens_details.py +16 -0
- arkruntime/types/chat/completion_usage.py +35 -0
- arkruntime/types/chat/error.py +28 -0
- arkruntime/types/chat/error_response.py +15 -0
- arkruntime/types/chat/finish_reason.py +16 -0
- arkruntime/types/chat/function_object.py +35 -0
- arkruntime/types/chat/function_object_param.py +38 -0
- arkruntime/types/chat/image_detail.py +16 -0
- arkruntime/types/chat/image_pixel_limit.py +16 -0
- arkruntime/types/chat/image_pixel_limit_param.py +17 -0
- arkruntime/types/chat/model_fallback_status.py +20 -0
- arkruntime/types/chat/moderation_hit_type.py +14 -0
- arkruntime/types/chat/parsed_chat_completion_shim.py +52 -0
- arkruntime/types/chat/parsed_function_tool_call_shim.py +29 -0
- arkruntime/types/chat/prompt_tokens_details.py +34 -0
- arkruntime/types/chat/reasoning_effort.py +19 -0
- arkruntime/types/chat/request_service_tier.py +15 -0
- arkruntime/types/chat/response_format_type.py +15 -0
- arkruntime/types/chat/response_service_tier.py +15 -0
- arkruntime/types/chat/thinking.py +17 -0
- arkruntime/types/chat/thinking_mode.py +15 -0
- arkruntime/types/chat/thinking_param.py +17 -0
- arkruntime/types/chat/tool_choice_mode.py +15 -0
- arkruntime/types/chat/tool_type.py +13 -0
- arkruntime/types/chat/tool_type_param.py +11 -0
- arkruntime/types/chat/video_image_pixel_limit.py +16 -0
- arkruntime/types/chat/video_image_pixel_limit_param.py +17 -0
- arkruntime/types/completion_usage.py +43 -0
- arkruntime/types/content_generation/__init__.py +66 -0
- arkruntime/types/content_generation/_init_extras_shim.py +12 -0
- arkruntime/types/content_generation/audio_role.py +16 -0
- arkruntime/types/content_generation/audio_url.py +16 -0
- arkruntime/types/content_generation/audio_url_param.py +14 -0
- arkruntime/types/content_generation/content_generation_task.py +125 -0
- arkruntime/types/content_generation/content_item.py +54 -0
- arkruntime/types/content_generation/content_item_param.py +46 -0
- arkruntime/types/content_generation/content_type.py +21 -0
- arkruntime/types/content_generation/create_content_generation_task_request.py +106 -0
- arkruntime/types/content_generation/create_content_generation_task_request_param.py +83 -0
- arkruntime/types/content_generation/create_content_generation_task_response.py +16 -0
- arkruntime/types/content_generation/draft_task.py +16 -0
- arkruntime/types/content_generation/draft_task_param.py +14 -0
- arkruntime/types/content_generation/image_role.py +20 -0
- arkruntime/types/content_generation/image_url.py +16 -0
- arkruntime/types/content_generation/image_url_param.py +14 -0
- arkruntime/types/content_generation/list_content_generation_tasks_response.py +24 -0
- arkruntime/types/content_generation/reasoning_effort.py +16 -0
- arkruntime/types/content_generation/task_content.py +30 -0
- arkruntime/types/content_generation/task_error.py +20 -0
- arkruntime/types/content_generation/task_status.py +21 -0
- arkruntime/types/content_generation/task_usage.py +28 -0
- arkruntime/types/content_generation/tool.py +18 -0
- arkruntime/types/content_generation/tool_param.py +17 -0
- arkruntime/types/content_generation/tool_type.py +13 -0
- arkruntime/types/content_generation/tool_type_param.py +11 -0
- arkruntime/types/content_generation/tool_usage.py +18 -0
- arkruntime/types/content_generation/video_role.py +16 -0
- arkruntime/types/content_generation/video_url.py +16 -0
- arkruntime/types/content_generation/video_url_param.py +14 -0
- arkruntime/types/embedding/__init__.py +30 -0
- arkruntime/types/embedding/_init_extras_shim.py +12 -0
- arkruntime/types/embedding/embedding.py +18 -0
- arkruntime/types/embedding/embedding_input.py +18 -0
- arkruntime/types/embedding/embedding_input_param.py +16 -0
- arkruntime/types/embedding/embedding_item.py +32 -0
- arkruntime/types/embedding/embedding_request.py +39 -0
- arkruntime/types/embedding/embedding_request_param.py +37 -0
- arkruntime/types/embedding/embedding_response.py +41 -0
- arkruntime/types/embedding/embedding_usage.py +24 -0
- arkruntime/types/embedding/encoding_format.py +14 -0
- arkruntime/types/environment/__init__.py +36 -0
- arkruntime/types/environment/_init_extras_shim.py +12 -0
- arkruntime/types/environment/create_environment_request.py +41 -0
- arkruntime/types/environment/delete_environment_response.py +24 -0
- arkruntime/types/environment/env_config.py +38 -0
- arkruntime/types/environment/env_config_type.py +18 -0
- arkruntime/types/environment/environment.py +57 -0
- arkruntime/types/environment/environment_scope.py +18 -0
- arkruntime/types/environment/list_environments_response.py +30 -0
- arkruntime/types/environment/networking_config.py +37 -0
- arkruntime/types/environment/networking_type.py +18 -0
- arkruntime/types/environment/packages_config.py +47 -0
- arkruntime/types/environment/update_environment_request.py +45 -0
- arkruntime/types/file/__init__.py +40 -0
- arkruntime/types/file/_init_extras_shim.py +12 -0
- arkruntime/types/file/file_create_request.py +41 -0
- arkruntime/types/file/file_create_request_param.py +41 -0
- arkruntime/types/file/file_deleted.py +30 -0
- arkruntime/types/file/file_error.py +32 -0
- arkruntime/types/file/file_list_response.py +42 -0
- arkruntime/types/file/file_object.py +71 -0
- arkruntime/types/file/order.py +18 -0
- arkruntime/types/file/preprocess_configs.py +24 -0
- arkruntime/types/file/preprocess_configs_param.py +22 -0
- arkruntime/types/file/purpose.py +18 -0
- arkruntime/types/file/status.py +19 -0
- arkruntime/types/file/tos_storage.py +28 -0
- arkruntime/types/file/tos_storage_param.py +25 -0
- arkruntime/types/file/video.py +26 -0
- arkruntime/types/file/video_param.py +23 -0
- arkruntime/types/images/__init__.py +55 -0
- arkruntime/types/images/_init_extras_shim.py +12 -0
- arkruntime/types/images/bounding_box.py +27 -0
- arkruntime/types/images/create_image_generation_request.py +88 -0
- arkruntime/types/images/create_image_generation_request_param.py +73 -0
- arkruntime/types/images/image_data_item.py +58 -0
- arkruntime/types/images/image_error.py +20 -0
- arkruntime/types/images/image_generation_response.py +43 -0
- arkruntime/types/images/image_generation_stream_event.py +74 -0
- arkruntime/types/images/image_generation_stream_event_type.py +19 -0
- arkruntime/types/images/optimize_prompt_mode.py +18 -0
- arkruntime/types/images/optimize_prompt_options.py +20 -0
- arkruntime/types/images/optimize_prompt_options_param.py +18 -0
- arkruntime/types/images/output_format.py +18 -0
- arkruntime/types/images/response_format.py +18 -0
- arkruntime/types/images/sequential_image_generation_mode.py +18 -0
- arkruntime/types/images/sequential_image_generation_options.py +18 -0
- arkruntime/types/images/sequential_image_generation_options_param.py +16 -0
- arkruntime/types/images/tool.py +18 -0
- arkruntime/types/images/tool_param.py +17 -0
- arkruntime/types/images/tool_type.py +13 -0
- arkruntime/types/images/tool_type_param.py +11 -0
- arkruntime/types/images/tool_usage.py +18 -0
- arkruntime/types/images/usage.py +36 -0
- arkruntime/types/memory/__init__.py +44 -0
- arkruntime/types/memory/_init_extras_shim.py +12 -0
- arkruntime/types/memory/actor.py +26 -0
- arkruntime/types/memory/actor_type.py +16 -0
- arkruntime/types/memory/create_memory_request.py +24 -0
- arkruntime/types/memory/create_memory_store_request.py +30 -0
- arkruntime/types/memory/delete_memory_response.py +26 -0
- arkruntime/types/memory/delete_memory_store_response.py +26 -0
- arkruntime/types/memory/list_memories_order_by.py +18 -0
- arkruntime/types/memory/list_memories_response.py +32 -0
- arkruntime/types/memory/list_memory_stores_response.py +28 -0
- arkruntime/types/memory/memory.py +64 -0
- arkruntime/types/memory/memory_list_item.py +58 -0
- arkruntime/types/memory/memory_list_item_type.py +20 -0
- arkruntime/types/memory/memory_store.py +64 -0
- arkruntime/types/memory/update_memory_request.py +27 -0
- arkruntime/types/memory/update_memory_store_request.py +31 -0
- arkruntime/types/multimodal_embedding/__init__.py +54 -0
- arkruntime/types/multimodal_embedding/_init_extras_shim.py +12 -0
- arkruntime/types/multimodal_embedding/embedding.py +13 -0
- arkruntime/types/multimodal_embedding/embedding_data_item.py +33 -0
- arkruntime/types/multimodal_embedding/embedding_input.py +34 -0
- arkruntime/types/multimodal_embedding/embedding_input_param.py +29 -0
- arkruntime/types/multimodal_embedding/embedding_input_type.py +15 -0
- arkruntime/types/multimodal_embedding/embedding_object.py +14 -0
- arkruntime/types/multimodal_embedding/embedding_usage.py +26 -0
- arkruntime/types/multimodal_embedding/encoding_format.py +14 -0
- arkruntime/types/multimodal_embedding/image_url.py +16 -0
- arkruntime/types/multimodal_embedding/image_url_param.py +14 -0
- arkruntime/types/multimodal_embedding/multi_embedding_config.py +18 -0
- arkruntime/types/multimodal_embedding/multi_embedding_config_param.py +17 -0
- arkruntime/types/multimodal_embedding/multi_embedding_mode.py +14 -0
- arkruntime/types/multimodal_embedding/multi_modal_embedding_request.py +47 -0
- arkruntime/types/multimodal_embedding/multi_modal_embedding_request_param.py +39 -0
- arkruntime/types/multimodal_embedding/multi_modal_embedding_response.py +41 -0
- arkruntime/types/multimodal_embedding/prompt_tokens_details.py +20 -0
- arkruntime/types/multimodal_embedding/sparse_embedding_config.py +20 -0
- arkruntime/types/multimodal_embedding/sparse_embedding_config_param.py +18 -0
- arkruntime/types/multimodal_embedding/sparse_embedding_mode.py +14 -0
- arkruntime/types/multimodal_embedding/sparse_embedding_value.py +20 -0
- arkruntime/types/multimodal_embedding/video_url.py +22 -0
- arkruntime/types/multimodal_embedding/video_url_param.py +19 -0
- arkruntime/types/responses/__init__.py +528 -0
- arkruntime/types/responses/_init_extras_shim.py +47 -0
- arkruntime/types/responses/annotation.py +20 -0
- arkruntime/types/responses/annotation_param.py +14 -0
- arkruntime/types/responses/applied_edit.py +22 -0
- arkruntime/types/responses/audio_chunk.py +15 -0
- arkruntime/types/responses/audio_chunking_strategy.py +18 -0
- arkruntime/types/responses/audio_chunking_strategy_param.py +21 -0
- arkruntime/types/responses/cache_mode.py +14 -0
- arkruntime/types/responses/clear_thinking.py +18 -0
- arkruntime/types/responses/clear_thinking_keep.py +18 -0
- arkruntime/types/responses/clear_thinking_keep_param.py +19 -0
- arkruntime/types/responses/clear_thinking_param.py +19 -0
- arkruntime/types/responses/clear_thinking_response.py +16 -0
- arkruntime/types/responses/clear_tool_uses.py +23 -0
- arkruntime/types/responses/clear_tool_uses_inputs.py +18 -0
- arkruntime/types/responses/clear_tool_uses_inputs_param.py +19 -0
- arkruntime/types/responses/clear_tool_uses_param.py +27 -0
- arkruntime/types/responses/clear_tool_uses_response.py +16 -0
- arkruntime/types/responses/content_filter.py +14 -0
- arkruntime/types/responses/content_item.py +36 -0
- arkruntime/types/responses/content_item_audio.py +20 -0
- arkruntime/types/responses/content_item_audio_param.py +23 -0
- arkruntime/types/responses/content_item_file.py +19 -0
- arkruntime/types/responses/content_item_file_param.py +23 -0
- arkruntime/types/responses/content_item_image.py +22 -0
- arkruntime/types/responses/content_item_image_param.py +26 -0
- arkruntime/types/responses/content_item_param.py +29 -0
- arkruntime/types/responses/content_item_text.py +22 -0
- arkruntime/types/responses/content_item_text_param.py +19 -0
- arkruntime/types/responses/content_item_video.py +27 -0
- arkruntime/types/responses/content_item_video_param.py +24 -0
- arkruntime/types/responses/context_management.py +17 -0
- arkruntime/types/responses/context_management_param.py +17 -0
- arkruntime/types/responses/context_management_response.py +17 -0
- arkruntime/types/responses/cover_image.py +26 -0
- arkruntime/types/responses/cover_image_param.py +22 -0
- arkruntime/types/responses/delete_response_response.py +17 -0
- arkruntime/types/responses/doc_citation.py +19 -0
- arkruntime/types/responses/doc_citation_param.py +23 -0
- arkruntime/types/responses/doubao_app_call_block.py +30 -0
- arkruntime/types/responses/doubao_app_call_block_output_text.py +21 -0
- arkruntime/types/responses/doubao_app_call_block_reasoning_search.py +24 -0
- arkruntime/types/responses/doubao_app_call_block_reasoning_text.py +21 -0
- arkruntime/types/responses/doubao_app_call_block_search.py +24 -0
- arkruntime/types/responses/doubao_app_feature.py +20 -0
- arkruntime/types/responses/doubao_app_feature_item.py +18 -0
- arkruntime/types/responses/doubao_app_feature_item_param.py +19 -0
- arkruntime/types/responses/doubao_app_feature_mode.py +14 -0
- arkruntime/types/responses/doubao_app_feature_param.py +23 -0
- arkruntime/types/responses/doubao_app_search_result.py +15 -0
- arkruntime/types/responses/doubao_app_search_text_item.py +15 -0
- arkruntime/types/responses/doubao_app_tool.py +20 -0
- arkruntime/types/responses/doubao_app_tool_param.py +22 -0
- arkruntime/types/responses/edit.py +19 -0
- arkruntime/types/responses/edit_param.py +14 -0
- arkruntime/types/responses/function_tool.py +32 -0
- arkruntime/types/responses/function_tool_param.py +29 -0
- arkruntime/types/responses/image_detail.py +16 -0
- arkruntime/types/responses/image_pixel_limit.py +16 -0
- arkruntime/types/responses/image_pixel_limit_param.py +17 -0
- arkruntime/types/responses/image_process_options.py +15 -0
- arkruntime/types/responses/image_process_options_param.py +15 -0
- arkruntime/types/responses/image_process_tool.py +21 -0
- arkruntime/types/responses/image_process_tool_param.py +25 -0
- arkruntime/types/responses/incomplete_details.py +24 -0
- arkruntime/types/responses/input_item.py +38 -0
- arkruntime/types/responses/input_item_list_params_shim.py +39 -0
- arkruntime/types/responses/input_item_param.py +33 -0
- arkruntime/types/responses/input_tokens_details.py +17 -0
- arkruntime/types/responses/item_agent_tool_call.py +20 -0
- arkruntime/types/responses/item_doubao_app_call.py +22 -0
- arkruntime/types/responses/item_easy_message.py +22 -0
- arkruntime/types/responses/item_easy_message_param.py +26 -0
- arkruntime/types/responses/item_function_image_process.py +24 -0
- arkruntime/types/responses/item_function_knowledge_search.py +21 -0
- arkruntime/types/responses/item_function_mcp_approval_request.py +34 -0
- arkruntime/types/responses/item_function_mcp_approval_request_param.py +28 -0
- arkruntime/types/responses/item_function_mcp_approval_response.py +34 -0
- arkruntime/types/responses/item_function_mcp_approval_response_param.py +28 -0
- arkruntime/types/responses/item_function_mcp_call.py +44 -0
- arkruntime/types/responses/item_function_mcp_call_param.py +38 -0
- arkruntime/types/responses/item_function_mcp_list_tools.py +36 -0
- arkruntime/types/responses/item_function_mcp_list_tools_param.py +30 -0
- arkruntime/types/responses/item_function_tool_call.py +37 -0
- arkruntime/types/responses/item_function_tool_call_output.py +22 -0
- arkruntime/types/responses/item_function_tool_call_output_param.py +26 -0
- arkruntime/types/responses/item_function_tool_call_param.py +32 -0
- arkruntime/types/responses/item_function_web_search.py +21 -0
- arkruntime/types/responses/item_input_message.py +24 -0
- arkruntime/types/responses/item_output_message.py +23 -0
- arkruntime/types/responses/item_reasoning.py +24 -0
- arkruntime/types/responses/item_reasoning_param.py +29 -0
- arkruntime/types/responses/item_reference.py +16 -0
- arkruntime/types/responses/item_status.py +17 -0
- arkruntime/types/responses/item_transcription.py +21 -0
- arkruntime/types/responses/knowledge_search_tool.py +46 -0
- arkruntime/types/responses/knowledge_search_tool_param.py +37 -0
- arkruntime/types/responses/list_input_items_response.py +21 -0
- arkruntime/types/responses/mcp_allowed_tools.py +17 -0
- arkruntime/types/responses/mcp_allowed_tools_filter.py +15 -0
- arkruntime/types/responses/mcp_allowed_tools_filter_param.py +15 -0
- arkruntime/types/responses/mcp_allowed_tools_param.py +13 -0
- arkruntime/types/responses/mcp_approval_mode.py +14 -0
- arkruntime/types/responses/mcp_list_tools_tool.py +30 -0
- arkruntime/types/responses/mcp_list_tools_tool_param.py +25 -0
- arkruntime/types/responses/mcp_require_approval.py +18 -0
- arkruntime/types/responses/mcp_require_approval_param.py +14 -0
- arkruntime/types/responses/mcp_tool.py +24 -0
- arkruntime/types/responses/mcp_tool_approval_filter.py +19 -0
- arkruntime/types/responses/mcp_tool_approval_filter_always.py +15 -0
- arkruntime/types/responses/mcp_tool_approval_filter_always_param.py +15 -0
- arkruntime/types/responses/mcp_tool_approval_filter_never.py +15 -0
- arkruntime/types/responses/mcp_tool_approval_filter_never_param.py +15 -0
- arkruntime/types/responses/mcp_tool_approval_filter_param.py +20 -0
- arkruntime/types/responses/mcp_tool_param.py +30 -0
- arkruntime/types/responses/message_content.py +15 -0
- arkruntime/types/responses/message_content_param.py +13 -0
- arkruntime/types/responses/message_role.py +16 -0
- arkruntime/types/responses/order.py +18 -0
- arkruntime/types/responses/output_content_item.py +23 -0
- arkruntime/types/responses/output_content_item_param.py +18 -0
- arkruntime/types/responses/output_content_item_reasoning_text.py +19 -0
- arkruntime/types/responses/output_content_item_reasoning_text_param.py +21 -0
- arkruntime/types/responses/output_content_item_text.py +19 -0
- arkruntime/types/responses/output_content_item_text_param.py +21 -0
- arkruntime/types/responses/output_item.py +46 -0
- arkruntime/types/responses/output_tokens_details.py +13 -0
- arkruntime/types/responses/parsed_response_shim.py +106 -0
- arkruntime/types/responses/reasoning.py +17 -0
- arkruntime/types/responses/reasoning_effort.py +19 -0
- arkruntime/types/responses/reasoning_param.py +17 -0
- arkruntime/types/responses/reasoning_summary_part.py +16 -0
- arkruntime/types/responses/reasoning_summary_part_param.py +17 -0
- arkruntime/types/responses/response.py +58 -0
- arkruntime/types/responses/response_agent_tool_call_completed_event.py +19 -0
- arkruntime/types/responses/response_agent_tool_call_in_progress_event.py +19 -0
- arkruntime/types/responses/response_caching.py +18 -0
- arkruntime/types/responses/response_caching_param.py +19 -0
- arkruntime/types/responses/response_completed_event.py +28 -0
- arkruntime/types/responses/response_content_part_added_event.py +22 -0
- arkruntime/types/responses/response_content_part_done_event.py +22 -0
- arkruntime/types/responses/response_created_event.py +28 -0
- arkruntime/types/responses/response_doubao_app_call_block_added_event.py +21 -0
- arkruntime/types/responses/response_doubao_app_call_block_done_event.py +21 -0
- arkruntime/types/responses/response_doubao_app_call_completed_event.py +22 -0
- arkruntime/types/responses/response_doubao_app_call_failed_event.py +19 -0
- arkruntime/types/responses/response_doubao_app_call_in_progress_event.py +19 -0
- arkruntime/types/responses/response_doubao_app_call_output_text_delta_event.py +20 -0
- arkruntime/types/responses/response_doubao_app_call_output_text_done_event.py +20 -0
- arkruntime/types/responses/response_doubao_app_call_reasoning_search_completed_event.py +24 -0
- arkruntime/types/responses/response_doubao_app_call_reasoning_search_in_progress_event.py +19 -0
- arkruntime/types/responses/response_doubao_app_call_reasoning_search_searching_event.py +20 -0
- arkruntime/types/responses/response_doubao_app_call_reasoning_text_delta_event.py +20 -0
- arkruntime/types/responses/response_doubao_app_call_reasoning_text_done_event.py +20 -0
- arkruntime/types/responses/response_doubao_app_call_search_completed_event.py +24 -0
- arkruntime/types/responses/response_doubao_app_call_search_in_progress_event.py +19 -0
- arkruntime/types/responses/response_doubao_app_call_search_searching_event.py +20 -0
- arkruntime/types/responses/response_error.py +20 -0
- arkruntime/types/responses/response_error_event.py +34 -0
- arkruntime/types/responses/response_failed_event.py +28 -0
- arkruntime/types/responses/response_function_call_arguments_delta_event.py +34 -0
- arkruntime/types/responses/response_function_call_arguments_done_event.py +31 -0
- arkruntime/types/responses/response_image_process_action.py +16 -0
- arkruntime/types/responses/response_image_process_call_completed_event.py +22 -0
- arkruntime/types/responses/response_image_process_call_in_progress_event.py +21 -0
- arkruntime/types/responses/response_image_process_call_processing_event.py +22 -0
- arkruntime/types/responses/response_image_process_error.py +13 -0
- arkruntime/types/responses/response_in_progress_event.py +28 -0
- arkruntime/types/responses/response_includable.py +15 -0
- arkruntime/types/responses/response_incomplete_event.py +28 -0
- arkruntime/types/responses/response_knowledge_search_call_completed_event.py +21 -0
- arkruntime/types/responses/response_knowledge_search_call_failed_event.py +21 -0
- arkruntime/types/responses/response_knowledge_search_call_in_progress_event.py +21 -0
- arkruntime/types/responses/response_knowledge_search_call_searching_event.py +21 -0
- arkruntime/types/responses/response_mcp_approval_request_event.py +20 -0
- arkruntime/types/responses/response_mcp_call_arguments_delta_event.py +35 -0
- arkruntime/types/responses/response_mcp_call_arguments_done_event.py +34 -0
- arkruntime/types/responses/response_mcp_call_completed_event.py +30 -0
- arkruntime/types/responses/response_mcp_call_failed_event.py +30 -0
- arkruntime/types/responses/response_mcp_call_in_progress_event.py +30 -0
- arkruntime/types/responses/response_mcp_list_tools_completed_event.py +30 -0
- arkruntime/types/responses/response_mcp_list_tools_failed_event.py +30 -0
- arkruntime/types/responses/response_mcp_list_tools_in_progress_event.py +30 -0
- arkruntime/types/responses/response_output_item_added_event.py +20 -0
- arkruntime/types/responses/response_output_item_done_event.py +20 -0
- arkruntime/types/responses/response_output_text_annotation_added_event.py +46 -0
- arkruntime/types/responses/response_reasoning_raw_text_delta_event.py +38 -0
- arkruntime/types/responses/response_reasoning_raw_text_done_event.py +38 -0
- arkruntime/types/responses/response_reasoning_summary_part_added_event.py +22 -0
- arkruntime/types/responses/response_reasoning_summary_part_done_event.py +22 -0
- arkruntime/types/responses/response_reasoning_summary_text_delta_event.py +38 -0
- arkruntime/types/responses/response_reasoning_summary_text_done_event.py +38 -0
- arkruntime/types/responses/response_reasoning_text_delta_event.py +38 -0
- arkruntime/types/responses/response_reasoning_text_done_event.py +38 -0
- arkruntime/types/responses/response_status.py +16 -0
- arkruntime/types/responses/response_stream_event.py +216 -0
- arkruntime/types/responses/response_text_config.py +15 -0
- arkruntime/types/responses/response_text_config_param.py +16 -0
- arkruntime/types/responses/response_text_delta_event.py +38 -0
- arkruntime/types/responses/response_text_done_event.py +38 -0
- arkruntime/types/responses/response_transcription_part_added_event.py +22 -0
- arkruntime/types/responses/response_transcription_part_done_event.py +22 -0
- arkruntime/types/responses/response_transcription_text_delta_event.py +46 -0
- arkruntime/types/responses/response_transcription_text_done_event.py +52 -0
- arkruntime/types/responses/response_usage.py +47 -0
- arkruntime/types/responses/response_web_search_call_completed_event.py +30 -0
- arkruntime/types/responses/response_web_search_call_in_progress_event.py +30 -0
- arkruntime/types/responses/response_web_search_call_searching_event.py +30 -0
- arkruntime/types/responses/responses_input.py +15 -0
- arkruntime/types/responses/responses_input_param.py +13 -0
- arkruntime/types/responses/responses_request.py +50 -0
- arkruntime/types/responses/responses_request_param.py +73 -0
- arkruntime/types/responses/service_tier.py +14 -0
- arkruntime/types/responses/session.py +13 -0
- arkruntime/types/responses/session_param.py +13 -0
- arkruntime/types/responses/text_format.py +22 -0
- arkruntime/types/responses/text_format_param.py +25 -0
- arkruntime/types/responses/text_format_type.py +15 -0
- arkruntime/types/responses/text_translation_options.py +14 -0
- arkruntime/types/responses/thinking.py +17 -0
- arkruntime/types/responses/thinking_mode.py +15 -0
- arkruntime/types/responses/thinking_param.py +17 -0
- arkruntime/types/responses/thinking_turns_param.py +16 -0
- arkruntime/types/responses/thinking_turns_param_param.py +17 -0
- arkruntime/types/responses/tool.py +34 -0
- arkruntime/types/responses/tool_choice.py +16 -0
- arkruntime/types/responses/tool_choice_function.py +22 -0
- arkruntime/types/responses/tool_choice_function_param.py +19 -0
- arkruntime/types/responses/tool_choice_knowledge_search.py +15 -0
- arkruntime/types/responses/tool_choice_knowledge_search_param.py +15 -0
- arkruntime/types/responses/tool_choice_mcp.py +26 -0
- arkruntime/types/responses/tool_choice_mcp_param.py +22 -0
- arkruntime/types/responses/tool_choice_options.py +15 -0
- arkruntime/types/responses/tool_choice_param.py +14 -0
- arkruntime/types/responses/tool_choice_web_search.py +15 -0
- arkruntime/types/responses/tool_choice_web_search_param.py +15 -0
- arkruntime/types/responses/tool_name_list.py +15 -0
- arkruntime/types/responses/tool_name_list_param.py +15 -0
- arkruntime/types/responses/tool_param.py +25 -0
- arkruntime/types/responses/tool_usage.py +27 -0
- arkruntime/types/responses/tool_usage_details.py +30 -0
- arkruntime/types/responses/tool_uses_keep.py +16 -0
- arkruntime/types/responses/tool_uses_keep_param.py +17 -0
- arkruntime/types/responses/tool_uses_trigger.py +16 -0
- arkruntime/types/responses/tool_uses_trigger_param.py +17 -0
- arkruntime/types/responses/transcription_part.py +19 -0
- arkruntime/types/responses/truncation_mode.py +14 -0
- arkruntime/types/responses/typed_tool_choice.py +30 -0
- arkruntime/types/responses/typed_tool_choice_param.py +21 -0
- arkruntime/types/responses/url_citation.py +26 -0
- arkruntime/types/responses/url_citation_param.py +35 -0
- arkruntime/types/responses/user_location.py +34 -0
- arkruntime/types/responses/user_location_param.py +28 -0
- arkruntime/types/responses/web_search_action.py +16 -0
- arkruntime/types/responses/web_search_source.py +16 -0
- arkruntime/types/responses/web_search_tool.py +22 -0
- arkruntime/types/responses/web_search_tool_param.py +26 -0
- arkruntime/types/session/__init__.py +154 -0
- arkruntime/types/session/_init_extras_shim.py +88 -0
- arkruntime/types/session/agent_identifier.py +19 -0
- arkruntime/types/session/agent_ref.py +31 -0
- arkruntime/types/session/base64_document_source.py +27 -0
- arkruntime/types/session/base64_image_source.py +27 -0
- arkruntime/types/session/cache_creation.py +26 -0
- arkruntime/types/session/create_session_request.py +50 -0
- arkruntime/types/session/create_session_resource_request.py +29 -0
- arkruntime/types/session/delete_session_response.py +24 -0
- arkruntime/types/session/document_source.py +34 -0
- arkruntime/types/session/file_document_source.py +23 -0
- arkruntime/types/session/file_image_source.py +23 -0
- arkruntime/types/session/image_source.py +28 -0
- arkruntime/types/session/list_session_events_response_wire.py +31 -0
- arkruntime/types/session/list_session_resources_response.py +24 -0
- arkruntime/types/session/list_session_threads_response.py +28 -0
- arkruntime/types/session/list_sessions_order.py +18 -0
- arkruntime/types/session/list_sessions_response.py +28 -0
- arkruntime/types/session/managed_agents_agent_message_preview.py +27 -0
- arkruntime/types/session/managed_agents_agent_thinking_preview.py +27 -0
- arkruntime/types/session/managed_agents_delta_content.py +34 -0
- arkruntime/types/session/managed_agents_delta_event.py +34 -0
- arkruntime/types/session/managed_agents_delta_text_block.py +27 -0
- arkruntime/types/session/managed_agents_document_block.py +33 -0
- arkruntime/types/session/managed_agents_event_params.py +57 -0
- arkruntime/types/session/managed_agents_file_rubric_params.py +23 -0
- arkruntime/types/session/managed_agents_image_block.py +25 -0
- arkruntime/types/session/managed_agents_message_content_block.py +30 -0
- arkruntime/types/session/managed_agents_rubric.py +26 -0
- arkruntime/types/session/managed_agents_search_result_block.py +38 -0
- arkruntime/types/session/managed_agents_session_event.py +34 -0
- arkruntime/types/session/managed_agents_start_event.py +31 -0
- arkruntime/types/session/managed_agents_start_event_preview.py +27 -0
- arkruntime/types/session/managed_agents_stream_preview_event.py +26 -0
- arkruntime/types/session/managed_agents_system_content_block.py +23 -0
- arkruntime/types/session/managed_agents_system_message_event_params.py +34 -0
- arkruntime/types/session/managed_agents_text_block.py +23 -0
- arkruntime/types/session/managed_agents_text_rubric_params.py +23 -0
- arkruntime/types/session/managed_agents_tool_result_content_block.py +34 -0
- arkruntime/types/session/managed_agents_user_custom_tool_result_event_params.py +44 -0
- arkruntime/types/session/managed_agents_user_define_outcome_event_params.py +45 -0
- arkruntime/types/session/managed_agents_user_interrupt_event_params.py +31 -0
- arkruntime/types/session/managed_agents_user_message_event_params.py +34 -0
- arkruntime/types/session/managed_agents_user_tool_confirmation_event_params.py +46 -0
- arkruntime/types/session/managed_agents_user_tool_result_event_params.py +44 -0
- arkruntime/types/session/plain_text_document_source.py +27 -0
- arkruntime/types/session/search_result_citations.py +20 -0
- arkruntime/types/session/search_result_content.py +20 -0
- arkruntime/types/session/send_session_events_request.py +24 -0
- arkruntime/types/session/send_session_events_response.py +22 -0
- arkruntime/types/session/session.py +80 -0
- arkruntime/types/session/session_resource.py +70 -0
- arkruntime/types/session/session_resource_access.py +18 -0
- arkruntime/types/session/session_resource_type.py +19 -0
- arkruntime/types/session/session_status.py +20 -0
- arkruntime/types/session/session_stream_shim.py +540 -0
- arkruntime/types/session/session_thread.py +56 -0
- arkruntime/types/session/session_thread_status.py +20 -0
- arkruntime/types/session/session_usage.py +36 -0
- arkruntime/types/session/tag.py +26 -0
- arkruntime/types/session/tool_confirmation_result.py +18 -0
- arkruntime/types/session/update_session_request.py +28 -0
- arkruntime/types/session/url_document_source.py +23 -0
- arkruntime/types/session/url_image_source.py +23 -0
- arkruntime/types/skill/__init__.py +18 -0
- arkruntime/types/skill/_init_extras_shim.py +12 -0
- arkruntime/types/skill/create_skill_request.py +18 -0
- arkruntime/types/skill/skill.py +46 -0
- arkruntime/types/tokenization/__init__.py +24 -0
- arkruntime/types/tokenization/_init_extras_shim.py +12 -0
- arkruntime/types/tokenization/tokenization_input.py +17 -0
- arkruntime/types/tokenization/tokenization_input_param.py +15 -0
- arkruntime/types/tokenization/tokenization_item.py +39 -0
- arkruntime/types/tokenization/tokenization_request.py +30 -0
- arkruntime/types/tokenization/tokenization_request_param.py +30 -0
- arkruntime/types/tokenization/tokenization_response.py +36 -0
- arkruntime/types/vault/__init__.py +62 -0
- arkruntime/types/vault/_init_extras_shim.py +12 -0
- arkruntime/types/vault/create_credential_request.py +32 -0
- arkruntime/types/vault/create_vault_request.py +26 -0
- arkruntime/types/vault/credential.py +52 -0
- arkruntime/types/vault/credential_auth.py +64 -0
- arkruntime/types/vault/credential_auth_type.py +22 -0
- arkruntime/types/vault/credential_networking.py +29 -0
- arkruntime/types/vault/credential_networking_type.py +18 -0
- arkruntime/types/vault/credential_validation.py +54 -0
- arkruntime/types/vault/delete_credential_response.py +26 -0
- arkruntime/types/vault/delete_vault_response.py +26 -0
- arkruntime/types/vault/limited_credential_networking.py +22 -0
- arkruntime/types/vault/list_credentials_response.py +35 -0
- arkruntime/types/vault/list_vaults_response.py +32 -0
- arkruntime/types/vault/mcp_probe.py +26 -0
- arkruntime/types/vault/mcpo_auth_refresh.py +45 -0
- arkruntime/types/vault/refresh_http_response.py +32 -0
- arkruntime/types/vault/refresh_object.py +27 -0
- arkruntime/types/vault/refresh_status.py +20 -0
- arkruntime/types/vault/token_endpoint_auth.py +29 -0
- arkruntime/types/vault/token_endpoint_auth_type.py +19 -0
- arkruntime/types/vault/update_credential_request.py +35 -0
- arkruntime/types/vault/update_vault_request.py +27 -0
- arkruntime/types/vault/validation_status.py +19 -0
- arkruntime/types/vault/vault.py +42 -0
- arkruntime-0.1.0.dist-info/METADATA +347 -0
- arkruntime-0.1.0.dist-info/RECORD +714 -0
- arkruntime-0.1.0.dist-info/WHEEL +5 -0
- arkruntime-0.1.0.dist-info/licenses/LICENSE +201 -0
- arkruntime-0.1.0.dist-info/top_level.txt +1 -0
arkruntime/_streaming.py
ADDED
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
# Copyright (c) 2025 ByteDance Ltd. and/or its affiliates.
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
# License text: https://github.com/volcengine/ark-runtime-python/blob/main/LICENSE
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import inspect
|
|
8
|
+
import json
|
|
9
|
+
from types import TracebackType
|
|
10
|
+
from typing import (
|
|
11
|
+
TYPE_CHECKING,
|
|
12
|
+
Any,
|
|
13
|
+
AsyncIterator,
|
|
14
|
+
Generic,
|
|
15
|
+
Iterator,
|
|
16
|
+
Optional,
|
|
17
|
+
TypeVar,
|
|
18
|
+
cast,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
import httpx
|
|
22
|
+
from typing_extensions import (
|
|
23
|
+
Protocol,
|
|
24
|
+
Self,
|
|
25
|
+
TypeGuard,
|
|
26
|
+
get_origin,
|
|
27
|
+
override,
|
|
28
|
+
runtime_checkable,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
from ._constants import CLIENT_REQUEST_HEADER
|
|
32
|
+
from ._exceptions import ArkAPIError
|
|
33
|
+
from ._utils import extract_type_var_from_base
|
|
34
|
+
from ._utils._utils import is_mapping
|
|
35
|
+
|
|
36
|
+
if TYPE_CHECKING:
|
|
37
|
+
from ._client import Ark, AsyncArk
|
|
38
|
+
|
|
39
|
+
_T = TypeVar("_T")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class Stream(Generic[_T]):
|
|
43
|
+
"""Provides the core interface to iterate over a synchronous stream response."""
|
|
44
|
+
|
|
45
|
+
response: httpx.Response
|
|
46
|
+
|
|
47
|
+
_decoder: SSEBytesDecoder
|
|
48
|
+
|
|
49
|
+
def __init__(
|
|
50
|
+
self,
|
|
51
|
+
*,
|
|
52
|
+
cast_to: type[_T],
|
|
53
|
+
response: httpx.Response,
|
|
54
|
+
client: Ark,
|
|
55
|
+
iterator: Optional[Iterator[_T]] | None = None,
|
|
56
|
+
) -> None:
|
|
57
|
+
if iterator is not None:
|
|
58
|
+
self._iterator = iterator
|
|
59
|
+
else:
|
|
60
|
+
self.response = response
|
|
61
|
+
self._cast_to = cast_to
|
|
62
|
+
self._client = client
|
|
63
|
+
self._decoder = client._make_sse_decoder()
|
|
64
|
+
self._iterator = self.__stream__()
|
|
65
|
+
|
|
66
|
+
@classmethod
|
|
67
|
+
def _make_stream_from_iterator(cls, iterator: Iterator[_T]) -> Stream[_T]:
|
|
68
|
+
return Stream(cast_to=None, response=None, client=None, iterator=iterator)
|
|
69
|
+
|
|
70
|
+
def __next__(self) -> _T:
|
|
71
|
+
return self._iterator.__next__()
|
|
72
|
+
|
|
73
|
+
def __iter__(self) -> Iterator[_T]:
|
|
74
|
+
for item in self._iterator:
|
|
75
|
+
yield item
|
|
76
|
+
|
|
77
|
+
def _iter_events(self) -> Iterator[ServerSentEvent]:
|
|
78
|
+
yield from self._decoder.iter_bytes(self.response.iter_bytes())
|
|
79
|
+
|
|
80
|
+
def __stream__(self) -> Iterator[_T]:
|
|
81
|
+
cast_to = cast(Any, self._cast_to)
|
|
82
|
+
response = self.response
|
|
83
|
+
process_data = self._client._process_response_data
|
|
84
|
+
iterator = self._iter_events()
|
|
85
|
+
request_id = self.response.headers.get(CLIENT_REQUEST_HEADER, "") if response else None
|
|
86
|
+
|
|
87
|
+
for sse in iterator:
|
|
88
|
+
if sse.data.startswith("[DONE]"):
|
|
89
|
+
break
|
|
90
|
+
|
|
91
|
+
if sse.event is None or (isinstance(sse.event, str) and len(sse.event) > 0):
|
|
92
|
+
data = sse.json()
|
|
93
|
+
if is_mapping(data) and data.get("error"):
|
|
94
|
+
message = None
|
|
95
|
+
error = data.get("error")
|
|
96
|
+
if is_mapping(error):
|
|
97
|
+
message = error.get("message")
|
|
98
|
+
if not message or not isinstance(message, str):
|
|
99
|
+
message = "An error occurred during streaming"
|
|
100
|
+
|
|
101
|
+
raise ArkAPIError(
|
|
102
|
+
message=message,
|
|
103
|
+
request=self.response.request,
|
|
104
|
+
body=data["error"],
|
|
105
|
+
request_id=request_id,
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
yield process_data(data=data, cast_to=cast_to, response=response)
|
|
109
|
+
|
|
110
|
+
else:
|
|
111
|
+
data = sse.json()
|
|
112
|
+
|
|
113
|
+
if sse.event == "error" and is_mapping(data) and data.get("error"):
|
|
114
|
+
message = None
|
|
115
|
+
error = data.get("error")
|
|
116
|
+
if is_mapping(error):
|
|
117
|
+
message = error.get("message")
|
|
118
|
+
if not message or not isinstance(message, str):
|
|
119
|
+
message = "An error occurred during streaming"
|
|
120
|
+
|
|
121
|
+
raise ArkAPIError(
|
|
122
|
+
message=message,
|
|
123
|
+
request=self.response.request,
|
|
124
|
+
body=data["error"],
|
|
125
|
+
request_id=request_id,
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
yield process_data(
|
|
129
|
+
data={"data": data, "event": sse.event},
|
|
130
|
+
cast_to=cast_to,
|
|
131
|
+
response=response,
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
# Ensure the entire stream is consumed
|
|
135
|
+
for _sse in iterator:
|
|
136
|
+
...
|
|
137
|
+
|
|
138
|
+
def __enter__(self) -> Self:
|
|
139
|
+
return self
|
|
140
|
+
|
|
141
|
+
def __exit__(
|
|
142
|
+
self,
|
|
143
|
+
exc_type: type[BaseException] | None,
|
|
144
|
+
exc: BaseException | None,
|
|
145
|
+
exc_tb: TracebackType | None,
|
|
146
|
+
) -> None:
|
|
147
|
+
self.close()
|
|
148
|
+
|
|
149
|
+
def close(self) -> None:
|
|
150
|
+
"""
|
|
151
|
+
Close the response and release the connection.
|
|
152
|
+
|
|
153
|
+
Automatically called if the response body is read to completion.
|
|
154
|
+
"""
|
|
155
|
+
self.response.close()
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
class AsyncStream(Generic[_T]):
|
|
159
|
+
"""Provides the core interface to iterate over an asynchronous stream response."""
|
|
160
|
+
|
|
161
|
+
response: httpx.Response
|
|
162
|
+
|
|
163
|
+
_decoder: SSEDecoder | SSEBytesDecoder
|
|
164
|
+
|
|
165
|
+
def __init__(
|
|
166
|
+
self,
|
|
167
|
+
*,
|
|
168
|
+
cast_to: type[_T],
|
|
169
|
+
response: httpx.Response,
|
|
170
|
+
client: AsyncArk,
|
|
171
|
+
iterator: Optional[AsyncIterator[_T]] | None = None,
|
|
172
|
+
) -> None:
|
|
173
|
+
if iterator is not None:
|
|
174
|
+
self._iterator = iterator
|
|
175
|
+
else:
|
|
176
|
+
self.response = response
|
|
177
|
+
self._cast_to = cast_to
|
|
178
|
+
self._client = client
|
|
179
|
+
self._decoder = client._make_sse_decoder()
|
|
180
|
+
self._iterator = self.__stream__()
|
|
181
|
+
|
|
182
|
+
@classmethod
|
|
183
|
+
def _make_stream_from_iterator(cls, iterator: AsyncIterator[_T]) -> AsyncStream[_T]:
|
|
184
|
+
return AsyncStream(cast_to=None, response=None, client=None, iterator=iterator)
|
|
185
|
+
|
|
186
|
+
async def __anext__(self) -> _T:
|
|
187
|
+
return await self._iterator.__anext__()
|
|
188
|
+
|
|
189
|
+
async def __aiter__(self) -> AsyncIterator[_T]:
|
|
190
|
+
async for item in self._iterator:
|
|
191
|
+
yield item
|
|
192
|
+
|
|
193
|
+
async def _iter_events(self) -> AsyncIterator[ServerSentEvent]:
|
|
194
|
+
async for sse in self._decoder.aiter_bytes(self.response.aiter_bytes()):
|
|
195
|
+
yield sse
|
|
196
|
+
|
|
197
|
+
async def __stream__(self) -> AsyncIterator[_T]:
|
|
198
|
+
cast_to = cast(Any, self._cast_to)
|
|
199
|
+
response = self.response
|
|
200
|
+
process_data = self._client._process_response_data
|
|
201
|
+
iterator = self._iter_events()
|
|
202
|
+
request_id = response.headers.get(CLIENT_REQUEST_HEADER, "") if response else None
|
|
203
|
+
|
|
204
|
+
async for sse in iterator:
|
|
205
|
+
if sse.data.startswith("[DONE]"):
|
|
206
|
+
break
|
|
207
|
+
|
|
208
|
+
if sse.event is None or (isinstance(sse.event, str) and len(sse.event) > 0):
|
|
209
|
+
data = sse.json()
|
|
210
|
+
if is_mapping(data) and data.get("error"):
|
|
211
|
+
message = None
|
|
212
|
+
error = data.get("error")
|
|
213
|
+
if is_mapping(error):
|
|
214
|
+
message = error.get("message")
|
|
215
|
+
if not message or not isinstance(message, str):
|
|
216
|
+
message = "An error occurred during streaming"
|
|
217
|
+
|
|
218
|
+
raise ArkAPIError(
|
|
219
|
+
message=message,
|
|
220
|
+
request=self.response.request,
|
|
221
|
+
body=data["error"],
|
|
222
|
+
request_id=request_id,
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
yield process_data(data=data, cast_to=cast_to, response=response)
|
|
226
|
+
|
|
227
|
+
else:
|
|
228
|
+
data = sse.json()
|
|
229
|
+
|
|
230
|
+
if sse.event == "error" and is_mapping(data) and data.get("error"):
|
|
231
|
+
message = None
|
|
232
|
+
error = data.get("error")
|
|
233
|
+
if is_mapping(error):
|
|
234
|
+
message = error.get("message")
|
|
235
|
+
if not message or not isinstance(message, str):
|
|
236
|
+
message = "An error occurred during streaming"
|
|
237
|
+
|
|
238
|
+
raise ArkAPIError(
|
|
239
|
+
message=message,
|
|
240
|
+
request=self.response.request,
|
|
241
|
+
body=data["error"],
|
|
242
|
+
request_id=request_id,
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
yield process_data(
|
|
246
|
+
data={"data": data, "event": sse.event},
|
|
247
|
+
cast_to=cast_to,
|
|
248
|
+
response=response,
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
# Ensure the entire stream is consumed
|
|
252
|
+
async for _sse in iterator:
|
|
253
|
+
...
|
|
254
|
+
|
|
255
|
+
async def __aenter__(self) -> Self:
|
|
256
|
+
return self
|
|
257
|
+
|
|
258
|
+
async def __aexit__(
|
|
259
|
+
self,
|
|
260
|
+
exc_type: type[BaseException] | None,
|
|
261
|
+
exc: BaseException | None,
|
|
262
|
+
exc_tb: TracebackType | None,
|
|
263
|
+
) -> None:
|
|
264
|
+
await self.close()
|
|
265
|
+
|
|
266
|
+
async def close(self) -> None:
|
|
267
|
+
"""
|
|
268
|
+
Close the response and release the connection.
|
|
269
|
+
|
|
270
|
+
Automatically called if the response body is read to completion.
|
|
271
|
+
"""
|
|
272
|
+
await self.response.aclose()
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
class ServerSentEvent:
|
|
276
|
+
def __init__(
|
|
277
|
+
self,
|
|
278
|
+
*,
|
|
279
|
+
event: str | None = None,
|
|
280
|
+
data: str | None = None,
|
|
281
|
+
id: str | None = None,
|
|
282
|
+
retry: int | None = None,
|
|
283
|
+
) -> None:
|
|
284
|
+
if data is None:
|
|
285
|
+
data = ""
|
|
286
|
+
|
|
287
|
+
self._id = id
|
|
288
|
+
self._data = data
|
|
289
|
+
self._event = event or None
|
|
290
|
+
self._retry = retry
|
|
291
|
+
|
|
292
|
+
@property
|
|
293
|
+
def event(self) -> str | None:
|
|
294
|
+
return self._event
|
|
295
|
+
|
|
296
|
+
@property
|
|
297
|
+
def id(self) -> str | None:
|
|
298
|
+
return self._id
|
|
299
|
+
|
|
300
|
+
@property
|
|
301
|
+
def retry(self) -> int | None:
|
|
302
|
+
return self._retry
|
|
303
|
+
|
|
304
|
+
@property
|
|
305
|
+
def data(self) -> str:
|
|
306
|
+
return self._data
|
|
307
|
+
|
|
308
|
+
def json(self) -> Any:
|
|
309
|
+
return json.loads(self.data)
|
|
310
|
+
|
|
311
|
+
@override
|
|
312
|
+
def __repr__(self) -> str:
|
|
313
|
+
return f"ServerSentEvent(event={self.event}, data={self.data}, id={self.id}, retry={self.retry})"
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
class SSEDecoder:
|
|
317
|
+
_data: list[str]
|
|
318
|
+
_event: str | None
|
|
319
|
+
_retry: int | None
|
|
320
|
+
_last_event_id: str | None
|
|
321
|
+
|
|
322
|
+
def __init__(self) -> None:
|
|
323
|
+
self._event = None
|
|
324
|
+
self._data = []
|
|
325
|
+
self._last_event_id = None
|
|
326
|
+
self._retry = None
|
|
327
|
+
|
|
328
|
+
def iter_bytes(self, iterator: Iterator[bytes]) -> Iterator[ServerSentEvent]:
|
|
329
|
+
"""Given an iterator that yields raw binary data, iterate over it & yield every event encountered"""
|
|
330
|
+
for chunk in self._iter_chunks(iterator):
|
|
331
|
+
# Split before decoding so splitlines() only uses \r and \n
|
|
332
|
+
for raw_line in chunk.splitlines():
|
|
333
|
+
line = raw_line.decode("utf-8")
|
|
334
|
+
sse = self.decode(line)
|
|
335
|
+
if sse:
|
|
336
|
+
yield sse
|
|
337
|
+
|
|
338
|
+
def _iter_chunks(self, iterator: Iterator[bytes]) -> Iterator[bytes]:
|
|
339
|
+
"""Given an iterator that yields raw binary data, iterate over it and yield individual SSE chunks"""
|
|
340
|
+
data = b""
|
|
341
|
+
for chunk in iterator:
|
|
342
|
+
for line in chunk.splitlines(keepends=True):
|
|
343
|
+
data += line
|
|
344
|
+
if data.endswith((b"\r\r", b"\n\n", b"\r\n\r\n")):
|
|
345
|
+
yield data
|
|
346
|
+
data = b""
|
|
347
|
+
if data:
|
|
348
|
+
yield data
|
|
349
|
+
|
|
350
|
+
async def aiter_bytes(self, iterator: AsyncIterator[bytes]) -> AsyncIterator[ServerSentEvent]:
|
|
351
|
+
"""Given an iterator that yields raw binary data, iterate over it & yield every event encountered"""
|
|
352
|
+
async for chunk in self._aiter_chunks(iterator):
|
|
353
|
+
# Split before decoding so splitlines() only uses \r and \n
|
|
354
|
+
for raw_line in chunk.splitlines():
|
|
355
|
+
line = raw_line.decode("utf-8")
|
|
356
|
+
sse = self.decode(line)
|
|
357
|
+
if sse:
|
|
358
|
+
yield sse
|
|
359
|
+
|
|
360
|
+
async def _aiter_chunks(self, iterator: AsyncIterator[bytes]) -> AsyncIterator[bytes]:
|
|
361
|
+
"""Given an iterator that yields raw binary data, iterate over it and yield individual SSE chunks"""
|
|
362
|
+
data = b""
|
|
363
|
+
async for chunk in iterator:
|
|
364
|
+
for line in chunk.splitlines(keepends=True):
|
|
365
|
+
data += line
|
|
366
|
+
if data.endswith((b"\r\r", b"\n\n", b"\r\n\r\n")):
|
|
367
|
+
yield data
|
|
368
|
+
data = b""
|
|
369
|
+
if data:
|
|
370
|
+
yield data
|
|
371
|
+
|
|
372
|
+
def decode(self, line: str) -> ServerSentEvent | None:
|
|
373
|
+
if not line:
|
|
374
|
+
if not self._event and not self._data and not self._last_event_id and self._retry is None:
|
|
375
|
+
return None
|
|
376
|
+
|
|
377
|
+
sse = ServerSentEvent(
|
|
378
|
+
event=self._event,
|
|
379
|
+
data="\n".join(self._data),
|
|
380
|
+
id=self._last_event_id,
|
|
381
|
+
retry=self._retry,
|
|
382
|
+
)
|
|
383
|
+
|
|
384
|
+
# NOTE: as per the SSE spec, do not reset last_event_id.
|
|
385
|
+
self._event = None
|
|
386
|
+
self._data = []
|
|
387
|
+
self._retry = None
|
|
388
|
+
|
|
389
|
+
return sse
|
|
390
|
+
|
|
391
|
+
if line.startswith(":"):
|
|
392
|
+
return None
|
|
393
|
+
|
|
394
|
+
fieldname, _, value = line.partition(":")
|
|
395
|
+
|
|
396
|
+
if value.startswith(" "):
|
|
397
|
+
value = value[1:]
|
|
398
|
+
|
|
399
|
+
if fieldname == "event":
|
|
400
|
+
self._event = value
|
|
401
|
+
elif fieldname == "data":
|
|
402
|
+
self._data.append(value)
|
|
403
|
+
elif fieldname == "id":
|
|
404
|
+
if "\0" in value:
|
|
405
|
+
pass
|
|
406
|
+
else:
|
|
407
|
+
self._last_event_id = value
|
|
408
|
+
elif fieldname == "retry":
|
|
409
|
+
try:
|
|
410
|
+
self._retry = int(value)
|
|
411
|
+
except (TypeError, ValueError):
|
|
412
|
+
pass
|
|
413
|
+
else:
|
|
414
|
+
pass # Field is ignored.
|
|
415
|
+
|
|
416
|
+
return None
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
@runtime_checkable
|
|
420
|
+
class SSEBytesDecoder(Protocol):
|
|
421
|
+
def iter_bytes(self, iterator: Iterator[bytes]) -> Iterator[ServerSentEvent]:
|
|
422
|
+
"""Given an iterator that yields raw binary data, iterate over it & yield every event encountered"""
|
|
423
|
+
...
|
|
424
|
+
|
|
425
|
+
def aiter_bytes(self, iterator: AsyncIterator[bytes]) -> AsyncIterator[ServerSentEvent]:
|
|
426
|
+
"""Given an async iterator that yields raw binary data, iterate over it & yield every event encountered"""
|
|
427
|
+
...
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
def is_stream_class_type(
|
|
431
|
+
typ: type,
|
|
432
|
+
) -> TypeGuard[type[Stream[object]] | type[AsyncStream[object]]]:
|
|
433
|
+
"""TypeGuard for determining whether or not the given type is a subclass of `Stream` / `AsyncStream`"""
|
|
434
|
+
origin = get_origin(typ) or typ
|
|
435
|
+
return inspect.isclass(origin) and issubclass(origin, (Stream, AsyncStream))
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
def extract_stream_chunk_type(
|
|
439
|
+
stream_cls: type,
|
|
440
|
+
*,
|
|
441
|
+
failure_message: str | None = None,
|
|
442
|
+
) -> type:
|
|
443
|
+
"""Given a type like `Stream[T]`, returns the generic type variable `T`.
|
|
444
|
+
|
|
445
|
+
This also handles the case where a concrete subclass is given, e.g.
|
|
446
|
+
```py
|
|
447
|
+
class MyStream(Stream[bytes]):
|
|
448
|
+
...
|
|
449
|
+
|
|
450
|
+
extract_stream_chunk_type(MyStream) -> bytes
|
|
451
|
+
```
|
|
452
|
+
"""
|
|
453
|
+
from ._base_client import AsyncStream, Stream
|
|
454
|
+
|
|
455
|
+
return extract_type_var_from_base(
|
|
456
|
+
stream_cls,
|
|
457
|
+
index=0,
|
|
458
|
+
generic_bases=cast("tuple[type, ...]", (Stream, AsyncStream)),
|
|
459
|
+
failure_message=failure_message,
|
|
460
|
+
)
|
arkruntime/_types.py
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# Copyright (c) 2025 ByteDance Ltd. and/or its affiliates.
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
# License text: https://github.com/volcengine/ark-runtime-python/blob/main/LICENSE
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import functools
|
|
8
|
+
from collections import defaultdict
|
|
9
|
+
from os import PathLike
|
|
10
|
+
from typing import (
|
|
11
|
+
IO,
|
|
12
|
+
TYPE_CHECKING,
|
|
13
|
+
Any,
|
|
14
|
+
Callable,
|
|
15
|
+
Dict,
|
|
16
|
+
List,
|
|
17
|
+
Mapping,
|
|
18
|
+
Optional,
|
|
19
|
+
Sequence,
|
|
20
|
+
Tuple,
|
|
21
|
+
Type,
|
|
22
|
+
TypeVar,
|
|
23
|
+
Union,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
import pydantic
|
|
27
|
+
from httpx import Response
|
|
28
|
+
from typing_extensions import (
|
|
29
|
+
Literal,
|
|
30
|
+
Protocol,
|
|
31
|
+
Set,
|
|
32
|
+
TypeAlias,
|
|
33
|
+
override,
|
|
34
|
+
runtime_checkable,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
if TYPE_CHECKING:
|
|
38
|
+
from ._models import BaseModel
|
|
39
|
+
from ._response import ArkAPIResponse, ArkAsyncAPIResponse
|
|
40
|
+
|
|
41
|
+
ModelT = TypeVar("ModelT", bound=pydantic.BaseModel)
|
|
42
|
+
_T = TypeVar("_T")
|
|
43
|
+
ResponseT = TypeVar(
|
|
44
|
+
"ResponseT",
|
|
45
|
+
bound=Union[
|
|
46
|
+
object,
|
|
47
|
+
str,
|
|
48
|
+
None,
|
|
49
|
+
"BaseModel",
|
|
50
|
+
List[Any],
|
|
51
|
+
Dict[str, Any],
|
|
52
|
+
Response,
|
|
53
|
+
"ArkAPIResponse[Any]",
|
|
54
|
+
"ArkAsyncAPIResponse[Any]",
|
|
55
|
+
],
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
if TYPE_CHECKING:
|
|
59
|
+
Base64FileInput = Union[IO[bytes], PathLike[str]]
|
|
60
|
+
FileContent = Union[IO[bytes], bytes, PathLike[str]]
|
|
61
|
+
else:
|
|
62
|
+
Base64FileInput = Union[IO[bytes], PathLike]
|
|
63
|
+
FileContent = Union[IO[bytes], bytes, PathLike] # PathLike is not subscriptable in Python 3.8.
|
|
64
|
+
|
|
65
|
+
FileTypes = Union[
|
|
66
|
+
# file (or bytes)
|
|
67
|
+
FileContent,
|
|
68
|
+
# (filename, file (or bytes))
|
|
69
|
+
Tuple[Optional[str], FileContent],
|
|
70
|
+
# (filename, file (or bytes), content_type)
|
|
71
|
+
Tuple[Optional[str], FileContent, Optional[str]],
|
|
72
|
+
# (filename, file (or bytes), content_type, headers)
|
|
73
|
+
Tuple[Optional[str], FileContent, Optional[str], Mapping[str, str]],
|
|
74
|
+
]
|
|
75
|
+
RequestFiles = Union[Mapping[str, FileTypes], Sequence[Tuple[str, FileTypes]]]
|
|
76
|
+
|
|
77
|
+
# duplicate of the above but without our custom file support
|
|
78
|
+
HttpxFileContent = Union[IO[bytes], bytes]
|
|
79
|
+
HttpxFileTypes = Union[
|
|
80
|
+
# file (or bytes)
|
|
81
|
+
HttpxFileContent,
|
|
82
|
+
# (filename, file (or bytes))
|
|
83
|
+
Tuple[Optional[str], HttpxFileContent],
|
|
84
|
+
# (filename, file (or bytes), content_type)
|
|
85
|
+
Tuple[Optional[str], HttpxFileContent, Optional[str]],
|
|
86
|
+
# (filename, file (or bytes), content_type, headers)
|
|
87
|
+
Tuple[Optional[str], HttpxFileContent, Optional[str], Mapping[str, str]],
|
|
88
|
+
]
|
|
89
|
+
HttpxRequestFiles = Union[Mapping[str, HttpxFileTypes], Sequence[Tuple[str, HttpxFileTypes]]]
|
|
90
|
+
|
|
91
|
+
if TYPE_CHECKING:
|
|
92
|
+
NoneType: Type[None]
|
|
93
|
+
else:
|
|
94
|
+
NoneType = type(None)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class NotGiven:
|
|
98
|
+
"""
|
|
99
|
+
A sentinel singleton class used to distinguish omitted keyword arguments
|
|
100
|
+
from those passed in with the value None (which may have different behavior).
|
|
101
|
+
|
|
102
|
+
For example:
|
|
103
|
+
|
|
104
|
+
```py
|
|
105
|
+
def get(timeout: Union[int, NotGiven, None] = NotGiven()) -> Response:
|
|
106
|
+
...
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
get(timeout=1) # 1s timeout
|
|
110
|
+
get(timeout=None) # No timeout
|
|
111
|
+
get() # Default timeout behavior, which may not be statically known at the method definition.
|
|
112
|
+
```
|
|
113
|
+
"""
|
|
114
|
+
|
|
115
|
+
def __bool__(self) -> Literal[False]:
|
|
116
|
+
return False
|
|
117
|
+
|
|
118
|
+
@override
|
|
119
|
+
def __repr__(self) -> str:
|
|
120
|
+
return "NOT_GIVEN"
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
NotGivenOr = Union[_T, NotGiven]
|
|
124
|
+
NOT_GIVEN = NotGiven()
|
|
125
|
+
|
|
126
|
+
Headers = Dict[str, str]
|
|
127
|
+
Query = Dict[str, object]
|
|
128
|
+
Body = Dict[str, object]
|
|
129
|
+
AnyMapping = Mapping[str, object]
|
|
130
|
+
|
|
131
|
+
IncEx: TypeAlias = Union[
|
|
132
|
+
Set[int],
|
|
133
|
+
Set[str],
|
|
134
|
+
Mapping[int, Union["IncEx", bool]],
|
|
135
|
+
Mapping[str, Union["IncEx", bool]],
|
|
136
|
+
]
|
|
137
|
+
|
|
138
|
+
PostParser = Callable[[Any], Any]
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
@runtime_checkable
|
|
142
|
+
class InheritsGeneric(Protocol):
|
|
143
|
+
"""Represents a type that has inherited from `Generic`
|
|
144
|
+
|
|
145
|
+
The `__orig_bases__` property can be used to determine the resolved
|
|
146
|
+
type variable for a given base class.
|
|
147
|
+
"""
|
|
148
|
+
|
|
149
|
+
__orig_bases__: tuple[_GenericAlias]
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
class _GenericAlias(Protocol):
|
|
153
|
+
__origin__: type[object]
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
_overload_registry = defaultdict(functools.partial(defaultdict, dict))
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def _overload_dummy(*args, **kwds):
|
|
160
|
+
"""Helper for @overload to raise when called."""
|
|
161
|
+
raise NotImplementedError(
|
|
162
|
+
"You should not call an overloaded function. "
|
|
163
|
+
"A series of @overload-decorated functions "
|
|
164
|
+
"outside a stub module should always be followed "
|
|
165
|
+
"by an implementation that is not @overload-ed."
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def overload(func):
|
|
170
|
+
"""Decorator for overloaded functions/methods.
|
|
171
|
+
|
|
172
|
+
In a stub file, place two or more stub definitions for the same
|
|
173
|
+
function in a row, each decorated with @overload.
|
|
174
|
+
|
|
175
|
+
For example::
|
|
176
|
+
|
|
177
|
+
@overload
|
|
178
|
+
def utf8(value: None) -> None: ...
|
|
179
|
+
@overload
|
|
180
|
+
def utf8(value: bytes) -> bytes: ...
|
|
181
|
+
@overload
|
|
182
|
+
def utf8(value: str) -> bytes: ...
|
|
183
|
+
|
|
184
|
+
In a non-stub file (i.e. a regular .py file), do the same but
|
|
185
|
+
follow it with an implementation. The implementation should *not*
|
|
186
|
+
be decorated with @overload::
|
|
187
|
+
|
|
188
|
+
@overload
|
|
189
|
+
def utf8(value: None) -> None: ...
|
|
190
|
+
@overload
|
|
191
|
+
def utf8(value: bytes) -> bytes: ...
|
|
192
|
+
@overload
|
|
193
|
+
def utf8(value: str) -> bytes: ...
|
|
194
|
+
def utf8(value):
|
|
195
|
+
... # implementation goes here
|
|
196
|
+
|
|
197
|
+
The overloads for a function can be retrieved at runtime using the
|
|
198
|
+
get_overloads() function.
|
|
199
|
+
"""
|
|
200
|
+
# classmethod and staticmethod
|
|
201
|
+
f = getattr(func, "__func__", func)
|
|
202
|
+
try:
|
|
203
|
+
_overload_registry[f.__module__][f.__qualname__][f.__code__.co_firstlineno] = func
|
|
204
|
+
except AttributeError:
|
|
205
|
+
# Not a normal function; ignore.
|
|
206
|
+
pass
|
|
207
|
+
return _overload_dummy
|