byteplussdk-arkruntime 3.0.64__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.
- byteplussdk_arkruntime-3.0.64.dist-info/METADATA +36 -0
- byteplussdk_arkruntime-3.0.64.dist-info/RECORD +240 -0
- byteplussdk_arkruntime-3.0.64.dist-info/WHEEL +5 -0
- byteplussdk_arkruntime-3.0.64.dist-info/licenses/LICENSE.txt +203 -0
- byteplussdk_arkruntime-3.0.64.dist-info/top_level.txt +1 -0
- byteplussdkarkruntime/__init__.py +7 -0
- byteplussdkarkruntime/_base_client.py +1439 -0
- byteplussdkarkruntime/_client.py +570 -0
- byteplussdkarkruntime/_compat.py +245 -0
- byteplussdkarkruntime/_constants.py +43 -0
- byteplussdkarkruntime/_exceptions.py +202 -0
- byteplussdkarkruntime/_files.py +149 -0
- byteplussdkarkruntime/_legacy_response.py +451 -0
- byteplussdkarkruntime/_models.py +734 -0
- byteplussdkarkruntime/_qs.py +168 -0
- byteplussdkarkruntime/_request_options.py +117 -0
- byteplussdkarkruntime/_resource.py +47 -0
- byteplussdkarkruntime/_response.py +615 -0
- byteplussdkarkruntime/_streaming.py +470 -0
- byteplussdkarkruntime/_types.py +210 -0
- byteplussdkarkruntime/_utils/__init__.py +58 -0
- byteplussdkarkruntime/_utils/_key_agreement.py +207 -0
- byteplussdkarkruntime/_utils/_logs.py +24 -0
- byteplussdkarkruntime/_utils/_model_breaker.py +83 -0
- byteplussdkarkruntime/_utils/_streams.py +12 -0
- byteplussdkarkruntime/_utils/_transform.py +489 -0
- byteplussdkarkruntime/_utils/_typing.py +171 -0
- byteplussdkarkruntime/_utils/_utils.py +497 -0
- byteplussdkarkruntime/common/__init__.py +14 -0
- byteplussdkarkruntime/common/_parsing/__init__.py +22 -0
- byteplussdkarkruntime/common/_parsing/_completions.py +290 -0
- byteplussdkarkruntime/common/_parsing/_responses.py +189 -0
- byteplussdkarkruntime/common/_pydantic.py +192 -0
- byteplussdkarkruntime/common/_tools.py +67 -0
- byteplussdkarkruntime/common/streaming/__init__.py +12 -0
- byteplussdkarkruntime/common/streaming/_deltas.py +86 -0
- byteplussdkarkruntime/common/streaming/chat/__init__.py +33 -0
- byteplussdkarkruntime/common/streaming/chat/_completions.py +772 -0
- byteplussdkarkruntime/common/streaming/chat/_events.py +103 -0
- byteplussdkarkruntime/common/streaming/chat/_types.py +36 -0
- byteplussdkarkruntime/pagination.py +134 -0
- byteplussdkarkruntime/resources/__init__.py +48 -0
- byteplussdkarkruntime/resources/batch/__init__.py +3 -0
- byteplussdkarkruntime/resources/batch/_utils.py +155 -0
- byteplussdkarkruntime/resources/batch/batch.py +37 -0
- byteplussdkarkruntime/resources/batch/chat/__init__.py +3 -0
- byteplussdkarkruntime/resources/batch/chat/chat.py +19 -0
- byteplussdkarkruntime/resources/batch/chat/completions.py +329 -0
- byteplussdkarkruntime/resources/batch/embeddings.py +105 -0
- byteplussdkarkruntime/resources/batch/multimodal_embeddings.py +111 -0
- byteplussdkarkruntime/resources/batch_chat/__init__.py +3 -0
- byteplussdkarkruntime/resources/batch_chat/chat.py +21 -0
- byteplussdkarkruntime/resources/batch_chat/completions.py +328 -0
- byteplussdkarkruntime/resources/beta/__init__.py +12 -0
- byteplussdkarkruntime/resources/beta/beta.py +81 -0
- byteplussdkarkruntime/resources/beta/chat/__init__.py +21 -0
- byteplussdkarkruntime/resources/beta/chat/chat.py +31 -0
- byteplussdkarkruntime/resources/beta/chat/completions.py +454 -0
- byteplussdkarkruntime/resources/chat/__init__.py +3 -0
- byteplussdkarkruntime/resources/chat/chat.py +21 -0
- byteplussdkarkruntime/resources/chat/completions.py +258 -0
- byteplussdkarkruntime/resources/content_generation/__init__.py +6 -0
- byteplussdkarkruntime/resources/content_generation/content_generation.py +17 -0
- byteplussdkarkruntime/resources/content_generation/tasks.py +348 -0
- byteplussdkarkruntime/resources/context/__init__.py +3 -0
- byteplussdkarkruntime/resources/context/completions.py +221 -0
- byteplussdkarkruntime/resources/context/context.py +98 -0
- byteplussdkarkruntime/resources/embeddings.py +110 -0
- byteplussdkarkruntime/resources/encryption.py +215 -0
- byteplussdkarkruntime/resources/files.py +592 -0
- byteplussdkarkruntime/resources/images/__init__.py +6 -0
- byteplussdkarkruntime/resources/images/images.py +335 -0
- byteplussdkarkruntime/resources/multimodal_embeddings.py +113 -0
- byteplussdkarkruntime/resources/responses/__init__.py +16 -0
- byteplussdkarkruntime/resources/responses/input_items.py +248 -0
- byteplussdkarkruntime/resources/responses/responses.py +417 -0
- byteplussdkarkruntime/types/__init__.py +28 -0
- byteplussdkarkruntime/types/chat/__init__.py +78 -0
- byteplussdkarkruntime/types/chat/chat_completion.py +93 -0
- byteplussdkarkruntime/types/chat/chat_completion_assistant_message_param.py +61 -0
- byteplussdkarkruntime/types/chat/chat_completion_audio.py +22 -0
- byteplussdkarkruntime/types/chat/chat_completion_chunk.py +165 -0
- byteplussdkarkruntime/types/chat/chat_completion_content_part_image_param.py +20 -0
- byteplussdkarkruntime/types/chat/chat_completion_content_part_param.py +30 -0
- byteplussdkarkruntime/types/chat/chat_completion_content_part_text_param.py +13 -0
- byteplussdkarkruntime/types/chat/chat_completion_content_part_video_param.py +32 -0
- byteplussdkarkruntime/types/chat/chat_completion_function_call_option_param.py +10 -0
- byteplussdkarkruntime/types/chat/chat_completion_function_message_param.py +17 -0
- byteplussdkarkruntime/types/chat/chat_completion_message.py +56 -0
- byteplussdkarkruntime/types/chat/chat_completion_message_param.py +19 -0
- byteplussdkarkruntime/types/chat/chat_completion_message_tool_call.py +29 -0
- byteplussdkarkruntime/types/chat/chat_completion_message_tool_call_param.py +29 -0
- byteplussdkarkruntime/types/chat/chat_completion_named_tool_choice_param.py +17 -0
- byteplussdkarkruntime/types/chat/chat_completion_role.py +5 -0
- byteplussdkarkruntime/types/chat/chat_completion_stream_options_param.py +19 -0
- byteplussdkarkruntime/types/chat/chat_completion_system_message_param.py +34 -0
- byteplussdkarkruntime/types/chat/chat_completion_token_logprob.py +55 -0
- byteplussdkarkruntime/types/chat/chat_completion_tool_choice_option_param.py +12 -0
- byteplussdkarkruntime/types/chat/chat_completion_tool_message_param.py +37 -0
- byteplussdkarkruntime/types/chat/chat_completion_tool_param.py +14 -0
- byteplussdkarkruntime/types/chat/chat_completion_user_message_param.py +34 -0
- byteplussdkarkruntime/types/chat/completion_create_params.py +258 -0
- byteplussdkarkruntime/types/chat/parsed_chat_completion.py +52 -0
- byteplussdkarkruntime/types/chat/parsed_function_tool_call.py +34 -0
- byteplussdkarkruntime/types/completion_usage.py +33 -0
- byteplussdkarkruntime/types/content_generation/__init__.py +0 -0
- byteplussdkarkruntime/types/content_generation/content_generation_task.py +106 -0
- byteplussdkarkruntime/types/content_generation/content_generation_task_id.py +11 -0
- byteplussdkarkruntime/types/content_generation/create_task_content_param.py +72 -0
- byteplussdkarkruntime/types/content_generation/list_content_generation_tasks_response.py +24 -0
- byteplussdkarkruntime/types/context/__init__.py +8 -0
- byteplussdkarkruntime/types/context/context_chat_completion.py +33 -0
- byteplussdkarkruntime/types/context/context_chat_completion_chunk.py +41 -0
- byteplussdkarkruntime/types/context/context_create_params.py +37 -0
- byteplussdkarkruntime/types/context/create_context_response.py +25 -0
- byteplussdkarkruntime/types/context/truncation_strategy.py +13 -0
- byteplussdkarkruntime/types/create_embedding_response.py +36 -0
- byteplussdkarkruntime/types/embedding.py +21 -0
- byteplussdkarkruntime/types/file_create_params.py +49 -0
- byteplussdkarkruntime/types/file_deleted.py +24 -0
- byteplussdkarkruntime/types/file_list_params.py +43 -0
- byteplussdkarkruntime/types/file_object.py +69 -0
- byteplussdkarkruntime/types/file_purpose.py +16 -0
- byteplussdkarkruntime/types/images/__init__.py +3 -0
- byteplussdkarkruntime/types/images/image_gen_completed_event.py +59 -0
- byteplussdkarkruntime/types/images/image_gen_generating_event.py +53 -0
- byteplussdkarkruntime/types/images/image_gen_stream_event.py +24 -0
- byteplussdkarkruntime/types/images/images.py +99 -0
- byteplussdkarkruntime/types/multimodal_embedding/__init__.py +15 -0
- byteplussdkarkruntime/types/multimodal_embedding/embedding_content_part_image_param.py +17 -0
- byteplussdkarkruntime/types/multimodal_embedding/embedding_content_part_text_param.py +13 -0
- byteplussdkarkruntime/types/multimodal_embedding/embedding_data.py +15 -0
- byteplussdkarkruntime/types/multimodal_embedding/embedding_input.py +12 -0
- byteplussdkarkruntime/types/multimodal_embedding/embedding_response.py +29 -0
- byteplussdkarkruntime/types/multimodal_embedding/embedding_usage.py +23 -0
- byteplussdkarkruntime/types/responses/__init__.py +133 -0
- byteplussdkarkruntime/types/responses/easy_input_message.py +36 -0
- byteplussdkarkruntime/types/responses/easy_input_message_param.py +37 -0
- byteplussdkarkruntime/types/responses/function_tool.py +35 -0
- byteplussdkarkruntime/types/responses/function_tool_param.py +35 -0
- byteplussdkarkruntime/types/responses/input_item_list_params.py +47 -0
- byteplussdkarkruntime/types/responses/mcp_input_item_param.py +109 -0
- byteplussdkarkruntime/types/responses/mcp_tool.py +80 -0
- byteplussdkarkruntime/types/responses/mcp_tool_param.py +78 -0
- byteplussdkarkruntime/types/responses/response.py +152 -0
- byteplussdkarkruntime/types/responses/response_annotation_added_event.py +36 -0
- byteplussdkarkruntime/types/responses/response_caching.py +25 -0
- byteplussdkarkruntime/types/responses/response_caching_param.py +22 -0
- byteplussdkarkruntime/types/responses/response_completed_event.py +26 -0
- byteplussdkarkruntime/types/responses/response_content_part_added_event.py +39 -0
- byteplussdkarkruntime/types/responses/response_content_part_done_event.py +39 -0
- byteplussdkarkruntime/types/responses/response_create_params.py +26 -0
- byteplussdkarkruntime/types/responses/response_created_event.py +26 -0
- byteplussdkarkruntime/types/responses/response_error.py +25 -0
- byteplussdkarkruntime/types/responses/response_error_event.py +32 -0
- byteplussdkarkruntime/types/responses/response_failed_event.py +26 -0
- byteplussdkarkruntime/types/responses/response_format_text_config.py +25 -0
- byteplussdkarkruntime/types/responses/response_format_text_config_param.py +25 -0
- byteplussdkarkruntime/types/responses/response_function_call_arguments_delta_event.py +33 -0
- byteplussdkarkruntime/types/responses/response_function_call_arguments_done_event.py +30 -0
- byteplussdkarkruntime/types/responses/response_function_tool_call.py +42 -0
- byteplussdkarkruntime/types/responses/response_function_tool_call_item.py +20 -0
- byteplussdkarkruntime/types/responses/response_function_tool_call_output_item.py +39 -0
- byteplussdkarkruntime/types/responses/response_function_tool_call_param.py +31 -0
- byteplussdkarkruntime/types/responses/response_in_progress_event.py +26 -0
- byteplussdkarkruntime/types/responses/response_includable.py +19 -0
- byteplussdkarkruntime/types/responses/response_incomplete_details.py +30 -0
- byteplussdkarkruntime/types/responses/response_incomplete_event.py +26 -0
- byteplussdkarkruntime/types/responses/response_input_content.py +24 -0
- byteplussdkarkruntime/types/responses/response_input_content_param.py +23 -0
- byteplussdkarkruntime/types/responses/response_input_image.py +38 -0
- byteplussdkarkruntime/types/responses/response_input_image_param.py +42 -0
- byteplussdkarkruntime/types/responses/response_input_image_pixel_limit_param.py +29 -0
- byteplussdkarkruntime/types/responses/response_input_message_content_list.py +20 -0
- byteplussdkarkruntime/types/responses/response_input_message_content_list_param.py +26 -0
- byteplussdkarkruntime/types/responses/response_input_message_item.py +43 -0
- byteplussdkarkruntime/types/responses/response_input_param.py +51 -0
- byteplussdkarkruntime/types/responses/response_input_text.py +25 -0
- byteplussdkarkruntime/types/responses/response_input_text_param.py +25 -0
- byteplussdkarkruntime/types/responses/response_input_video_param.py +34 -0
- byteplussdkarkruntime/types/responses/response_item.py +40 -0
- byteplussdkarkruntime/types/responses/response_item_list.py +36 -0
- byteplussdkarkruntime/types/responses/response_mcp_call_arguments_delta_event.py +37 -0
- byteplussdkarkruntime/types/responses/response_mcp_call_arguments_done_event.py +34 -0
- byteplussdkarkruntime/types/responses/response_mcp_call_completed_event.py +31 -0
- byteplussdkarkruntime/types/responses/response_mcp_call_failed_event.py +31 -0
- byteplussdkarkruntime/types/responses/response_mcp_call_in_progress_event.py +31 -0
- byteplussdkarkruntime/types/responses/response_mcp_item.py +110 -0
- byteplussdkarkruntime/types/responses/response_mcp_list_tools_completed_event.py +31 -0
- byteplussdkarkruntime/types/responses/response_mcp_list_tools_failed_event.py +31 -0
- byteplussdkarkruntime/types/responses/response_mcp_list_tools_in_progress_event.py +31 -0
- byteplussdkarkruntime/types/responses/response_output_item.py +36 -0
- byteplussdkarkruntime/types/responses/response_output_item_added_event.py +29 -0
- byteplussdkarkruntime/types/responses/response_output_item_done_event.py +29 -0
- byteplussdkarkruntime/types/responses/response_output_message.py +43 -0
- byteplussdkarkruntime/types/responses/response_output_text.py +61 -0
- byteplussdkarkruntime/types/responses/response_output_text_param.py +77 -0
- byteplussdkarkruntime/types/responses/response_reasoning_item.py +46 -0
- byteplussdkarkruntime/types/responses/response_reasoning_item_param.py +37 -0
- byteplussdkarkruntime/types/responses/response_reasoning_summary_part_added_event.py +42 -0
- byteplussdkarkruntime/types/responses/response_reasoning_summary_part_done_event.py +42 -0
- byteplussdkarkruntime/types/responses/response_reasoning_summary_text_delta_event.py +34 -0
- byteplussdkarkruntime/types/responses/response_reasoning_summary_text_done_event.py +34 -0
- byteplussdkarkruntime/types/responses/response_status.py +17 -0
- byteplussdkarkruntime/types/responses/response_stream_event.py +93 -0
- byteplussdkarkruntime/types/responses/response_text_config.py +28 -0
- byteplussdkarkruntime/types/responses/response_text_config_param.py +31 -0
- byteplussdkarkruntime/types/responses/response_text_delta_event.py +34 -0
- byteplussdkarkruntime/types/responses/response_text_done_event.py +34 -0
- byteplussdkarkruntime/types/responses/response_tool_usage.py +32 -0
- byteplussdkarkruntime/types/responses/response_usage.py +54 -0
- byteplussdkarkruntime/types/responses/response_web_search_call_completed_event.py +29 -0
- byteplussdkarkruntime/types/responses/response_web_search_call_in_progress_event.py +29 -0
- byteplussdkarkruntime/types/responses/response_web_search_call_searching_event.py +29 -0
- byteplussdkarkruntime/types/responses/response_web_search_item.py +43 -0
- byteplussdkarkruntime/types/responses/tool.py +25 -0
- byteplussdkarkruntime/types/responses/tool_choice_function.py +25 -0
- byteplussdkarkruntime/types/responses/tool_choice_function_param.py +25 -0
- byteplussdkarkruntime/types/responses/tool_choice_mcp_param.py +29 -0
- byteplussdkarkruntime/types/responses/tool_choice_options.py +17 -0
- byteplussdkarkruntime/types/responses/tool_param.py +24 -0
- byteplussdkarkruntime/types/responses/web_search_tool.py +49 -0
- byteplussdkarkruntime/types/responses/web_search_tool_param.py +46 -0
- byteplussdkarkruntime/types/shared/__init__.py +21 -0
- byteplussdkarkruntime/types/shared/reasoning.py +10 -0
- byteplussdkarkruntime/types/shared/reasoning_effort.py +16 -0
- byteplussdkarkruntime/types/shared/response_format_json_object.py +22 -0
- byteplussdkarkruntime/types/shared/response_format_json_schema.py +56 -0
- byteplussdkarkruntime/types/shared/response_format_text.py +22 -0
- byteplussdkarkruntime/types/shared/thinking.py +25 -0
- byteplussdkarkruntime/types/shared_params/__init__.py +13 -0
- byteplussdkarkruntime/types/shared_params/function_definition.py +34 -0
- byteplussdkarkruntime/types/shared_params/function_parameters.py +9 -0
- byteplussdkarkruntime/types/shared_params/metadata.py +20 -0
- byteplussdkarkruntime/types/shared_params/reasoning.py +12 -0
- byteplussdkarkruntime/types/shared_params/reasoning_effort.py +8 -0
- byteplussdkarkruntime/types/shared_params/response_format_json_object.py +22 -0
- byteplussdkarkruntime/types/shared_params/response_format_json_schema.py +54 -0
- byteplussdkarkruntime/types/shared_params/response_format_text.py +22 -0
- byteplussdkarkruntime/types/shared_params/thinking.py +22 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any, List, Tuple, Union, Mapping, TypeVar
|
|
4
|
+
from urllib.parse import parse_qs, urlencode
|
|
5
|
+
from typing_extensions import Literal, get_args
|
|
6
|
+
|
|
7
|
+
from ._types import NOT_GIVEN, NotGiven, NotGivenOr
|
|
8
|
+
from ._utils import flatten
|
|
9
|
+
|
|
10
|
+
_T = TypeVar("_T")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
ArrayFormat = Literal["comma", "repeat", "indices", "brackets"]
|
|
14
|
+
NestedFormat = Literal["dots", "brackets"]
|
|
15
|
+
|
|
16
|
+
PrimitiveData = Union[str, int, float, bool, None]
|
|
17
|
+
# this should be Data = Union[PrimitiveData, "List[Data]", "Tuple[Data]", "Mapping[str, Data]"]
|
|
18
|
+
# https://github.com/microsoft/pyright/issues/3555
|
|
19
|
+
Data = Union[PrimitiveData, List[Any], Tuple[Any], "Mapping[str, Any]"]
|
|
20
|
+
Params = Mapping[str, Data]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class Querystring:
|
|
24
|
+
array_format: ArrayFormat
|
|
25
|
+
nested_format: NestedFormat
|
|
26
|
+
|
|
27
|
+
def __init__(
|
|
28
|
+
self,
|
|
29
|
+
*,
|
|
30
|
+
array_format: ArrayFormat = "repeat",
|
|
31
|
+
nested_format: NestedFormat = "brackets",
|
|
32
|
+
) -> None:
|
|
33
|
+
self.array_format = array_format
|
|
34
|
+
self.nested_format = nested_format
|
|
35
|
+
|
|
36
|
+
def parse(self, query: str) -> Mapping[str, object]:
|
|
37
|
+
# Note: custom format syntax is not supported yet
|
|
38
|
+
return parse_qs(query)
|
|
39
|
+
|
|
40
|
+
def stringify(
|
|
41
|
+
self,
|
|
42
|
+
params: Params,
|
|
43
|
+
*,
|
|
44
|
+
array_format: NotGivenOr[ArrayFormat] = NOT_GIVEN,
|
|
45
|
+
nested_format: NotGivenOr[NestedFormat] = NOT_GIVEN,
|
|
46
|
+
) -> str:
|
|
47
|
+
return urlencode(
|
|
48
|
+
self.stringify_items(
|
|
49
|
+
params,
|
|
50
|
+
array_format=array_format,
|
|
51
|
+
nested_format=nested_format,
|
|
52
|
+
)
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
def stringify_items(
|
|
56
|
+
self,
|
|
57
|
+
params: Params,
|
|
58
|
+
*,
|
|
59
|
+
array_format: NotGivenOr[ArrayFormat] = NOT_GIVEN,
|
|
60
|
+
nested_format: NotGivenOr[NestedFormat] = NOT_GIVEN,
|
|
61
|
+
) -> list[tuple[str, str]]:
|
|
62
|
+
opts = Options(
|
|
63
|
+
qs=self,
|
|
64
|
+
array_format=array_format,
|
|
65
|
+
nested_format=nested_format,
|
|
66
|
+
)
|
|
67
|
+
if isinstance(params, list):
|
|
68
|
+
return flatten(
|
|
69
|
+
[self._stringify_item(key, value, opts) for key, value in params]
|
|
70
|
+
)
|
|
71
|
+
return flatten(
|
|
72
|
+
[self._stringify_item(key, value, opts) for key, value in params.items()]
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
def _stringify_item(
|
|
76
|
+
self,
|
|
77
|
+
key: str,
|
|
78
|
+
value: Data,
|
|
79
|
+
opts: Options,
|
|
80
|
+
) -> list[tuple[str, str]]:
|
|
81
|
+
if isinstance(value, Mapping):
|
|
82
|
+
items: list[tuple[str, str]] = []
|
|
83
|
+
nested_format = opts.nested_format
|
|
84
|
+
for subkey, subvalue in value.items():
|
|
85
|
+
items.extend(
|
|
86
|
+
self._stringify_item(
|
|
87
|
+
# TODO: error if unknown format
|
|
88
|
+
f"{key}.{subkey}"
|
|
89
|
+
if nested_format == "dots"
|
|
90
|
+
else f"{key}[{subkey}]",
|
|
91
|
+
subvalue,
|
|
92
|
+
opts,
|
|
93
|
+
)
|
|
94
|
+
)
|
|
95
|
+
return items
|
|
96
|
+
|
|
97
|
+
if isinstance(value, (list, tuple)):
|
|
98
|
+
array_format = opts.array_format
|
|
99
|
+
if array_format == "comma":
|
|
100
|
+
return [
|
|
101
|
+
(
|
|
102
|
+
key,
|
|
103
|
+
",".join(
|
|
104
|
+
self._primitive_value_to_str(item)
|
|
105
|
+
for item in value
|
|
106
|
+
if item is not None
|
|
107
|
+
),
|
|
108
|
+
),
|
|
109
|
+
]
|
|
110
|
+
elif array_format == "repeat":
|
|
111
|
+
items = []
|
|
112
|
+
for item in value:
|
|
113
|
+
items.extend(self._stringify_item(key, item, opts))
|
|
114
|
+
return items
|
|
115
|
+
elif array_format == "indices":
|
|
116
|
+
raise NotImplementedError(
|
|
117
|
+
"The array indices format is not supported yet"
|
|
118
|
+
)
|
|
119
|
+
elif array_format == "brackets":
|
|
120
|
+
items = []
|
|
121
|
+
key = key + "[]"
|
|
122
|
+
for item in value:
|
|
123
|
+
items.extend(self._stringify_item(key, item, opts))
|
|
124
|
+
return items
|
|
125
|
+
else:
|
|
126
|
+
raise NotImplementedError(
|
|
127
|
+
f"Unknown array_format value: {array_format}, choose from {', '.join(get_args(ArrayFormat))}"
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
serialised = self._primitive_value_to_str(value)
|
|
131
|
+
if not serialised:
|
|
132
|
+
return []
|
|
133
|
+
return [(key, serialised)]
|
|
134
|
+
|
|
135
|
+
def _primitive_value_to_str(self, value: PrimitiveData) -> str:
|
|
136
|
+
# copied from httpx
|
|
137
|
+
if value is True:
|
|
138
|
+
return "true"
|
|
139
|
+
elif value is False:
|
|
140
|
+
return "false"
|
|
141
|
+
elif value is None:
|
|
142
|
+
return ""
|
|
143
|
+
return str(value)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
_qs = Querystring()
|
|
147
|
+
parse = _qs.parse
|
|
148
|
+
stringify = _qs.stringify
|
|
149
|
+
stringify_items = _qs.stringify_items
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
class Options:
|
|
153
|
+
array_format: ArrayFormat
|
|
154
|
+
nested_format: NestedFormat
|
|
155
|
+
|
|
156
|
+
def __init__(
|
|
157
|
+
self,
|
|
158
|
+
qs: Querystring = _qs,
|
|
159
|
+
*,
|
|
160
|
+
array_format: NotGivenOr[ArrayFormat] = NOT_GIVEN,
|
|
161
|
+
nested_format: NotGivenOr[NestedFormat] = NOT_GIVEN,
|
|
162
|
+
) -> None:
|
|
163
|
+
self.array_format = (
|
|
164
|
+
qs.array_format if isinstance(array_format, NotGiven) else array_format
|
|
165
|
+
)
|
|
166
|
+
self.nested_format = (
|
|
167
|
+
qs.nested_format if isinstance(nested_format, NotGiven) else nested_format
|
|
168
|
+
)
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Union, Any, TYPE_CHECKING, cast, Optional
|
|
4
|
+
|
|
5
|
+
import pydantic
|
|
6
|
+
from httpx import Timeout
|
|
7
|
+
from typing_extensions import Unpack, TypedDict, ClassVar
|
|
8
|
+
|
|
9
|
+
from ._compat import PYDANTIC_V2, ConfigDict
|
|
10
|
+
from ._models import BaseModel
|
|
11
|
+
|
|
12
|
+
__all__ = ["ExtraRequestOptions", "RequestOptions"]
|
|
13
|
+
|
|
14
|
+
from ._types import NotGiven
|
|
15
|
+
|
|
16
|
+
from typing import (
|
|
17
|
+
Callable,
|
|
18
|
+
)
|
|
19
|
+
from typing_extensions import (
|
|
20
|
+
Required,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
from ._types import (
|
|
25
|
+
Body,
|
|
26
|
+
Query,
|
|
27
|
+
Headers,
|
|
28
|
+
AnyMapping,
|
|
29
|
+
HttpxRequestFiles,
|
|
30
|
+
)
|
|
31
|
+
from ._utils import (
|
|
32
|
+
is_given,
|
|
33
|
+
strip_not_given,
|
|
34
|
+
)
|
|
35
|
+
from ._constants import RAW_RESPONSE_HEADER
|
|
36
|
+
|
|
37
|
+
if TYPE_CHECKING:
|
|
38
|
+
pass
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class ExtraRequestOptions(TypedDict, total=False):
|
|
42
|
+
method: Required[str]
|
|
43
|
+
url: Required[str]
|
|
44
|
+
params: Query
|
|
45
|
+
headers: Headers
|
|
46
|
+
max_retries: int
|
|
47
|
+
timeout: Optional[Union[float, Timeout]]
|
|
48
|
+
files: Optional[HttpxRequestFiles]
|
|
49
|
+
idempotency_key: str
|
|
50
|
+
json_data: Body
|
|
51
|
+
extra_body: AnyMapping
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class RequestOptions(BaseModel):
|
|
55
|
+
method: str
|
|
56
|
+
url: str
|
|
57
|
+
body: Union[object, None] = {}
|
|
58
|
+
params: Query = {}
|
|
59
|
+
headers: Union[Headers, NotGiven] = NotGiven()
|
|
60
|
+
max_retries: Union[int, NotGiven] = NotGiven()
|
|
61
|
+
timeout: Union[float, Timeout, None, NotGiven] = NotGiven()
|
|
62
|
+
files: Union[HttpxRequestFiles, None] = None
|
|
63
|
+
idempotency_key: Union[str, None] = None
|
|
64
|
+
post_parser: Union[Callable[[Any], Any], NotGiven] = NotGiven()
|
|
65
|
+
|
|
66
|
+
# It should be noted that we cannot use `json` here as that would override
|
|
67
|
+
# a BaseModel method in an incompatible fashion.
|
|
68
|
+
json_data: Union[Body, None] = None
|
|
69
|
+
extra_body: Union[AnyMapping, None] = None
|
|
70
|
+
|
|
71
|
+
if PYDANTIC_V2:
|
|
72
|
+
model_config: ClassVar[ConfigDict] = ConfigDict(arbitrary_types_allowed=True)
|
|
73
|
+
else:
|
|
74
|
+
|
|
75
|
+
class Config(pydantic.BaseConfig): # pyright: ignore[reportDeprecated]
|
|
76
|
+
arbitrary_types_allowed: bool = True
|
|
77
|
+
|
|
78
|
+
def get_max_retries(self, max_retries: int) -> int:
|
|
79
|
+
if isinstance(self.max_retries, NotGiven):
|
|
80
|
+
return max_retries
|
|
81
|
+
return self.max_retries
|
|
82
|
+
|
|
83
|
+
def _strip_raw_response_header(self) -> None:
|
|
84
|
+
if not is_given(self.headers):
|
|
85
|
+
return
|
|
86
|
+
|
|
87
|
+
if self.headers.get(RAW_RESPONSE_HEADER):
|
|
88
|
+
self.headers = {**self.headers}
|
|
89
|
+
self.headers.pop(RAW_RESPONSE_HEADER)
|
|
90
|
+
|
|
91
|
+
# override the `construct` method so that we can run custom transformations.
|
|
92
|
+
# this is necessary as we don't want to do any actual runtime type checking
|
|
93
|
+
# (which means we can't use validators) but we do want to ensure that `NotGiven`
|
|
94
|
+
# values are not present
|
|
95
|
+
#
|
|
96
|
+
# type ignore required because we're adding explicit types to `**values`
|
|
97
|
+
@classmethod
|
|
98
|
+
def construct( # type: ignore
|
|
99
|
+
cls,
|
|
100
|
+
_fields_set: Optional[set[str]] = None,
|
|
101
|
+
**values: Unpack[ExtraRequestOptions],
|
|
102
|
+
) -> RequestOptions:
|
|
103
|
+
kwargs: dict[str, Any] = {
|
|
104
|
+
# we unconditionally call `strip_not_given` on any value
|
|
105
|
+
# as it will just ignore any non-mapping types
|
|
106
|
+
key: strip_not_given(value)
|
|
107
|
+
for key, value in values.items()
|
|
108
|
+
}
|
|
109
|
+
if PYDANTIC_V2:
|
|
110
|
+
return super().model_construct(_fields_set, **kwargs)
|
|
111
|
+
return cast(
|
|
112
|
+
RequestOptions, super().construct(_fields_set, **kwargs)
|
|
113
|
+
) # pyright: ignore[reportDeprecated]
|
|
114
|
+
|
|
115
|
+
if not TYPE_CHECKING:
|
|
116
|
+
# type checkers incorrectly complain about this assignment
|
|
117
|
+
model_construct = construct
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Copyright (c) [2025] [OpenAI]
|
|
2
|
+
# Copyright (c) [2025] [ByteDance Ltd. and/or its affiliates.]
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
#
|
|
5
|
+
# This file has been modified by [ByteDance Ltd. and/or its affiliates.] on 2025.7
|
|
6
|
+
#
|
|
7
|
+
# Original file was released under Apache License Version 2.0, with the full license text
|
|
8
|
+
# available at https://github.com/openai/openai-python/blob/main/LICENSE.
|
|
9
|
+
#
|
|
10
|
+
# This modified file is released under the same license.
|
|
11
|
+
|
|
12
|
+
from typing import TYPE_CHECKING
|
|
13
|
+
import time
|
|
14
|
+
import anyio
|
|
15
|
+
|
|
16
|
+
if TYPE_CHECKING:
|
|
17
|
+
from ._client import Ark, AsyncArk
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class SyncAPIResource:
|
|
21
|
+
_client: "Ark"
|
|
22
|
+
|
|
23
|
+
def __init__(self, client: "Ark") -> None:
|
|
24
|
+
self._client = client
|
|
25
|
+
self._post = client.post
|
|
26
|
+
self._get = client.get
|
|
27
|
+
self._delete = client.delete
|
|
28
|
+
self._post_without_retry = client.post_without_retry
|
|
29
|
+
self._get_api_list = client.get_api_list
|
|
30
|
+
|
|
31
|
+
def _sleep(self, seconds: float) -> None:
|
|
32
|
+
time.sleep(seconds)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class AsyncAPIResource:
|
|
36
|
+
_client: "AsyncArk"
|
|
37
|
+
|
|
38
|
+
def __init__(self, client: "AsyncArk") -> None:
|
|
39
|
+
self._client = client
|
|
40
|
+
self._post = client.post
|
|
41
|
+
self._get = client.get
|
|
42
|
+
self._delete = client.delete
|
|
43
|
+
self._post_without_retry = client.post_without_retry
|
|
44
|
+
self._get_api_list = client.get_api_list
|
|
45
|
+
|
|
46
|
+
async def _sleep(self, seconds: float) -> None:
|
|
47
|
+
await anyio.sleep(seconds)
|