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.
Files changed (240) hide show
  1. byteplussdk_arkruntime-3.0.64.dist-info/METADATA +36 -0
  2. byteplussdk_arkruntime-3.0.64.dist-info/RECORD +240 -0
  3. byteplussdk_arkruntime-3.0.64.dist-info/WHEEL +5 -0
  4. byteplussdk_arkruntime-3.0.64.dist-info/licenses/LICENSE.txt +203 -0
  5. byteplussdk_arkruntime-3.0.64.dist-info/top_level.txt +1 -0
  6. byteplussdkarkruntime/__init__.py +7 -0
  7. byteplussdkarkruntime/_base_client.py +1439 -0
  8. byteplussdkarkruntime/_client.py +570 -0
  9. byteplussdkarkruntime/_compat.py +245 -0
  10. byteplussdkarkruntime/_constants.py +43 -0
  11. byteplussdkarkruntime/_exceptions.py +202 -0
  12. byteplussdkarkruntime/_files.py +149 -0
  13. byteplussdkarkruntime/_legacy_response.py +451 -0
  14. byteplussdkarkruntime/_models.py +734 -0
  15. byteplussdkarkruntime/_qs.py +168 -0
  16. byteplussdkarkruntime/_request_options.py +117 -0
  17. byteplussdkarkruntime/_resource.py +47 -0
  18. byteplussdkarkruntime/_response.py +615 -0
  19. byteplussdkarkruntime/_streaming.py +470 -0
  20. byteplussdkarkruntime/_types.py +210 -0
  21. byteplussdkarkruntime/_utils/__init__.py +58 -0
  22. byteplussdkarkruntime/_utils/_key_agreement.py +207 -0
  23. byteplussdkarkruntime/_utils/_logs.py +24 -0
  24. byteplussdkarkruntime/_utils/_model_breaker.py +83 -0
  25. byteplussdkarkruntime/_utils/_streams.py +12 -0
  26. byteplussdkarkruntime/_utils/_transform.py +489 -0
  27. byteplussdkarkruntime/_utils/_typing.py +171 -0
  28. byteplussdkarkruntime/_utils/_utils.py +497 -0
  29. byteplussdkarkruntime/common/__init__.py +14 -0
  30. byteplussdkarkruntime/common/_parsing/__init__.py +22 -0
  31. byteplussdkarkruntime/common/_parsing/_completions.py +290 -0
  32. byteplussdkarkruntime/common/_parsing/_responses.py +189 -0
  33. byteplussdkarkruntime/common/_pydantic.py +192 -0
  34. byteplussdkarkruntime/common/_tools.py +67 -0
  35. byteplussdkarkruntime/common/streaming/__init__.py +12 -0
  36. byteplussdkarkruntime/common/streaming/_deltas.py +86 -0
  37. byteplussdkarkruntime/common/streaming/chat/__init__.py +33 -0
  38. byteplussdkarkruntime/common/streaming/chat/_completions.py +772 -0
  39. byteplussdkarkruntime/common/streaming/chat/_events.py +103 -0
  40. byteplussdkarkruntime/common/streaming/chat/_types.py +36 -0
  41. byteplussdkarkruntime/pagination.py +134 -0
  42. byteplussdkarkruntime/resources/__init__.py +48 -0
  43. byteplussdkarkruntime/resources/batch/__init__.py +3 -0
  44. byteplussdkarkruntime/resources/batch/_utils.py +155 -0
  45. byteplussdkarkruntime/resources/batch/batch.py +37 -0
  46. byteplussdkarkruntime/resources/batch/chat/__init__.py +3 -0
  47. byteplussdkarkruntime/resources/batch/chat/chat.py +19 -0
  48. byteplussdkarkruntime/resources/batch/chat/completions.py +329 -0
  49. byteplussdkarkruntime/resources/batch/embeddings.py +105 -0
  50. byteplussdkarkruntime/resources/batch/multimodal_embeddings.py +111 -0
  51. byteplussdkarkruntime/resources/batch_chat/__init__.py +3 -0
  52. byteplussdkarkruntime/resources/batch_chat/chat.py +21 -0
  53. byteplussdkarkruntime/resources/batch_chat/completions.py +328 -0
  54. byteplussdkarkruntime/resources/beta/__init__.py +12 -0
  55. byteplussdkarkruntime/resources/beta/beta.py +81 -0
  56. byteplussdkarkruntime/resources/beta/chat/__init__.py +21 -0
  57. byteplussdkarkruntime/resources/beta/chat/chat.py +31 -0
  58. byteplussdkarkruntime/resources/beta/chat/completions.py +454 -0
  59. byteplussdkarkruntime/resources/chat/__init__.py +3 -0
  60. byteplussdkarkruntime/resources/chat/chat.py +21 -0
  61. byteplussdkarkruntime/resources/chat/completions.py +258 -0
  62. byteplussdkarkruntime/resources/content_generation/__init__.py +6 -0
  63. byteplussdkarkruntime/resources/content_generation/content_generation.py +17 -0
  64. byteplussdkarkruntime/resources/content_generation/tasks.py +348 -0
  65. byteplussdkarkruntime/resources/context/__init__.py +3 -0
  66. byteplussdkarkruntime/resources/context/completions.py +221 -0
  67. byteplussdkarkruntime/resources/context/context.py +98 -0
  68. byteplussdkarkruntime/resources/embeddings.py +110 -0
  69. byteplussdkarkruntime/resources/encryption.py +215 -0
  70. byteplussdkarkruntime/resources/files.py +592 -0
  71. byteplussdkarkruntime/resources/images/__init__.py +6 -0
  72. byteplussdkarkruntime/resources/images/images.py +335 -0
  73. byteplussdkarkruntime/resources/multimodal_embeddings.py +113 -0
  74. byteplussdkarkruntime/resources/responses/__init__.py +16 -0
  75. byteplussdkarkruntime/resources/responses/input_items.py +248 -0
  76. byteplussdkarkruntime/resources/responses/responses.py +417 -0
  77. byteplussdkarkruntime/types/__init__.py +28 -0
  78. byteplussdkarkruntime/types/chat/__init__.py +78 -0
  79. byteplussdkarkruntime/types/chat/chat_completion.py +93 -0
  80. byteplussdkarkruntime/types/chat/chat_completion_assistant_message_param.py +61 -0
  81. byteplussdkarkruntime/types/chat/chat_completion_audio.py +22 -0
  82. byteplussdkarkruntime/types/chat/chat_completion_chunk.py +165 -0
  83. byteplussdkarkruntime/types/chat/chat_completion_content_part_image_param.py +20 -0
  84. byteplussdkarkruntime/types/chat/chat_completion_content_part_param.py +30 -0
  85. byteplussdkarkruntime/types/chat/chat_completion_content_part_text_param.py +13 -0
  86. byteplussdkarkruntime/types/chat/chat_completion_content_part_video_param.py +32 -0
  87. byteplussdkarkruntime/types/chat/chat_completion_function_call_option_param.py +10 -0
  88. byteplussdkarkruntime/types/chat/chat_completion_function_message_param.py +17 -0
  89. byteplussdkarkruntime/types/chat/chat_completion_message.py +56 -0
  90. byteplussdkarkruntime/types/chat/chat_completion_message_param.py +19 -0
  91. byteplussdkarkruntime/types/chat/chat_completion_message_tool_call.py +29 -0
  92. byteplussdkarkruntime/types/chat/chat_completion_message_tool_call_param.py +29 -0
  93. byteplussdkarkruntime/types/chat/chat_completion_named_tool_choice_param.py +17 -0
  94. byteplussdkarkruntime/types/chat/chat_completion_role.py +5 -0
  95. byteplussdkarkruntime/types/chat/chat_completion_stream_options_param.py +19 -0
  96. byteplussdkarkruntime/types/chat/chat_completion_system_message_param.py +34 -0
  97. byteplussdkarkruntime/types/chat/chat_completion_token_logprob.py +55 -0
  98. byteplussdkarkruntime/types/chat/chat_completion_tool_choice_option_param.py +12 -0
  99. byteplussdkarkruntime/types/chat/chat_completion_tool_message_param.py +37 -0
  100. byteplussdkarkruntime/types/chat/chat_completion_tool_param.py +14 -0
  101. byteplussdkarkruntime/types/chat/chat_completion_user_message_param.py +34 -0
  102. byteplussdkarkruntime/types/chat/completion_create_params.py +258 -0
  103. byteplussdkarkruntime/types/chat/parsed_chat_completion.py +52 -0
  104. byteplussdkarkruntime/types/chat/parsed_function_tool_call.py +34 -0
  105. byteplussdkarkruntime/types/completion_usage.py +33 -0
  106. byteplussdkarkruntime/types/content_generation/__init__.py +0 -0
  107. byteplussdkarkruntime/types/content_generation/content_generation_task.py +106 -0
  108. byteplussdkarkruntime/types/content_generation/content_generation_task_id.py +11 -0
  109. byteplussdkarkruntime/types/content_generation/create_task_content_param.py +72 -0
  110. byteplussdkarkruntime/types/content_generation/list_content_generation_tasks_response.py +24 -0
  111. byteplussdkarkruntime/types/context/__init__.py +8 -0
  112. byteplussdkarkruntime/types/context/context_chat_completion.py +33 -0
  113. byteplussdkarkruntime/types/context/context_chat_completion_chunk.py +41 -0
  114. byteplussdkarkruntime/types/context/context_create_params.py +37 -0
  115. byteplussdkarkruntime/types/context/create_context_response.py +25 -0
  116. byteplussdkarkruntime/types/context/truncation_strategy.py +13 -0
  117. byteplussdkarkruntime/types/create_embedding_response.py +36 -0
  118. byteplussdkarkruntime/types/embedding.py +21 -0
  119. byteplussdkarkruntime/types/file_create_params.py +49 -0
  120. byteplussdkarkruntime/types/file_deleted.py +24 -0
  121. byteplussdkarkruntime/types/file_list_params.py +43 -0
  122. byteplussdkarkruntime/types/file_object.py +69 -0
  123. byteplussdkarkruntime/types/file_purpose.py +16 -0
  124. byteplussdkarkruntime/types/images/__init__.py +3 -0
  125. byteplussdkarkruntime/types/images/image_gen_completed_event.py +59 -0
  126. byteplussdkarkruntime/types/images/image_gen_generating_event.py +53 -0
  127. byteplussdkarkruntime/types/images/image_gen_stream_event.py +24 -0
  128. byteplussdkarkruntime/types/images/images.py +99 -0
  129. byteplussdkarkruntime/types/multimodal_embedding/__init__.py +15 -0
  130. byteplussdkarkruntime/types/multimodal_embedding/embedding_content_part_image_param.py +17 -0
  131. byteplussdkarkruntime/types/multimodal_embedding/embedding_content_part_text_param.py +13 -0
  132. byteplussdkarkruntime/types/multimodal_embedding/embedding_data.py +15 -0
  133. byteplussdkarkruntime/types/multimodal_embedding/embedding_input.py +12 -0
  134. byteplussdkarkruntime/types/multimodal_embedding/embedding_response.py +29 -0
  135. byteplussdkarkruntime/types/multimodal_embedding/embedding_usage.py +23 -0
  136. byteplussdkarkruntime/types/responses/__init__.py +133 -0
  137. byteplussdkarkruntime/types/responses/easy_input_message.py +36 -0
  138. byteplussdkarkruntime/types/responses/easy_input_message_param.py +37 -0
  139. byteplussdkarkruntime/types/responses/function_tool.py +35 -0
  140. byteplussdkarkruntime/types/responses/function_tool_param.py +35 -0
  141. byteplussdkarkruntime/types/responses/input_item_list_params.py +47 -0
  142. byteplussdkarkruntime/types/responses/mcp_input_item_param.py +109 -0
  143. byteplussdkarkruntime/types/responses/mcp_tool.py +80 -0
  144. byteplussdkarkruntime/types/responses/mcp_tool_param.py +78 -0
  145. byteplussdkarkruntime/types/responses/response.py +152 -0
  146. byteplussdkarkruntime/types/responses/response_annotation_added_event.py +36 -0
  147. byteplussdkarkruntime/types/responses/response_caching.py +25 -0
  148. byteplussdkarkruntime/types/responses/response_caching_param.py +22 -0
  149. byteplussdkarkruntime/types/responses/response_completed_event.py +26 -0
  150. byteplussdkarkruntime/types/responses/response_content_part_added_event.py +39 -0
  151. byteplussdkarkruntime/types/responses/response_content_part_done_event.py +39 -0
  152. byteplussdkarkruntime/types/responses/response_create_params.py +26 -0
  153. byteplussdkarkruntime/types/responses/response_created_event.py +26 -0
  154. byteplussdkarkruntime/types/responses/response_error.py +25 -0
  155. byteplussdkarkruntime/types/responses/response_error_event.py +32 -0
  156. byteplussdkarkruntime/types/responses/response_failed_event.py +26 -0
  157. byteplussdkarkruntime/types/responses/response_format_text_config.py +25 -0
  158. byteplussdkarkruntime/types/responses/response_format_text_config_param.py +25 -0
  159. byteplussdkarkruntime/types/responses/response_function_call_arguments_delta_event.py +33 -0
  160. byteplussdkarkruntime/types/responses/response_function_call_arguments_done_event.py +30 -0
  161. byteplussdkarkruntime/types/responses/response_function_tool_call.py +42 -0
  162. byteplussdkarkruntime/types/responses/response_function_tool_call_item.py +20 -0
  163. byteplussdkarkruntime/types/responses/response_function_tool_call_output_item.py +39 -0
  164. byteplussdkarkruntime/types/responses/response_function_tool_call_param.py +31 -0
  165. byteplussdkarkruntime/types/responses/response_in_progress_event.py +26 -0
  166. byteplussdkarkruntime/types/responses/response_includable.py +19 -0
  167. byteplussdkarkruntime/types/responses/response_incomplete_details.py +30 -0
  168. byteplussdkarkruntime/types/responses/response_incomplete_event.py +26 -0
  169. byteplussdkarkruntime/types/responses/response_input_content.py +24 -0
  170. byteplussdkarkruntime/types/responses/response_input_content_param.py +23 -0
  171. byteplussdkarkruntime/types/responses/response_input_image.py +38 -0
  172. byteplussdkarkruntime/types/responses/response_input_image_param.py +42 -0
  173. byteplussdkarkruntime/types/responses/response_input_image_pixel_limit_param.py +29 -0
  174. byteplussdkarkruntime/types/responses/response_input_message_content_list.py +20 -0
  175. byteplussdkarkruntime/types/responses/response_input_message_content_list_param.py +26 -0
  176. byteplussdkarkruntime/types/responses/response_input_message_item.py +43 -0
  177. byteplussdkarkruntime/types/responses/response_input_param.py +51 -0
  178. byteplussdkarkruntime/types/responses/response_input_text.py +25 -0
  179. byteplussdkarkruntime/types/responses/response_input_text_param.py +25 -0
  180. byteplussdkarkruntime/types/responses/response_input_video_param.py +34 -0
  181. byteplussdkarkruntime/types/responses/response_item.py +40 -0
  182. byteplussdkarkruntime/types/responses/response_item_list.py +36 -0
  183. byteplussdkarkruntime/types/responses/response_mcp_call_arguments_delta_event.py +37 -0
  184. byteplussdkarkruntime/types/responses/response_mcp_call_arguments_done_event.py +34 -0
  185. byteplussdkarkruntime/types/responses/response_mcp_call_completed_event.py +31 -0
  186. byteplussdkarkruntime/types/responses/response_mcp_call_failed_event.py +31 -0
  187. byteplussdkarkruntime/types/responses/response_mcp_call_in_progress_event.py +31 -0
  188. byteplussdkarkruntime/types/responses/response_mcp_item.py +110 -0
  189. byteplussdkarkruntime/types/responses/response_mcp_list_tools_completed_event.py +31 -0
  190. byteplussdkarkruntime/types/responses/response_mcp_list_tools_failed_event.py +31 -0
  191. byteplussdkarkruntime/types/responses/response_mcp_list_tools_in_progress_event.py +31 -0
  192. byteplussdkarkruntime/types/responses/response_output_item.py +36 -0
  193. byteplussdkarkruntime/types/responses/response_output_item_added_event.py +29 -0
  194. byteplussdkarkruntime/types/responses/response_output_item_done_event.py +29 -0
  195. byteplussdkarkruntime/types/responses/response_output_message.py +43 -0
  196. byteplussdkarkruntime/types/responses/response_output_text.py +61 -0
  197. byteplussdkarkruntime/types/responses/response_output_text_param.py +77 -0
  198. byteplussdkarkruntime/types/responses/response_reasoning_item.py +46 -0
  199. byteplussdkarkruntime/types/responses/response_reasoning_item_param.py +37 -0
  200. byteplussdkarkruntime/types/responses/response_reasoning_summary_part_added_event.py +42 -0
  201. byteplussdkarkruntime/types/responses/response_reasoning_summary_part_done_event.py +42 -0
  202. byteplussdkarkruntime/types/responses/response_reasoning_summary_text_delta_event.py +34 -0
  203. byteplussdkarkruntime/types/responses/response_reasoning_summary_text_done_event.py +34 -0
  204. byteplussdkarkruntime/types/responses/response_status.py +17 -0
  205. byteplussdkarkruntime/types/responses/response_stream_event.py +93 -0
  206. byteplussdkarkruntime/types/responses/response_text_config.py +28 -0
  207. byteplussdkarkruntime/types/responses/response_text_config_param.py +31 -0
  208. byteplussdkarkruntime/types/responses/response_text_delta_event.py +34 -0
  209. byteplussdkarkruntime/types/responses/response_text_done_event.py +34 -0
  210. byteplussdkarkruntime/types/responses/response_tool_usage.py +32 -0
  211. byteplussdkarkruntime/types/responses/response_usage.py +54 -0
  212. byteplussdkarkruntime/types/responses/response_web_search_call_completed_event.py +29 -0
  213. byteplussdkarkruntime/types/responses/response_web_search_call_in_progress_event.py +29 -0
  214. byteplussdkarkruntime/types/responses/response_web_search_call_searching_event.py +29 -0
  215. byteplussdkarkruntime/types/responses/response_web_search_item.py +43 -0
  216. byteplussdkarkruntime/types/responses/tool.py +25 -0
  217. byteplussdkarkruntime/types/responses/tool_choice_function.py +25 -0
  218. byteplussdkarkruntime/types/responses/tool_choice_function_param.py +25 -0
  219. byteplussdkarkruntime/types/responses/tool_choice_mcp_param.py +29 -0
  220. byteplussdkarkruntime/types/responses/tool_choice_options.py +17 -0
  221. byteplussdkarkruntime/types/responses/tool_param.py +24 -0
  222. byteplussdkarkruntime/types/responses/web_search_tool.py +49 -0
  223. byteplussdkarkruntime/types/responses/web_search_tool_param.py +46 -0
  224. byteplussdkarkruntime/types/shared/__init__.py +21 -0
  225. byteplussdkarkruntime/types/shared/reasoning.py +10 -0
  226. byteplussdkarkruntime/types/shared/reasoning_effort.py +16 -0
  227. byteplussdkarkruntime/types/shared/response_format_json_object.py +22 -0
  228. byteplussdkarkruntime/types/shared/response_format_json_schema.py +56 -0
  229. byteplussdkarkruntime/types/shared/response_format_text.py +22 -0
  230. byteplussdkarkruntime/types/shared/thinking.py +25 -0
  231. byteplussdkarkruntime/types/shared_params/__init__.py +13 -0
  232. byteplussdkarkruntime/types/shared_params/function_definition.py +34 -0
  233. byteplussdkarkruntime/types/shared_params/function_parameters.py +9 -0
  234. byteplussdkarkruntime/types/shared_params/metadata.py +20 -0
  235. byteplussdkarkruntime/types/shared_params/reasoning.py +12 -0
  236. byteplussdkarkruntime/types/shared_params/reasoning_effort.py +8 -0
  237. byteplussdkarkruntime/types/shared_params/response_format_json_object.py +22 -0
  238. byteplussdkarkruntime/types/shared_params/response_format_json_schema.py +54 -0
  239. byteplussdkarkruntime/types/shared_params/response_format_text.py +22 -0
  240. byteplussdkarkruntime/types/shared_params/thinking.py +22 -0
