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,103 @@
|
|
|
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 typing import List, Union, Generic, Optional
|
|
14
|
+
from typing_extensions import Literal
|
|
15
|
+
|
|
16
|
+
from ._types import ParsedChatCompletionSnapshot
|
|
17
|
+
from ...._models import BaseModel, GenericModel
|
|
18
|
+
from ..._parsing import ResponseFormatT
|
|
19
|
+
from ....types.chat import ChatCompletionChunk, ChatCompletionTokenLogprob
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ChunkEvent(BaseModel):
|
|
23
|
+
type: Literal["chunk"]
|
|
24
|
+
|
|
25
|
+
chunk: ChatCompletionChunk
|
|
26
|
+
|
|
27
|
+
snapshot: ParsedChatCompletionSnapshot
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class ContentDeltaEvent(BaseModel):
|
|
31
|
+
"""This event is yielded for every chunk with `choice.delta.content` data."""
|
|
32
|
+
|
|
33
|
+
type: Literal["content.delta"]
|
|
34
|
+
|
|
35
|
+
delta: str
|
|
36
|
+
|
|
37
|
+
snapshot: str
|
|
38
|
+
|
|
39
|
+
parsed: Optional[object] = None
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class ContentDoneEvent(GenericModel, Generic[ResponseFormatT]):
|
|
43
|
+
type: Literal["content.done"]
|
|
44
|
+
|
|
45
|
+
content: str
|
|
46
|
+
|
|
47
|
+
parsed: Optional[ResponseFormatT] = None
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class FunctionToolCallArgumentsDeltaEvent(BaseModel):
|
|
51
|
+
type: Literal["tool_calls.function.arguments.delta"]
|
|
52
|
+
|
|
53
|
+
name: str
|
|
54
|
+
|
|
55
|
+
index: int
|
|
56
|
+
|
|
57
|
+
arguments: str
|
|
58
|
+
"""Accumulated raw JSON string"""
|
|
59
|
+
|
|
60
|
+
parsed_arguments: object
|
|
61
|
+
"""The parsed arguments so far"""
|
|
62
|
+
|
|
63
|
+
arguments_delta: str
|
|
64
|
+
"""The JSON string delta"""
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class FunctionToolCallArgumentsDoneEvent(BaseModel):
|
|
68
|
+
type: Literal["tool_calls.function.arguments.done"]
|
|
69
|
+
|
|
70
|
+
name: str
|
|
71
|
+
|
|
72
|
+
index: int
|
|
73
|
+
|
|
74
|
+
arguments: str
|
|
75
|
+
"""Accumulated raw JSON string"""
|
|
76
|
+
|
|
77
|
+
parsed_arguments: object
|
|
78
|
+
"""The parsed arguments"""
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class LogprobsContentDeltaEvent(BaseModel):
|
|
82
|
+
type: Literal["logprobs.content.delta"]
|
|
83
|
+
|
|
84
|
+
content: List[ChatCompletionTokenLogprob]
|
|
85
|
+
|
|
86
|
+
snapshot: List[ChatCompletionTokenLogprob]
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class LogprobsContentDoneEvent(BaseModel):
|
|
90
|
+
type: Literal["logprobs.content.done"]
|
|
91
|
+
|
|
92
|
+
content: List[ChatCompletionTokenLogprob]
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
ChatCompletionStreamEvent = Union[
|
|
96
|
+
ChunkEvent,
|
|
97
|
+
ContentDeltaEvent,
|
|
98
|
+
ContentDoneEvent[ResponseFormatT],
|
|
99
|
+
FunctionToolCallArgumentsDeltaEvent,
|
|
100
|
+
FunctionToolCallArgumentsDoneEvent,
|
|
101
|
+
LogprobsContentDeltaEvent,
|
|
102
|
+
LogprobsContentDoneEvent,
|
|
103
|
+
]
|
|
@@ -0,0 +1,36 @@
|
|
|
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 __future__ import annotations
|
|
14
|
+
|
|
15
|
+
from typing_extensions import TypeAlias
|
|
16
|
+
|
|
17
|
+
from ....types.chat import (
|
|
18
|
+
ParsedChoice,
|
|
19
|
+
ParsedChatCompletion,
|
|
20
|
+
ParsedChatCompletionMessage,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
ParsedChatCompletionSnapshot: TypeAlias = ParsedChatCompletion[object]
|
|
24
|
+
"""Snapshot type representing an in-progress accumulation of
|
|
25
|
+
a `ParsedChatCompletion` object.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
ParsedChatCompletionMessageSnapshot: TypeAlias = ParsedChatCompletionMessage[object]
|
|
29
|
+
"""Snapshot type representing an in-progress accumulation of
|
|
30
|
+
a `ParsedChatCompletionMessage` object.
|
|
31
|
+
|
|
32
|
+
If the content has been fully accumulated, the `.parsed` content will be
|
|
33
|
+
the `response_format` instance, otherwise it'll be the raw JSON parsed version.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
ParsedChoiceSnapshot: TypeAlias = ParsedChoice[object]
|
|
@@ -0,0 +1,134 @@
|
|
|
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 Any, List, Generic, TypeVar, Optional, cast
|
|
13
|
+
from typing_extensions import Protocol, override, runtime_checkable
|
|
14
|
+
|
|
15
|
+
from ._base_client import BasePage, PageInfo, BaseSyncPage, BaseAsyncPage
|
|
16
|
+
|
|
17
|
+
__all__ = ["SyncPage", "AsyncPage", "SyncCursorPage", "AsyncCursorPage"]
|
|
18
|
+
|
|
19
|
+
_T = TypeVar("_T")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@runtime_checkable
|
|
23
|
+
class CursorPageItem(Protocol):
|
|
24
|
+
id: Optional[str]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class SyncPage(BaseSyncPage[_T], BasePage[_T], Generic[_T]):
|
|
28
|
+
"""Note: no pagination actually occurs yet, this is for forwards-compatibility."""
|
|
29
|
+
|
|
30
|
+
data: List[_T]
|
|
31
|
+
object: str
|
|
32
|
+
|
|
33
|
+
@override
|
|
34
|
+
def _get_page_items(self) -> List[_T]:
|
|
35
|
+
data = self.data
|
|
36
|
+
if not data:
|
|
37
|
+
return []
|
|
38
|
+
return data
|
|
39
|
+
|
|
40
|
+
@override
|
|
41
|
+
def next_page_info(self) -> None:
|
|
42
|
+
"""
|
|
43
|
+
This page represents a response that isn't actually paginated at the API level
|
|
44
|
+
so there will never be a next page.
|
|
45
|
+
"""
|
|
46
|
+
return None
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class AsyncPage(BaseAsyncPage[_T], BasePage[_T], Generic[_T]):
|
|
50
|
+
"""Note: no pagination actually occurs yet, this is for forwards-compatibility."""
|
|
51
|
+
|
|
52
|
+
data: List[_T]
|
|
53
|
+
object: str
|
|
54
|
+
|
|
55
|
+
@override
|
|
56
|
+
def _get_page_items(self) -> List[_T]:
|
|
57
|
+
data = self.data
|
|
58
|
+
if not data:
|
|
59
|
+
return []
|
|
60
|
+
return data
|
|
61
|
+
|
|
62
|
+
@override
|
|
63
|
+
def next_page_info(self) -> None:
|
|
64
|
+
"""
|
|
65
|
+
This page represents a response that isn't actually paginated at the API level
|
|
66
|
+
so there will never be a next page.
|
|
67
|
+
"""
|
|
68
|
+
return None
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class SyncCursorPage(BaseSyncPage[_T], BasePage[_T], Generic[_T]):
|
|
72
|
+
data: List[_T]
|
|
73
|
+
has_more: Optional[bool] = None
|
|
74
|
+
|
|
75
|
+
@override
|
|
76
|
+
def _get_page_items(self) -> List[_T]:
|
|
77
|
+
data = self.data
|
|
78
|
+
if not data:
|
|
79
|
+
return []
|
|
80
|
+
return data
|
|
81
|
+
|
|
82
|
+
@override
|
|
83
|
+
def has_next_page(self) -> bool:
|
|
84
|
+
has_more = self.has_more
|
|
85
|
+
if has_more is not None and has_more is False:
|
|
86
|
+
return False
|
|
87
|
+
|
|
88
|
+
return super().has_next_page()
|
|
89
|
+
|
|
90
|
+
@override
|
|
91
|
+
def next_page_info(self) -> Optional[PageInfo]:
|
|
92
|
+
data = self.data
|
|
93
|
+
if not data:
|
|
94
|
+
return None
|
|
95
|
+
|
|
96
|
+
item = cast(Any, data[-1])
|
|
97
|
+
if not isinstance(item, CursorPageItem) or item.id is None:
|
|
98
|
+
# TODO emit warning log
|
|
99
|
+
return None
|
|
100
|
+
|
|
101
|
+
return PageInfo(params={"after": item.id})
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class AsyncCursorPage(BaseAsyncPage[_T], BasePage[_T], Generic[_T]):
|
|
105
|
+
data: List[_T]
|
|
106
|
+
has_more: Optional[bool] = None
|
|
107
|
+
|
|
108
|
+
@override
|
|
109
|
+
def _get_page_items(self) -> List[_T]:
|
|
110
|
+
data = self.data
|
|
111
|
+
if not data:
|
|
112
|
+
return []
|
|
113
|
+
return data
|
|
114
|
+
|
|
115
|
+
@override
|
|
116
|
+
def has_next_page(self) -> bool:
|
|
117
|
+
has_more = self.has_more
|
|
118
|
+
if has_more is not None and has_more is False:
|
|
119
|
+
return False
|
|
120
|
+
|
|
121
|
+
return super().has_next_page()
|
|
122
|
+
|
|
123
|
+
@override
|
|
124
|
+
def next_page_info(self) -> Optional[PageInfo]:
|
|
125
|
+
data = self.data
|
|
126
|
+
if not data:
|
|
127
|
+
return None
|
|
128
|
+
|
|
129
|
+
item = cast(Any, data[-1])
|
|
130
|
+
if not isinstance(item, CursorPageItem) or item.id is None:
|
|
131
|
+
# TODO emit warning log
|
|
132
|
+
return None
|
|
133
|
+
|
|
134
|
+
return PageInfo(params={"after": item.id})
|
|
@@ -0,0 +1,48 @@
|
|
|
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 .chat import Chat, AsyncChat
|
|
13
|
+
from .embeddings import Embeddings, AsyncEmbeddings
|
|
14
|
+
from .context import Context, AsyncContext
|
|
15
|
+
from .multimodal_embeddings import MultimodalEmbeddings, AsyncMultimodalEmbeddings
|
|
16
|
+
from .content_generation import ContentGeneration, AsyncContentGeneration
|
|
17
|
+
from .images import Images, AsyncImages
|
|
18
|
+
from .batch_chat import BatchChat, AsyncBatchChat
|
|
19
|
+
from .batch import Batch, AsyncBatch
|
|
20
|
+
from .responses import Responses, AsyncResponses, InputItems, AsyncInputItems
|
|
21
|
+
from .files import Files, AsyncFiles
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
"Chat",
|
|
26
|
+
"AsyncChat",
|
|
27
|
+
"Embeddings",
|
|
28
|
+
"AsyncEmbeddings",
|
|
29
|
+
"Context",
|
|
30
|
+
"AsyncContext",
|
|
31
|
+
"MultimodalEmbeddings",
|
|
32
|
+
"AsyncMultimodalEmbeddings",
|
|
33
|
+
"ContentGeneration",
|
|
34
|
+
"AsyncContentGeneration",
|
|
35
|
+
"Images",
|
|
36
|
+
"AsyncImages",
|
|
37
|
+
"BatchChat",
|
|
38
|
+
"AsyncBatchChat",
|
|
39
|
+
"Batch",
|
|
40
|
+
"AsyncBatch",
|
|
41
|
+
"AsyncBatchChat",
|
|
42
|
+
"AsyncResponses",
|
|
43
|
+
"Responses",
|
|
44
|
+
"InputItems",
|
|
45
|
+
"AsyncInputItems",
|
|
46
|
+
"Files",
|
|
47
|
+
"AsyncFiles",
|
|
48
|
+
]
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import logging
|
|
3
|
+
import time
|
|
4
|
+
from datetime import datetime, timedelta
|
|
5
|
+
from random import random
|
|
6
|
+
from typing import Any, Awaitable, Callable, Optional, TypeVar
|
|
7
|
+
|
|
8
|
+
import httpx
|
|
9
|
+
|
|
10
|
+
from ..._constants import INITIAL_RETRY_DELAY, MAX_RETRY_DELAY
|
|
11
|
+
from ..._exceptions import ArkAPIConnectionError, ArkAPIStatusError, ArkAPITimeoutError
|
|
12
|
+
from ..._utils._model_breaker import ModelBreaker
|
|
13
|
+
|
|
14
|
+
log: logging.Logger = logging.getLogger(__name__)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _calculate_retry_timeout(retry_times: int) -> float:
|
|
18
|
+
nbRetries = min(retry_times, MAX_RETRY_DELAY / INITIAL_RETRY_DELAY)
|
|
19
|
+
sleep_seconds = min(INITIAL_RETRY_DELAY * pow(2, nbRetries), MAX_RETRY_DELAY)
|
|
20
|
+
# Apply some jitter, plus-or-minus half a second.
|
|
21
|
+
jitter = 1 - 0.25 * random()
|
|
22
|
+
timeout = sleep_seconds * jitter
|
|
23
|
+
return timeout if timeout >= 0 else 0
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _get_retry_after(response: httpx.Response) -> Optional[int]:
|
|
27
|
+
retry_after = response.headers.get("Retry-After")
|
|
28
|
+
if retry_after is not None:
|
|
29
|
+
if retry_after.isdigit():
|
|
30
|
+
return int(retry_after)
|
|
31
|
+
return None
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _should_retry(response: httpx.Response) -> bool:
|
|
35
|
+
# Retry on request timeouts.
|
|
36
|
+
if response.status_code == 408:
|
|
37
|
+
return True
|
|
38
|
+
|
|
39
|
+
# Retry on lock timeouts.
|
|
40
|
+
if response.status_code == 409:
|
|
41
|
+
return True
|
|
42
|
+
|
|
43
|
+
# Retry on rate limits.
|
|
44
|
+
if response.status_code == 429:
|
|
45
|
+
return True
|
|
46
|
+
|
|
47
|
+
# Retry internal errors.
|
|
48
|
+
if response.status_code >= 500:
|
|
49
|
+
return True
|
|
50
|
+
|
|
51
|
+
return False
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def get_request_last_time(
|
|
55
|
+
client: httpx.Client, timeout: Optional[Any] = None
|
|
56
|
+
) -> datetime:
|
|
57
|
+
if timeout is None:
|
|
58
|
+
timeout = client.timeout
|
|
59
|
+
timeoutSeconds = 0
|
|
60
|
+
if isinstance(timeout, httpx.Timeout):
|
|
61
|
+
timeoutSeconds = timeout.read
|
|
62
|
+
elif isinstance(timeout, float):
|
|
63
|
+
timeoutSeconds = timeout
|
|
64
|
+
elif isinstance(timeout, int):
|
|
65
|
+
timeoutSeconds = timeout
|
|
66
|
+
else:
|
|
67
|
+
raise TypeError("timeout type {} is not supported".format(type(timeout)))
|
|
68
|
+
return datetime.now() + timedelta(seconds=timeoutSeconds)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
R = TypeVar("R")
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def with_batch_retry(
|
|
75
|
+
deadline: datetime,
|
|
76
|
+
breaker: ModelBreaker,
|
|
77
|
+
func: Callable[..., R],
|
|
78
|
+
*args,
|
|
79
|
+
**kwargs,
|
|
80
|
+
) -> R:
|
|
81
|
+
retry_times = 0
|
|
82
|
+
while True:
|
|
83
|
+
breaker.wait()
|
|
84
|
+
if datetime.now() > deadline:
|
|
85
|
+
raise ArkAPITimeoutError(None, None)
|
|
86
|
+
try:
|
|
87
|
+
return func(*args, **kwargs)
|
|
88
|
+
except ArkAPIConnectionError:
|
|
89
|
+
waitTime = _calculate_retry_timeout(retry_times)
|
|
90
|
+
log.debug(
|
|
91
|
+
"Retry due to connection error, wait time: %is, retry times: %i",
|
|
92
|
+
waitTime,
|
|
93
|
+
retry_times,
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
if datetime.now() + timedelta(seconds=waitTime) > deadline:
|
|
97
|
+
raise ArkAPITimeoutError(None, None)
|
|
98
|
+
time.sleep(waitTime)
|
|
99
|
+
except ArkAPIStatusError as err:
|
|
100
|
+
retry_after = _get_retry_after(err.response)
|
|
101
|
+
log.debug(
|
|
102
|
+
"Got status error, retry after: %is, retry times: %i, error: %s",
|
|
103
|
+
retry_after,
|
|
104
|
+
retry_times,
|
|
105
|
+
err,
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
if retry_after is not None and retry_after > 0:
|
|
109
|
+
breaker.reset(retry_after)
|
|
110
|
+
if not _should_retry(err.response):
|
|
111
|
+
raise err
|
|
112
|
+
|
|
113
|
+
retry_times = retry_times + 1
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
async def async_with_batch_retry(
|
|
117
|
+
deadline: datetime,
|
|
118
|
+
breaker: ModelBreaker,
|
|
119
|
+
func: Callable[..., Awaitable[R]],
|
|
120
|
+
*args,
|
|
121
|
+
**kwargs,
|
|
122
|
+
) -> R:
|
|
123
|
+
retry_times = 0
|
|
124
|
+
while True:
|
|
125
|
+
await breaker.asyncwait()
|
|
126
|
+
if datetime.now() > deadline:
|
|
127
|
+
raise ArkAPITimeoutError(None, None)
|
|
128
|
+
try:
|
|
129
|
+
return await func(*args, **kwargs)
|
|
130
|
+
except ArkAPIConnectionError:
|
|
131
|
+
waitTime = _calculate_retry_timeout(retry_times)
|
|
132
|
+
log.debug(
|
|
133
|
+
"Retry due to connection error, wait time: %is, retry times: %i",
|
|
134
|
+
waitTime,
|
|
135
|
+
retry_times,
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
if datetime.now() + timedelta(seconds=waitTime) > deadline:
|
|
139
|
+
raise ArkAPITimeoutError(None, None)
|
|
140
|
+
await asyncio.sleep(waitTime)
|
|
141
|
+
except ArkAPIStatusError as err:
|
|
142
|
+
retry_after = _get_retry_after(err.response)
|
|
143
|
+
log.debug(
|
|
144
|
+
"Got status error, retry after: %is, retry times: %i, error: %s",
|
|
145
|
+
retry_after,
|
|
146
|
+
retry_times,
|
|
147
|
+
err,
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
if retry_after is not None and retry_after > 0:
|
|
151
|
+
breaker.reset(retry_after)
|
|
152
|
+
if not _should_retry(err.response):
|
|
153
|
+
raise err
|
|
154
|
+
|
|
155
|
+
retry_times = retry_times + 1
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from ..._compat import cached_property
|
|
4
|
+
from ..._resource import AsyncAPIResource, SyncAPIResource
|
|
5
|
+
from .chat import AsyncChat, Chat
|
|
6
|
+
from .embeddings import AsyncEmbeddings, Embeddings
|
|
7
|
+
from .multimodal_embeddings import AsyncMultimodalEmbeddings, MultimodalEmbeddings
|
|
8
|
+
|
|
9
|
+
__all__ = ["Batch", "AsyncBatch"]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Batch(SyncAPIResource):
|
|
13
|
+
@cached_property
|
|
14
|
+
def chat(self) -> Chat:
|
|
15
|
+
return Chat(self._client)
|
|
16
|
+
|
|
17
|
+
@cached_property
|
|
18
|
+
def embeddings(self) -> Embeddings:
|
|
19
|
+
return Embeddings(self._client)
|
|
20
|
+
|
|
21
|
+
@cached_property
|
|
22
|
+
def multimodal_embeddings(self) -> MultimodalEmbeddings:
|
|
23
|
+
return MultimodalEmbeddings(self._client)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class AsyncBatch(AsyncAPIResource):
|
|
27
|
+
@cached_property
|
|
28
|
+
def chat(self) -> AsyncChat:
|
|
29
|
+
return AsyncChat(self._client)
|
|
30
|
+
|
|
31
|
+
@cached_property
|
|
32
|
+
def embeddings(self) -> AsyncEmbeddings:
|
|
33
|
+
return AsyncEmbeddings(self._client)
|
|
34
|
+
|
|
35
|
+
@cached_property
|
|
36
|
+
def multimodal_embeddings(self) -> AsyncMultimodalEmbeddings:
|
|
37
|
+
return AsyncMultimodalEmbeddings(self._client)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from ...._compat import cached_property
|
|
4
|
+
from ...._resource import AsyncAPIResource, SyncAPIResource
|
|
5
|
+
from .completions import AsyncCompletions, Completions
|
|
6
|
+
|
|
7
|
+
__all__ = ["Chat", "AsyncChat"]
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Chat(SyncAPIResource):
|
|
11
|
+
@cached_property
|
|
12
|
+
def completions(self) -> Completions:
|
|
13
|
+
return Completions(self._client)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class AsyncChat(AsyncAPIResource):
|
|
17
|
+
@cached_property
|
|
18
|
+
def completions(self) -> AsyncCompletions:
|
|
19
|
+
return AsyncCompletions(self._client)
|