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
|
@@ -0,0 +1,272 @@
|
|
|
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 json
|
|
8
|
+
from typing import TYPE_CHECKING, Any, Iterable, cast
|
|
9
|
+
|
|
10
|
+
import pydantic
|
|
11
|
+
from typing_extensions import TypeGuard, TypeVar, assert_never
|
|
12
|
+
|
|
13
|
+
from ..._compat import PYDANTIC_V2, model_parse_json
|
|
14
|
+
from ..._exceptions import ArkContentFilterFinishReasonError, ArkLengthFinishReasonError
|
|
15
|
+
from ..._models import construct_type_unchecked
|
|
16
|
+
from ..._types import NOT_GIVEN, NotGiven
|
|
17
|
+
from ..._utils import is_dict, is_given
|
|
18
|
+
from ...types.chat import (
|
|
19
|
+
ChatCompletion,
|
|
20
|
+
ChatCompletionMessage,
|
|
21
|
+
ChatCompletionToolParam,
|
|
22
|
+
ParsedChatCompletion,
|
|
23
|
+
ParsedChatCompletionMessage,
|
|
24
|
+
ParsedChoice,
|
|
25
|
+
ParsedFunction,
|
|
26
|
+
ParsedFunctionToolCall,
|
|
27
|
+
)
|
|
28
|
+
from ...types.chat.chat_completion_message_tool_call_function import (
|
|
29
|
+
ChatCompletionMessageToolCallFunction as Function,
|
|
30
|
+
)
|
|
31
|
+
from ...types.chat.chat_completion_response_format_param import (
|
|
32
|
+
ChatCompletionResponseFormatParam as ResponseFormatParam,
|
|
33
|
+
)
|
|
34
|
+
from ...types.chat.function_object_param import FunctionObjectParam as FunctionDefinition
|
|
35
|
+
from .._pydantic import is_basemodel_type, is_dataclass_like_type, to_strict_json_schema
|
|
36
|
+
from .._tools import PydanticFunctionTool
|
|
37
|
+
|
|
38
|
+
ResponseFormatT = TypeVar(
|
|
39
|
+
"ResponseFormatT",
|
|
40
|
+
# if it isn't given then we don't do any parsing
|
|
41
|
+
default=None,
|
|
42
|
+
)
|
|
43
|
+
_default_response_format: None = None
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def validate_input_tools(
|
|
47
|
+
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
|
|
48
|
+
) -> None:
|
|
49
|
+
if not is_given(tools):
|
|
50
|
+
return
|
|
51
|
+
|
|
52
|
+
for tool in tools:
|
|
53
|
+
if tool["type"] != "function":
|
|
54
|
+
raise ValueError(
|
|
55
|
+
f"Currently only `function` tool types support auto-parsing; Received `{tool['type']}`",
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
strict = tool["function"].get("strict")
|
|
59
|
+
if strict is not True:
|
|
60
|
+
raise ValueError(
|
|
61
|
+
f"`{tool['function']['name']}` is not strict. Only `strict` function tools can be auto-parsed"
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def parse_chat_completion(
|
|
66
|
+
*,
|
|
67
|
+
response_format: type[ResponseFormatT] | ResponseFormatParam | NotGiven,
|
|
68
|
+
input_tools: Iterable[ChatCompletionToolParam] | NotGiven,
|
|
69
|
+
chat_completion: ChatCompletion | ParsedChatCompletion[object],
|
|
70
|
+
) -> ParsedChatCompletion[ResponseFormatT]:
|
|
71
|
+
if is_given(input_tools):
|
|
72
|
+
input_tools = [t for t in input_tools]
|
|
73
|
+
else:
|
|
74
|
+
input_tools = []
|
|
75
|
+
|
|
76
|
+
choices: list[ParsedChoice[ResponseFormatT]] = []
|
|
77
|
+
for choice in chat_completion.choices:
|
|
78
|
+
if choice.finish_reason == "length":
|
|
79
|
+
raise ArkLengthFinishReasonError(completion=chat_completion)
|
|
80
|
+
|
|
81
|
+
if choice.finish_reason == "content_filter":
|
|
82
|
+
raise ArkContentFilterFinishReasonError()
|
|
83
|
+
|
|
84
|
+
message = choice.message
|
|
85
|
+
|
|
86
|
+
tool_calls: list[ParsedFunctionToolCall] = []
|
|
87
|
+
if message.tool_calls:
|
|
88
|
+
for tool_call in message.tool_calls:
|
|
89
|
+
if tool_call.type == "function":
|
|
90
|
+
tool_call_dict = tool_call.to_dict()
|
|
91
|
+
tool_calls.append(
|
|
92
|
+
construct_type_unchecked(
|
|
93
|
+
value={
|
|
94
|
+
**tool_call_dict,
|
|
95
|
+
"function": {
|
|
96
|
+
**cast(Any, tool_call_dict["function"]),
|
|
97
|
+
"parsed_arguments": parse_function_tool_arguments(
|
|
98
|
+
input_tools=input_tools,
|
|
99
|
+
function=tool_call.function,
|
|
100
|
+
),
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
type_=ParsedFunctionToolCall,
|
|
104
|
+
)
|
|
105
|
+
)
|
|
106
|
+
elif TYPE_CHECKING: # type: ignore[unreachable]
|
|
107
|
+
assert_never(tool_call)
|
|
108
|
+
else:
|
|
109
|
+
tool_calls.append(tool_call)
|
|
110
|
+
|
|
111
|
+
choices.append(
|
|
112
|
+
construct_type_unchecked(
|
|
113
|
+
type_=cast(Any, ParsedChoice)[solve_response_format_t(response_format)],
|
|
114
|
+
value={
|
|
115
|
+
**choice.to_dict(),
|
|
116
|
+
"message": {
|
|
117
|
+
**message.to_dict(),
|
|
118
|
+
"parsed": maybe_parse_content(
|
|
119
|
+
response_format=response_format,
|
|
120
|
+
message=message,
|
|
121
|
+
),
|
|
122
|
+
"tool_calls": tool_calls if tool_calls else None,
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
)
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
return cast(
|
|
129
|
+
ParsedChatCompletion[ResponseFormatT],
|
|
130
|
+
construct_type_unchecked(
|
|
131
|
+
type_=cast(Any, ParsedChatCompletion)[solve_response_format_t(response_format)],
|
|
132
|
+
value={
|
|
133
|
+
**chat_completion.to_dict(),
|
|
134
|
+
"choices": choices,
|
|
135
|
+
},
|
|
136
|
+
),
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def get_input_tool_by_name(*, input_tools: list[ChatCompletionToolParam], name: str) -> ChatCompletionToolParam | None:
|
|
141
|
+
return next((t for t in input_tools if t.get("function", {}).get("name") == name), None)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def parse_function_tool_arguments(
|
|
145
|
+
*, input_tools: list[ChatCompletionToolParam], function: Function | ParsedFunction
|
|
146
|
+
) -> object:
|
|
147
|
+
input_tool = get_input_tool_by_name(input_tools=input_tools, name=function.name)
|
|
148
|
+
if not input_tool:
|
|
149
|
+
return None
|
|
150
|
+
|
|
151
|
+
input_fn = cast(object, input_tool.get("function"))
|
|
152
|
+
if isinstance(input_fn, PydanticFunctionTool):
|
|
153
|
+
return model_parse_json(input_fn.model, function.arguments)
|
|
154
|
+
|
|
155
|
+
input_fn = cast(FunctionDefinition, input_fn)
|
|
156
|
+
|
|
157
|
+
if not input_fn.get("strict"):
|
|
158
|
+
return None
|
|
159
|
+
|
|
160
|
+
return json.loads(function.arguments)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def maybe_parse_content(
|
|
164
|
+
*,
|
|
165
|
+
response_format: type[ResponseFormatT] | ResponseFormatParam | NotGiven,
|
|
166
|
+
message: ChatCompletionMessage | ParsedChatCompletionMessage[object],
|
|
167
|
+
) -> ResponseFormatT | None:
|
|
168
|
+
if has_rich_response_format(response_format) and message.content:
|
|
169
|
+
return _parse_content(response_format, message.content)
|
|
170
|
+
|
|
171
|
+
return None
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def solve_response_format_t(
|
|
175
|
+
response_format: type[ResponseFormatT] | ResponseFormatParam | NotGiven,
|
|
176
|
+
) -> type[ResponseFormatT]:
|
|
177
|
+
"""Return the runtime type for the given response format.
|
|
178
|
+
|
|
179
|
+
If no response format is given, or if we won't auto-parse the response format
|
|
180
|
+
then we default to `None`.
|
|
181
|
+
"""
|
|
182
|
+
if has_rich_response_format(response_format):
|
|
183
|
+
return response_format
|
|
184
|
+
|
|
185
|
+
return cast("type[ResponseFormatT]", _default_response_format)
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def has_parseable_input(
|
|
189
|
+
*,
|
|
190
|
+
response_format: type | ResponseFormatParam | NotGiven,
|
|
191
|
+
input_tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
|
|
192
|
+
) -> bool:
|
|
193
|
+
if has_rich_response_format(response_format):
|
|
194
|
+
return True
|
|
195
|
+
|
|
196
|
+
for input_tool in input_tools or []:
|
|
197
|
+
if is_parseable_tool(input_tool):
|
|
198
|
+
return True
|
|
199
|
+
|
|
200
|
+
return False
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def has_rich_response_format(
|
|
204
|
+
response_format: type[ResponseFormatT] | ResponseFormatParam | NotGiven,
|
|
205
|
+
) -> TypeGuard[type[ResponseFormatT]]:
|
|
206
|
+
if not is_given(response_format):
|
|
207
|
+
return False
|
|
208
|
+
|
|
209
|
+
if is_response_format_param(response_format):
|
|
210
|
+
return False
|
|
211
|
+
|
|
212
|
+
return True
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def is_response_format_param(response_format: object) -> TypeGuard[ResponseFormatParam]:
|
|
216
|
+
return is_dict(response_format)
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def is_parseable_tool(input_tool: ChatCompletionToolParam) -> bool:
|
|
220
|
+
input_fn = cast(object, input_tool.get("function"))
|
|
221
|
+
if isinstance(input_fn, PydanticFunctionTool):
|
|
222
|
+
return True
|
|
223
|
+
|
|
224
|
+
return cast(FunctionDefinition, input_fn).get("strict") or False
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def _parse_content(response_format: type[ResponseFormatT], content: str) -> ResponseFormatT:
|
|
228
|
+
if is_basemodel_type(response_format):
|
|
229
|
+
return cast(ResponseFormatT, model_parse_json(response_format, content))
|
|
230
|
+
|
|
231
|
+
if is_dataclass_like_type(response_format):
|
|
232
|
+
if not PYDANTIC_V2:
|
|
233
|
+
raise TypeError(f"Non BaseModel types are only supported with Pydantic v2 - {response_format}")
|
|
234
|
+
|
|
235
|
+
return pydantic.TypeAdapter(response_format).validate_json(content)
|
|
236
|
+
|
|
237
|
+
raise TypeError(f"Unable to automatically parse response format type {response_format}")
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def type_to_response_format_param(
|
|
241
|
+
response_format: type | ResponseFormatParam | NotGiven,
|
|
242
|
+
) -> ResponseFormatParam | NotGiven:
|
|
243
|
+
if not is_given(response_format):
|
|
244
|
+
return NOT_GIVEN
|
|
245
|
+
|
|
246
|
+
if is_response_format_param(response_format):
|
|
247
|
+
return response_format
|
|
248
|
+
|
|
249
|
+
# type checkers don't narrow the negation of a `TypeGuard` as it isn't
|
|
250
|
+
# a safe default behaviour but we know that at this point the `response_format`
|
|
251
|
+
# can only be a `type`
|
|
252
|
+
response_format = cast(type, response_format)
|
|
253
|
+
|
|
254
|
+
json_schema_type: type[pydantic.BaseModel] | pydantic.TypeAdapter[Any] | None = None
|
|
255
|
+
|
|
256
|
+
if is_basemodel_type(response_format):
|
|
257
|
+
name = response_format.__name__
|
|
258
|
+
json_schema_type = response_format
|
|
259
|
+
elif is_dataclass_like_type(response_format):
|
|
260
|
+
name = response_format.__name__
|
|
261
|
+
json_schema_type = pydantic.TypeAdapter(response_format)
|
|
262
|
+
else:
|
|
263
|
+
raise TypeError(f"Unsupported response_format type - {response_format}")
|
|
264
|
+
|
|
265
|
+
return {
|
|
266
|
+
"type": "json_schema",
|
|
267
|
+
"json_schema": {
|
|
268
|
+
"schema": to_strict_json_schema(json_schema_type),
|
|
269
|
+
"name": name,
|
|
270
|
+
"strict": True,
|
|
271
|
+
},
|
|
272
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
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 json
|
|
8
|
+
from typing import TYPE_CHECKING, Any, Iterable, List, cast
|
|
9
|
+
|
|
10
|
+
import pydantic
|
|
11
|
+
from typing_extensions import TypeVar, assert_never
|
|
12
|
+
|
|
13
|
+
from ..._compat import PYDANTIC_V2, model_parse_json
|
|
14
|
+
from ..._models import construct_type_unchecked
|
|
15
|
+
from ..._types import NotGiven
|
|
16
|
+
from ..._utils import is_given
|
|
17
|
+
from ...types.chat.chat_completion_response_format_param import (
|
|
18
|
+
ChatCompletionResponseFormatParam as ResponseFormat,
|
|
19
|
+
)
|
|
20
|
+
from ...types.responses import (
|
|
21
|
+
FunctionToolParam,
|
|
22
|
+
ParsedContent,
|
|
23
|
+
ParsedResponse,
|
|
24
|
+
ParsedResponseFunctionToolCall,
|
|
25
|
+
ParsedResponseOutputItem,
|
|
26
|
+
ParsedResponseOutputMessage,
|
|
27
|
+
ParsedResponseOutputText,
|
|
28
|
+
Response,
|
|
29
|
+
ResponseFormatTextConfigParam,
|
|
30
|
+
ResponseFunctionToolCall,
|
|
31
|
+
ToolParam,
|
|
32
|
+
)
|
|
33
|
+
from .._pydantic import is_basemodel_type, is_dataclass_like_type
|
|
34
|
+
from .._tools import ResponsesPydanticFunctionTool
|
|
35
|
+
from ._completions import solve_response_format_t, type_to_response_format_param
|
|
36
|
+
|
|
37
|
+
TextFormatT = TypeVar(
|
|
38
|
+
"TextFormatT",
|
|
39
|
+
# if it isn't given then we don't do any parsing
|
|
40
|
+
default=None,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def type_to_text_format_param(type_: type) -> ResponseFormatTextConfigParam:
|
|
45
|
+
response_format_dict = type_to_response_format_param(type_)
|
|
46
|
+
assert is_given(response_format_dict)
|
|
47
|
+
response_format_dict = cast(ResponseFormat, response_format_dict) # pyright: ignore[reportUnnecessaryCast]
|
|
48
|
+
assert response_format_dict["type"] == "json_schema"
|
|
49
|
+
assert "schema" in response_format_dict["json_schema"]
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
"type": "json_schema",
|
|
53
|
+
"strict": True,
|
|
54
|
+
"name": response_format_dict["json_schema"]["name"],
|
|
55
|
+
"schema": response_format_dict["json_schema"]["schema"],
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def parse_response(
|
|
60
|
+
*,
|
|
61
|
+
text_format: type[TextFormatT] | NotGiven,
|
|
62
|
+
input_tools: Iterable[ToolParam] | NotGiven | None,
|
|
63
|
+
response: Response | ParsedResponse[object],
|
|
64
|
+
) -> ParsedResponse[TextFormatT]:
|
|
65
|
+
solved_t = solve_response_format_t(text_format)
|
|
66
|
+
output_list: List[ParsedResponseOutputItem[TextFormatT]] = []
|
|
67
|
+
|
|
68
|
+
for output in response.output:
|
|
69
|
+
if output.type == "message":
|
|
70
|
+
content_list: List[ParsedContent[TextFormatT]] = []
|
|
71
|
+
for item in output.content:
|
|
72
|
+
if item.type != "output_text":
|
|
73
|
+
content_list.append(item)
|
|
74
|
+
continue
|
|
75
|
+
|
|
76
|
+
content_list.append(
|
|
77
|
+
construct_type_unchecked(
|
|
78
|
+
type_=cast(Any, ParsedResponseOutputText)[solved_t],
|
|
79
|
+
value={
|
|
80
|
+
**item.to_dict(),
|
|
81
|
+
"parsed": parse_text(item.text, text_format=text_format),
|
|
82
|
+
},
|
|
83
|
+
)
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
output_list.append(
|
|
87
|
+
construct_type_unchecked(
|
|
88
|
+
type_=cast(Any, ParsedResponseOutputMessage)[solved_t],
|
|
89
|
+
value={
|
|
90
|
+
**output.to_dict(),
|
|
91
|
+
"content": content_list,
|
|
92
|
+
},
|
|
93
|
+
)
|
|
94
|
+
)
|
|
95
|
+
elif output.type == "function_call":
|
|
96
|
+
output_list.append(
|
|
97
|
+
construct_type_unchecked(
|
|
98
|
+
type_=ParsedResponseFunctionToolCall,
|
|
99
|
+
value={
|
|
100
|
+
**output.to_dict(),
|
|
101
|
+
"parsed_arguments": parse_function_tool_arguments(
|
|
102
|
+
input_tools=input_tools, function_call=output
|
|
103
|
+
),
|
|
104
|
+
},
|
|
105
|
+
)
|
|
106
|
+
)
|
|
107
|
+
elif (
|
|
108
|
+
output.type == "computer_call"
|
|
109
|
+
or output.type == "file_search_call"
|
|
110
|
+
or output.type == "web_search_call"
|
|
111
|
+
or output.type == "reasoning"
|
|
112
|
+
):
|
|
113
|
+
output_list.append(output)
|
|
114
|
+
elif TYPE_CHECKING: # type: ignore
|
|
115
|
+
assert_never(output)
|
|
116
|
+
else:
|
|
117
|
+
output_list.append(output)
|
|
118
|
+
|
|
119
|
+
return cast(
|
|
120
|
+
ParsedResponse[TextFormatT],
|
|
121
|
+
construct_type_unchecked(
|
|
122
|
+
type_=cast(Any, ParsedResponse)[solved_t],
|
|
123
|
+
value={
|
|
124
|
+
**response.to_dict(),
|
|
125
|
+
"output": output_list,
|
|
126
|
+
},
|
|
127
|
+
),
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def parse_text(text: str, text_format: type[TextFormatT] | NotGiven) -> TextFormatT | None:
|
|
132
|
+
if not is_given(text_format):
|
|
133
|
+
return None
|
|
134
|
+
|
|
135
|
+
if is_basemodel_type(text_format):
|
|
136
|
+
return cast(TextFormatT, model_parse_json(text_format, text))
|
|
137
|
+
|
|
138
|
+
if is_dataclass_like_type(text_format):
|
|
139
|
+
if not PYDANTIC_V2:
|
|
140
|
+
raise TypeError(f"Non BaseModel types are only supported with Pydantic v2 - {text_format}")
|
|
141
|
+
|
|
142
|
+
return pydantic.TypeAdapter(text_format).validate_json(text)
|
|
143
|
+
|
|
144
|
+
raise TypeError(f"Unable to automatically parse response format type {text_format}")
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def get_input_tool_by_name(*, input_tools: Iterable[ToolParam], name: str) -> FunctionToolParam | None:
|
|
148
|
+
for tool in input_tools:
|
|
149
|
+
if tool["type"] == "function" and tool.get("name") == name:
|
|
150
|
+
return tool
|
|
151
|
+
|
|
152
|
+
return None
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def parse_function_tool_arguments(
|
|
156
|
+
*,
|
|
157
|
+
input_tools: Iterable[ToolParam] | NotGiven | None,
|
|
158
|
+
function_call: ParsedResponseFunctionToolCall | ResponseFunctionToolCall,
|
|
159
|
+
) -> object:
|
|
160
|
+
if input_tools is None or not is_given(input_tools):
|
|
161
|
+
return None
|
|
162
|
+
|
|
163
|
+
input_tool = get_input_tool_by_name(input_tools=input_tools, name=function_call.name)
|
|
164
|
+
if not input_tool:
|
|
165
|
+
return None
|
|
166
|
+
|
|
167
|
+
tool = cast(object, input_tool)
|
|
168
|
+
if isinstance(tool, ResponsesPydanticFunctionTool):
|
|
169
|
+
return model_parse_json(tool.model, function_call.arguments)
|
|
170
|
+
|
|
171
|
+
if not input_tool.get("strict"):
|
|
172
|
+
return None
|
|
173
|
+
|
|
174
|
+
return json.loads(function_call.arguments)
|
|
@@ -0,0 +1,166 @@
|
|
|
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
|
+
from typing import Any, TypeVar
|
|
9
|
+
|
|
10
|
+
import pydantic
|
|
11
|
+
from typing_extensions import TypeGuard
|
|
12
|
+
|
|
13
|
+
from .._compat import PYDANTIC_V2, model_json_schema
|
|
14
|
+
from .._types import NOT_GIVEN
|
|
15
|
+
from .._utils import is_dict as _is_dict
|
|
16
|
+
from .._utils import is_list
|
|
17
|
+
|
|
18
|
+
_T = TypeVar("_T")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def to_strict_json_schema(
|
|
22
|
+
model: type[pydantic.BaseModel] | pydantic.TypeAdapter[Any],
|
|
23
|
+
) -> dict[str, Any]:
|
|
24
|
+
if inspect.isclass(model) and is_basemodel_type(model):
|
|
25
|
+
schema = model_json_schema(model)
|
|
26
|
+
elif PYDANTIC_V2 and isinstance(model, pydantic.TypeAdapter):
|
|
27
|
+
schema = model.json_schema()
|
|
28
|
+
else:
|
|
29
|
+
raise TypeError(f"Non BaseModel types are only supported with Pydantic v2 - {model}")
|
|
30
|
+
|
|
31
|
+
return _ensure_strict_json_schema(schema, path=(), root=schema)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _ensure_strict_json_schema(
|
|
35
|
+
json_schema: object,
|
|
36
|
+
*,
|
|
37
|
+
path: tuple[str, ...],
|
|
38
|
+
root: dict[str, object],
|
|
39
|
+
) -> dict[str, Any]:
|
|
40
|
+
"""Mutates the given JSON schema to ensure it conforms to the `strict` standard
|
|
41
|
+
that the API expects.
|
|
42
|
+
"""
|
|
43
|
+
if not is_dict(json_schema):
|
|
44
|
+
raise TypeError(f"Expected {json_schema} to be a dictionary; path={path}")
|
|
45
|
+
|
|
46
|
+
defs = json_schema.get("$defs")
|
|
47
|
+
if is_dict(defs):
|
|
48
|
+
for def_name, def_schema in defs.items():
|
|
49
|
+
_ensure_strict_json_schema(def_schema, path=(*path, "$defs", def_name), root=root)
|
|
50
|
+
|
|
51
|
+
definitions = json_schema.get("definitions")
|
|
52
|
+
if is_dict(definitions):
|
|
53
|
+
for definition_name, definition_schema in definitions.items():
|
|
54
|
+
_ensure_strict_json_schema(
|
|
55
|
+
definition_schema,
|
|
56
|
+
path=(*path, "definitions", definition_name),
|
|
57
|
+
root=root,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
typ = json_schema.get("type")
|
|
61
|
+
if typ == "object" and "additionalProperties" not in json_schema:
|
|
62
|
+
json_schema["additionalProperties"] = False
|
|
63
|
+
|
|
64
|
+
# object types
|
|
65
|
+
# { 'type': 'object', 'properties': { 'a': {...} } }
|
|
66
|
+
properties = json_schema.get("properties")
|
|
67
|
+
if is_dict(properties):
|
|
68
|
+
json_schema["required"] = [prop for prop in properties.keys()]
|
|
69
|
+
json_schema["properties"] = {
|
|
70
|
+
key: _ensure_strict_json_schema(prop_schema, path=(*path, "properties", key), root=root)
|
|
71
|
+
for key, prop_schema in properties.items()
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
# arrays
|
|
75
|
+
# { 'type': 'array', 'items': {...} }
|
|
76
|
+
items = json_schema.get("items")
|
|
77
|
+
if is_dict(items):
|
|
78
|
+
json_schema["items"] = _ensure_strict_json_schema(items, path=(*path, "items"), root=root)
|
|
79
|
+
|
|
80
|
+
# unions
|
|
81
|
+
any_of = json_schema.get("anyOf")
|
|
82
|
+
if is_list(any_of):
|
|
83
|
+
json_schema["anyOf"] = [
|
|
84
|
+
_ensure_strict_json_schema(variant, path=(*path, "anyOf", str(i)), root=root)
|
|
85
|
+
for i, variant in enumerate(any_of)
|
|
86
|
+
]
|
|
87
|
+
|
|
88
|
+
# intersections
|
|
89
|
+
all_of = json_schema.get("allOf")
|
|
90
|
+
if is_list(all_of):
|
|
91
|
+
if len(all_of) == 1:
|
|
92
|
+
json_schema.update(_ensure_strict_json_schema(all_of[0], path=(*path, "allOf", "0"), root=root))
|
|
93
|
+
json_schema.pop("allOf")
|
|
94
|
+
else:
|
|
95
|
+
json_schema["allOf"] = [
|
|
96
|
+
_ensure_strict_json_schema(entry, path=(*path, "allOf", str(i)), root=root)
|
|
97
|
+
for i, entry in enumerate(all_of)
|
|
98
|
+
]
|
|
99
|
+
|
|
100
|
+
# strip `None` defaults as there's no meaningful distinction here
|
|
101
|
+
# the schema will still be `nullable` and the model will default
|
|
102
|
+
# to using `None` anyway
|
|
103
|
+
if json_schema.get("default", NOT_GIVEN) is None:
|
|
104
|
+
json_schema.pop("default")
|
|
105
|
+
|
|
106
|
+
# we can't use `$ref`s if there are also other properties defined, e.g.
|
|
107
|
+
# `{"$ref": "...", "description": "my description"}`
|
|
108
|
+
#
|
|
109
|
+
# so we unravel the ref
|
|
110
|
+
# `{"type": "string", "description": "my description"}`
|
|
111
|
+
ref = json_schema.get("$ref")
|
|
112
|
+
if ref and has_more_than_n_keys(json_schema, 1):
|
|
113
|
+
assert isinstance(ref, str), f"Received non-string $ref - {ref}"
|
|
114
|
+
|
|
115
|
+
resolved = resolve_ref(root=root, ref=ref)
|
|
116
|
+
if not is_dict(resolved):
|
|
117
|
+
raise ValueError(f"Expected `$ref: {ref}` to resolved to a dictionary but got {resolved}")
|
|
118
|
+
|
|
119
|
+
# properties from the json schema take priority over the ones on the `$ref`
|
|
120
|
+
json_schema.update({**resolved, **json_schema})
|
|
121
|
+
json_schema.pop("$ref")
|
|
122
|
+
# Since the schema expanded from `$ref` might not have `additionalProperties: false` applied,
|
|
123
|
+
# we call `_ensure_strict_json_schema` again to fix the inlined schema and ensure it's valid.
|
|
124
|
+
return _ensure_strict_json_schema(json_schema, path=path, root=root)
|
|
125
|
+
|
|
126
|
+
return json_schema
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def resolve_ref(*, root: dict[str, object], ref: str) -> object:
|
|
130
|
+
if not ref.startswith("#/"):
|
|
131
|
+
raise ValueError(f"Unexpected $ref format {ref!r}; Does not start with #/")
|
|
132
|
+
|
|
133
|
+
path = ref[2:].split("/")
|
|
134
|
+
resolved = root
|
|
135
|
+
for key in path:
|
|
136
|
+
value = resolved[key]
|
|
137
|
+
assert is_dict(value), f"encountered non-dictionary entry while resolving {ref} - {resolved}"
|
|
138
|
+
resolved = value
|
|
139
|
+
|
|
140
|
+
return resolved
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def is_basemodel_type(typ: type) -> TypeGuard[type[pydantic.BaseModel]]:
|
|
144
|
+
if not inspect.isclass(typ):
|
|
145
|
+
return False
|
|
146
|
+
return issubclass(typ, pydantic.BaseModel)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def is_dataclass_like_type(typ: type) -> bool:
|
|
150
|
+
"""Returns True if the given type likely used `@pydantic.dataclass`"""
|
|
151
|
+
return hasattr(typ, "__pydantic_config__")
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def is_dict(obj: object) -> TypeGuard[dict[str, object]]:
|
|
155
|
+
# just pretend that we know there are only `str` keys
|
|
156
|
+
# as that check is not worth the performance cost
|
|
157
|
+
return _is_dict(obj)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def has_more_than_n_keys(obj: dict[str, object], n: int) -> bool:
|
|
161
|
+
i = 0
|
|
162
|
+
for _ in obj.keys():
|
|
163
|
+
i += 1
|
|
164
|
+
if i > n:
|
|
165
|
+
return True
|
|
166
|
+
return False
|
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
from typing import Any, Dict, cast
|
|
8
|
+
|
|
9
|
+
import pydantic
|
|
10
|
+
|
|
11
|
+
from ..types.chat import ChatCompletionToolParam
|
|
12
|
+
from ..types.chat.function_object_param import FunctionObjectParam as FunctionDefinition
|
|
13
|
+
from ..types.responses.function_tool_param import (
|
|
14
|
+
FunctionToolParam as ResponsesFunctionToolParam,
|
|
15
|
+
)
|
|
16
|
+
from ._pydantic import to_strict_json_schema
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class PydanticFunctionTool(Dict[str, Any]):
|
|
20
|
+
"""Dictionary wrapper so we can pass the given base model
|
|
21
|
+
throughout the entire request stack without having to special
|
|
22
|
+
case it.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
model: type[pydantic.BaseModel]
|
|
26
|
+
|
|
27
|
+
def __init__(self, defn: FunctionDefinition, model: type[pydantic.BaseModel]) -> None:
|
|
28
|
+
super().__init__(defn)
|
|
29
|
+
self.model = model
|
|
30
|
+
|
|
31
|
+
def cast(self) -> FunctionDefinition:
|
|
32
|
+
return cast(FunctionDefinition, self)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class ResponsesPydanticFunctionTool(Dict[str, Any]):
|
|
36
|
+
"""Responses-API counterpart to :class:`PydanticFunctionTool`.
|
|
37
|
+
|
|
38
|
+
The Responses API encodes function tools with a flatter shape than
|
|
39
|
+
Chat Completions — name, parameters and strict live directly on the
|
|
40
|
+
tool dict instead of nested under ``function``. We wrap that dict and
|
|
41
|
+
keep a reference to the pydantic model so the response parser can
|
|
42
|
+
deserialise ``arguments`` back into the original type.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
model: type[pydantic.BaseModel]
|
|
46
|
+
|
|
47
|
+
def __init__(
|
|
48
|
+
self,
|
|
49
|
+
tool: ResponsesFunctionToolParam,
|
|
50
|
+
model: type[pydantic.BaseModel],
|
|
51
|
+
) -> None:
|
|
52
|
+
super().__init__(tool)
|
|
53
|
+
self.model = model
|
|
54
|
+
|
|
55
|
+
def cast(self) -> ResponsesFunctionToolParam:
|
|
56
|
+
return cast(ResponsesFunctionToolParam, self)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def pydantic_function_tool(
|
|
60
|
+
model: type[pydantic.BaseModel],
|
|
61
|
+
*,
|
|
62
|
+
name: str | None = None, # inferred from class name by default
|
|
63
|
+
description: str | None = None, # inferred from class docstring by default
|
|
64
|
+
) -> ChatCompletionToolParam:
|
|
65
|
+
if description is None:
|
|
66
|
+
# note: we intentionally don't use `.getdoc()` to avoid
|
|
67
|
+
# including pydantic's docstrings
|
|
68
|
+
description = model.__doc__
|
|
69
|
+
|
|
70
|
+
function = PydanticFunctionTool(
|
|
71
|
+
{
|
|
72
|
+
"name": name or model.__name__,
|
|
73
|
+
"strict": True,
|
|
74
|
+
"parameters": to_strict_json_schema(model),
|
|
75
|
+
},
|
|
76
|
+
model,
|
|
77
|
+
).cast()
|
|
78
|
+
|
|
79
|
+
if description is not None:
|
|
80
|
+
function["description"] = description
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
"type": "function",
|
|
84
|
+
"function": function,
|
|
85
|
+
}
|