@@ -0,0 +1,497 @@
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 __future__ import annotations
13
+
14
+ import os
15
+ import inspect
16
+ import functools
17
+ import random
18
+ import string
19
+ from typing import (
20
+ Any,
21
+ Tuple,
22
+ Mapping,
23
+ TypeVar,
24
+ Callable,
25
+ Iterable,
26
+ Sequence,
27
+ cast,
28
+ overload,
29
+ )
30
+ from pathlib import Path
31
+ from datetime import date, datetime
32
+ from typing_extensions import TypeGuard
33
+
34
+ import sniffio
35
+
36
+ from .._types import NotGiven, FileTypes, NotGivenOr
37
+
38
+ _T = TypeVar("_T")
39
+ _TupleT = TypeVar("_TupleT", bound=Tuple[object, ...])
40
+ _MappingT = TypeVar("_MappingT", bound=Mapping[str, object])
41
+ _SequenceT = TypeVar("_SequenceT", bound=Sequence[object])
42
+ CallableT = TypeVar("CallableT", bound=Callable[..., Any])
43
+
44
+
45
+ def flatten(t: Iterable[Iterable[_T]]) -> list[_T]:
46
+ return [item for sublist in t for item in sublist]
47
+
48
+
49
+ def extract_files(
50
+ # TODO: this needs to take Dict but variance issues.....
51
+ # create protocol type ?
52
+ query: Mapping[str, object],
53
+ *,
54
+ paths: Sequence[Sequence[str]],
55
+ ) -> list[tuple[str, FileTypes]]:
56
+ """Recursively extract files from the given dictionary based on specified paths.
57
+
58
+ A path may look like this ['foo', 'files', '<array>', 'data'].
59
+
60
+ Note: this mutates the given dictionary.
61
+ """
62
+ files: list[tuple[str, FileTypes]] = []
63
+ for path in paths:
64
+ files.extend(_extract_items(query, path, index=0, flattened_key=None))
65
+ return files
66
+
67
+
68
+ def _extract_items(
69
+ obj: object,
70
+ path: Sequence[str],
71
+ *,
72
+ index: int,
73
+ flattened_key: str | None,
74
+ ) -> list[tuple[str, FileTypes]]:
75
+ try:
76
+ key = path[index]
77
+ except IndexError:
78
+ if isinstance(obj, NotGiven):
79
+ # no value was provided - we can safely ignore
80
+ return []
81
+
82
+ # cyclical import
83
+ from .._files import assert_is_file_content
84
+
85
+ # We have exhausted the path, return the entry we found.
86
+ assert_is_file_content(obj, key=flattened_key)
87
+ assert flattened_key is not None
88
+ return [(flattened_key, cast(FileTypes, obj))]
89
+
90
+ index += 1
91
+ if is_dict(obj):
92
+ try:
93
+ # We are at the last entry in the path so we must remove the field
94
+ if (len(path)) == index:
95
+ item = obj.pop(key)
96
+ else:
97
+ item = obj[key]
98
+ except KeyError:
99
+ # Key was not present in the dictionary, this is not indicative of an error
100
+ # as the given path may not point to a required field. We also do not want
101
+ # to enforce required fields as the API may differ from the spec in some cases.
102
+ return []
103
+ if flattened_key is None:
104
+ flattened_key = key
105
+ else:
106
+ flattened_key += f"[{key}]"
107
+ return _extract_items(
108
+ item,
109
+ path,
110
+ index=index,
111
+ flattened_key=flattened_key,
112
+ )
113
+ elif is_list(obj):
114
+ if key != "<array>":
115
+ return []
116
+
117
+ return flatten(
118
+ [
119
+ _extract_items(
120
+ item,
121
+ path,
122
+ index=index,
123
+ flattened_key=(
124
+ flattened_key + "[]" if flattened_key is not None else "[]"
125
+ ),
126
+ )
127
+ for item in obj
128
+ ]
129
+ )
130
+
131
+ # Something unexpected was passed, just ignore it.
132
+ return []
133
+
134
+
135
+ def is_given(obj: NotGivenOr[_T]) -> TypeGuard[_T]:
136
+ return not isinstance(obj, NotGiven)
137
+
138
+
139
+ # Type safe methods for narrowing types with TypeVars.
140
+ # The default narrowing for isinstance(obj, dict) is dict[unknown, unknown],
141
+ # however this cause Pyright to rightfully report errors. As we know we don't
142
+ # care about the contained types we can safely use `object` in it's place.
143
+ #
144
+ # There are two separate functions defined, `is_*` and `is_*_t` for different use cases.
145
+ # `is_*` is for when you're dealing with an unknown input
146
+ # `is_*_t` is for when you're narrowing a known union type to a specific subset
147
+
148
+
149
+ def is_tuple(obj: object) -> TypeGuard[tuple[object, ...]]:
150
+ return isinstance(obj, tuple)
151
+
152
+
153
+ def is_tuple_t(obj: _TupleT | object) -> TypeGuard[_TupleT]:
154
+ return isinstance(obj, tuple)
155
+
156
+
157
+ def is_sequence(obj: object) -> TypeGuard[Sequence[object]]:
158
+ return isinstance(obj, Sequence)
159
+
160
+
161
+ def is_sequence_t(obj: _SequenceT | object) -> TypeGuard[_SequenceT]:
162
+ return isinstance(obj, Sequence)
163
+
164
+
165
+ def is_mapping(obj: object) -> TypeGuard[Mapping[str, object]]:
166
+ return isinstance(obj, Mapping)
167
+
168
+
169
+ def is_mapping_t(obj: _MappingT | object) -> TypeGuard[_MappingT]:
170
+ return isinstance(obj, Mapping)
171
+
172
+
173
+ def is_dict(obj: object) -> TypeGuard[dict[object, object]]:
174
+ return isinstance(obj, dict)
175
+
176
+
177
+ def is_list(obj: object) -> TypeGuard[list[object]]:
178
+ return isinstance(obj, list)
179
+
180
+
181
+ def is_iterable(obj: object) -> TypeGuard[Iterable[object]]:
182
+ return isinstance(obj, Iterable)
183
+
184
+
185
+ def deepcopy_minimal(item: _T) -> _T:
186
+ """Minimal reimplementation of copy.deepcopy() that will only copy certain object types:
187
+
188
+ - mappings, e.g. `dict`
189
+ - list
190
+
191
+ This is done for performance reasons.
192
+ """
193
+ if is_mapping(item):
194
+ return cast(_T, {k: deepcopy_minimal(v) for k, v in item.items()})
195
+ if is_list(item):
196
+ return cast(_T, [deepcopy_minimal(entry) for entry in item])
197
+ return item
198
+
199
+
200
+ # copied from https://github.com/Rapptz/RoboDanny
201
+ def human_join(seq: Sequence[str], *, delim: str = ", ", final: str = "or") -> str:
202
+ size = len(seq)
203
+ if size == 0:
204
+ return ""
205
+
206
+ if size == 1:
207
+ return seq[0]
208
+
209
+ if size == 2:
210
+ return f"{seq[0]} {final} {seq[1]}"
211
+
212
+ return delim.join(seq[:-1]) + f" {final} {seq[-1]}"
213
+
214
+
215
+ def quote(string: str) -> str:
216
+ """Add single quotation marks around the given string. Does *not* do any escaping."""
217
+ return f"'{string}'"
218
+
219
+
220
+ def required_args(*variants: Sequence[str]) -> Callable[[CallableT], CallableT]:
221
+ """Decorator to enforce a given set of arguments or variants of arguments are passed to the decorated function.
222
+
223
+ Useful for enforcing runtime validation of overloaded functions.
224
+
225
+ Example usage:
226
+ ```py
227
+ @overload
228
+ def foo(*, a: str) -> str: ...
229
+
230
+
231
+ @overload
232
+ def foo(*, b: bool) -> str: ...
233
+
234
+
235
+ # This enforces the same constraints that a static type checker would
236
+ # i.e. that either a or b must be passed to the function
237
+ @required_args(["a"], ["b"])
238
+ def foo(*, a: str | None = None, b: bool | None = None) -> str: ...
239
+ ```
240
+ """
241
+
242
+ def inner(func: CallableT) -> CallableT:
243
+ params = inspect.signature(func).parameters
244
+ positional = [
245
+ name
246
+ for name, param in params.items()
247
+ if param.kind
248
+ in {
249
+ param.POSITIONAL_ONLY,
250
+ param.POSITIONAL_OR_KEYWORD,
251
+ }
252
+ ]
253
+
254
+ @functools.wraps(func)
255
+ def wrapper(*args: object, **kwargs: object) -> object:
256
+ given_params: set[str] = set()
257
+ for i, _ in enumerate(args):
258
+ try:
259
+ given_params.add(positional[i])
260
+ except IndexError:
261
+ raise TypeError(
262
+ f"{func.__name__}() takes {len(positional)} argument(s) but {len(args)} were given"
263
+ ) from None
264
+
265
+ for key in kwargs.keys():
266
+ given_params.add(key)
267
+
268
+ for variant in variants:
269
+ matches = all((param in given_params for param in variant))
270
+ if matches:
271
+ break
272
+ else: # no break
273
+ if len(variants) > 1:
274
+ variations = human_join(
275
+ [
276
+ "("
277
+ + human_join([quote(arg) for arg in variant], final="and")
278
+ + ")"
279
+ for variant in variants
280
+ ]
281
+ )
282
+ msg = f"Missing required arguments; Expected either {variations} arguments to be given"
283
+ else:
284
+ assert len(variants) > 0
285
+
286
+ # TODO: this error message is not deterministic
287
+ missing = list(set(variants[0]) - given_params)
288
+ if len(missing) > 1:
289
+ msg = f"Missing required arguments: {human_join([quote(arg) for arg in missing])}"
290
+ else:
291
+ msg = f"Missing required argument: {quote(missing[0])}"
292
+ raise TypeError(msg)
293
+ return func(*args, **kwargs)
294
+
295
+ return wrapper # type: ignore
296
+
297
+ return inner
298
+
299
+
300
+ _K = TypeVar("_K")
301
+ _V = TypeVar("_V")
302
+
303
+
304
+ @overload
305
+ def strip_not_given(obj: None) -> None: ...
306
+
307
+
308
+ @overload
309
+ def strip_not_given(obj: Mapping[_K, _V | NotGiven]) -> dict[_K, _V]: ...
310
+
311
+
312
+ @overload
313
+ def strip_not_given(obj: object) -> object: ...
314
+
315
+
316
+ def strip_not_given(obj: object | None) -> object:
317
+ """Remove all top-level keys where their values are instances of `NotGiven`"""
318
+ if obj is None:
319
+ return None
320
+
321
+ if not is_mapping(obj):
322
+ return obj
323
+
324
+ return {key: value for key, value in obj.items() if not isinstance(value, NotGiven)}
325
+
326
+
327
+ def coerce_integer(val: str) -> int:
328
+ return int(val, base=10)
329
+
330
+
331
+ def coerce_float(val: str) -> float:
332
+ return float(val)
333
+
334
+
335
+ def coerce_boolean(val: str) -> bool:
336
+ return val == "true" or val == "1" or val == "on"
337
+
338
+
339
+ def maybe_coerce_integer(val: str | None) -> int | None:
340
+ if val is None:
341
+ return None
342
+ return coerce_integer(val)
343
+
344
+
345
+ def maybe_coerce_float(val: str | None) -> float | None:
346
+ if val is None:
347
+ return None
348
+ return coerce_float(val)
349
+
350
+
351
+ def maybe_coerce_boolean(val: str | None) -> bool | None:
352
+ if val is None:
353
+ return None
354
+ return coerce_boolean(val)
355
+
356
+
357
+ def removeprefix(string: str, prefix: str) -> str:
358
+ """Remove a prefix from a string.
359
+
360
+ Backport of `str.removeprefix` for Python < 3.9
361
+ """
362
+ if string.startswith(prefix):
363
+ return string[len(prefix) :]
364
+ return string
365
+
366
+
367
+ def removesuffix(string: str, suffix: str) -> str:
368
+ """Remove a suffix from a string.
369
+
370
+ Backport of `str.removesuffix` for Python < 3.9
371
+ """
372
+ if string.endswith(suffix):
373
+ return string[: -len(suffix)]
374
+ return string
375
+
376
+
377
+ def file_from_path(path: str) -> FileTypes:
378
+ contents = Path(path).read_bytes()
379
+ file_name = os.path.basename(path)
380
+ return (file_name, contents)
381
+
382
+
383
+ def get_async_library() -> str:
384
+ try:
385
+ return sniffio.current_async_library()
386
+ except Exception:
387
+ return "false"
388
+
389
+
390
+ def lru_cache(*, maxsize: int | None = 128) -> Callable[[CallableT], CallableT]:
391
+ """A version of functools.lru_cache that retains the type signature
392
+ for the wrapped function arguments.
393
+ """
394
+ wrapper = functools.lru_cache( # noqa: TID251
395
+ maxsize=maxsize,
396
+ )
397
+ return cast(Any, wrapper) # type: ignore[no-any-return]
398
+
399
+
400
+ def json_safe(data: object) -> object:
401
+ """Translates a mapping / sequence recursively in the same fashion
402
+ as `pydantic` v2's `model_dump(mode="json")`.
403
+ """
404
+ if is_mapping(data):
405
+ return {json_safe(key): json_safe(value) for key, value in data.items()}
406
+
407
+ if is_iterable(data) and not isinstance(data, (str, bytes, bytearray)):
408
+ return [json_safe(item) for item in data]
409
+
410
+ if isinstance(data, (datetime, date)):
411
+ return data.isoformat()
412
+
413
+ return data
414
+
415
+
416
+ def _gen_request_id():
417
+ time_str = datetime.now().strftime("%Y%m%d%H%M%S")
418
+ chars = string.ascii_letters + string.digits
419
+ rand_str = "".join(random.choice(chars) for i in range(20))
420
+ return f"{time_str}{rand_str}"
421
+
422
+
423
+ def with_sts_token(func):
424
+ def wrapper(*args, **kwargs):
425
+ _insert_sts_token(args, kwargs)
426
+ return func(*args, **kwargs)
427
+
428
+ return wrapper
429
+
430
+
431
+ def async_with_sts_token(func):
432
+ async def wrapper(*args, **kwargs):
433
+ _insert_sts_token(args, kwargs)
434
+ return await func(*args, **kwargs)
435
+
436
+ return wrapper
437
+
438
+
439
+ def _insert_sts_token(args, kwargs):
440
+ assert len(args) > 0
441
+ assert "model" in kwargs, "you need to support model"
442
+
443
+ ark_client = args[0]._client
444
+ model = kwargs.get("model", "")
445
+ if (
446
+ ark_client.api_key is None
447
+ and model
448
+ and model.startswith("ep-")
449
+ and ark_client.ak
450
+ and ark_client.sk
451
+ ):
452
+ default_auth_header = {
453
+ "Authorization": "Bearer " + ark_client._get_endpoint_sts_token(model)
454
+ }
455
+ extra_headers = (
456
+ kwargs.get("extra_headers") if kwargs.get("extra_headers") else {}
457
+ )
458
+ kwargs["extra_headers"] = {**default_auth_header, **extra_headers}
459
+ elif (
460
+ ark_client.api_key is None
461
+ and model
462
+ and model.startswith("bot-")
463
+ and ark_client.ak
464
+ and ark_client.sk
465
+ ):
466
+ default_auth_header = {
467
+ "Authorization": "Bearer " + ark_client._get_bot_sts_token(model)
468
+ }
469
+ extra_headers = (
470
+ kwargs.get("extra_headers") if kwargs.get("extra_headers") else {}
471
+ )
472
+ kwargs["extra_headers"] = {**default_auth_header, **extra_headers}
473
+
474
+
475
+ def apikey_required(func):
476
+ def wrapper(*args, **kwargs):
477
+ _assert_apikey(args, kwargs)
478
+ return func(*args, **kwargs)
479
+
480
+ return wrapper
481
+
482
+
483
+ def async_apikey_required(func):
484
+ async def wrapper(*args, **kwargs):
485
+ _assert_apikey(args, kwargs)
486
+ return await func(*args, **kwargs)
487
+
488
+ return wrapper
489
+
490
+
491
+ def _assert_apikey(args, kwargs):
492
+ assert len(args) > 0
493
+
494
+ ark_client = args[0]._client
495
+ assert (
496
+ ark_client.api_key is not None
497
+ ), "ak&sk authentication is currently not supported for this method, please use api key instead"
@@ -0,0 +1,14 @@
1
+
2
+ # Copyright (c) [2025] [OpenAI]
3
+ # Copyright (c) [2025] [ByteDance Ltd. and/or its affiliates.]
4
+ # SPDX-License-Identifier: Apache-2.0
5
+ #
6
+ # This file has been modified by [ByteDance Ltd. and/or its affiliates.] on 2025.7
7
+ #
8
+ # Original file was released under Apache License Version 2.0, with the full license text
9
+ # available at https://github.com/openai/openai-python/blob/main/LICENSE.
10
+ #
11
+ # This modified file is released under the same license.
12
+
13
+ from ._tools import pydantic_function_tool as pydantic_function_tool
14
+ from ._parsing import ResponseFormatT as ResponseFormatT
@@ -0,0 +1,22 @@
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 ._completions import (
13
+ ResponseFormatT as ResponseFormatT,
14
+ has_parseable_input as has_parseable_input,
15
+ maybe_parse_content as maybe_parse_content,
16
+ validate_input_tools as validate_input_tools,
17
+ parse_chat_completion as parse_chat_completion,
18
+ get_input_tool_by_name as get_input_tool_by_name,
19
+ solve_response_format_t as solve_response_format_t,
20
+ parse_function_tool_arguments as parse_function_tool_arguments,
21
+ type_to_response_format_param as type_to_response_format_param,
22
+ )