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,592 @@
|
|
|
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
|
+
import datetime
|
|
14
|
+
import time
|
|
15
|
+
from typing import Mapping, cast
|
|
16
|
+
from typing_extensions import Literal
|
|
17
|
+
|
|
18
|
+
import httpx
|
|
19
|
+
|
|
20
|
+
from .. import _legacy_response
|
|
21
|
+
from ..types import FilePurpose, PreprocessConfigs, file_list_params, file_create_params
|
|
22
|
+
from .._types import Body, Query, Headers, FileTypes
|
|
23
|
+
from .._utils import (
|
|
24
|
+
extract_files,
|
|
25
|
+
maybe_transform,
|
|
26
|
+
deepcopy_minimal,
|
|
27
|
+
async_maybe_transform,
|
|
28
|
+
)
|
|
29
|
+
from .._compat import cached_property
|
|
30
|
+
from .._resource import SyncAPIResource, AsyncAPIResource
|
|
31
|
+
from .._response import (
|
|
32
|
+
to_streamed_response_wrapper,
|
|
33
|
+
async_to_streamed_response_wrapper,
|
|
34
|
+
)
|
|
35
|
+
from ..pagination import SyncCursorPage, AsyncCursorPage
|
|
36
|
+
from .._base_client import AsyncPaginator, make_request_options
|
|
37
|
+
from ..types.file_object import FileObject
|
|
38
|
+
from ..types.file_deleted import FileDeleted
|
|
39
|
+
|
|
40
|
+
__all__ = ["Files", "AsyncFiles"]
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class Files(SyncAPIResource):
|
|
44
|
+
@cached_property
|
|
45
|
+
def with_raw_response(self) -> FilesWithRawResponse:
|
|
46
|
+
"""
|
|
47
|
+
This property can be used as a prefix for any HTTP method call to return
|
|
48
|
+
the raw response object instead of the parsed content.
|
|
49
|
+
|
|
50
|
+
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
|
|
51
|
+
"""
|
|
52
|
+
return FilesWithRawResponse(self)
|
|
53
|
+
|
|
54
|
+
@cached_property
|
|
55
|
+
def with_streaming_response(self) -> FilesWithStreamingResponse:
|
|
56
|
+
"""
|
|
57
|
+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
|
58
|
+
|
|
59
|
+
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
|
|
60
|
+
"""
|
|
61
|
+
return FilesWithStreamingResponse(self)
|
|
62
|
+
|
|
63
|
+
def create(
|
|
64
|
+
self,
|
|
65
|
+
*,
|
|
66
|
+
file: FileTypes,
|
|
67
|
+
purpose: FilePurpose,
|
|
68
|
+
expires_at: datetime.datetime | int | None = None,
|
|
69
|
+
preprocess_configs: PreprocessConfigs | None = None,
|
|
70
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
71
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
72
|
+
extra_headers: Headers | None = None,
|
|
73
|
+
extra_query: Query | None = None,
|
|
74
|
+
extra_body: Body | None = None,
|
|
75
|
+
timeout: float | httpx.Timeout | None = None,
|
|
76
|
+
) -> FileObject:
|
|
77
|
+
"""Upload a file that can be used across various endpoints.
|
|
78
|
+
|
|
79
|
+
Individual files can be up to 512 MB.
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
file: The File object (not file name) to be uploaded.
|
|
83
|
+
|
|
84
|
+
purpose: The intended purpose of the uploaded file. Only `user_data` is supported.
|
|
85
|
+
|
|
86
|
+
expires_at: The expiration time for a file in Unix timestamp format. By default, files expires after 7 days.
|
|
87
|
+
|
|
88
|
+
extra_headers: Send extra headers
|
|
89
|
+
|
|
90
|
+
extra_query: Add additional query parameters to the request
|
|
91
|
+
|
|
92
|
+
extra_body: Add additional JSON properties to the request
|
|
93
|
+
|
|
94
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
95
|
+
"""
|
|
96
|
+
body = deepcopy_minimal(
|
|
97
|
+
{
|
|
98
|
+
"file": file,
|
|
99
|
+
"purpose": purpose,
|
|
100
|
+
"expires_at": expires_at,
|
|
101
|
+
"preprocess_configs": preprocess_configs,
|
|
102
|
+
}
|
|
103
|
+
)
|
|
104
|
+
files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
|
|
105
|
+
# It should be noted that the actual Content-Type header that will be
|
|
106
|
+
# sent to the server will contain a `boundary` parameter, e.g.
|
|
107
|
+
# multipart/form-data; boundary=---abc--
|
|
108
|
+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
|
|
109
|
+
return self._post(
|
|
110
|
+
"/files",
|
|
111
|
+
body=maybe_transform(body, file_create_params.FileCreateParams),
|
|
112
|
+
files=files,
|
|
113
|
+
options=make_request_options(
|
|
114
|
+
extra_headers=extra_headers,
|
|
115
|
+
extra_query=extra_query,
|
|
116
|
+
extra_body=extra_body,
|
|
117
|
+
timeout=timeout,
|
|
118
|
+
),
|
|
119
|
+
cast_to=FileObject,
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
def retrieve(
|
|
123
|
+
self,
|
|
124
|
+
file_id: str,
|
|
125
|
+
*,
|
|
126
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
127
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
128
|
+
extra_headers: Headers | None = None,
|
|
129
|
+
extra_query: Query | None = None,
|
|
130
|
+
extra_body: Body | None = None,
|
|
131
|
+
timeout: float | httpx.Timeout | None = None,
|
|
132
|
+
) -> FileObject:
|
|
133
|
+
"""
|
|
134
|
+
Returns information about a specific file.
|
|
135
|
+
|
|
136
|
+
Args:
|
|
137
|
+
file_id: The ID of the file to use for this request.
|
|
138
|
+
|
|
139
|
+
extra_headers: Send extra headers
|
|
140
|
+
|
|
141
|
+
extra_query: Add additional query parameters to the request
|
|
142
|
+
|
|
143
|
+
extra_body: Add additional JSON properties to the request
|
|
144
|
+
|
|
145
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
146
|
+
"""
|
|
147
|
+
if not file_id:
|
|
148
|
+
raise ValueError(
|
|
149
|
+
f"Expected a non-empty value for `file_id` but received {file_id!r}"
|
|
150
|
+
)
|
|
151
|
+
return self._get(
|
|
152
|
+
f"/files/{file_id}",
|
|
153
|
+
options=make_request_options(
|
|
154
|
+
extra_headers=extra_headers,
|
|
155
|
+
extra_query=extra_query,
|
|
156
|
+
extra_body=extra_body,
|
|
157
|
+
timeout=timeout,
|
|
158
|
+
),
|
|
159
|
+
cast_to=FileObject,
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
def list(
|
|
163
|
+
self,
|
|
164
|
+
*,
|
|
165
|
+
after: str | None = None,
|
|
166
|
+
limit: int | None = None,
|
|
167
|
+
order: Literal["asc", "desc"] | None = None,
|
|
168
|
+
purpose: FilePurpose | None = None,
|
|
169
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
170
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
171
|
+
extra_headers: Headers | None = None,
|
|
172
|
+
extra_query: Query | None = None,
|
|
173
|
+
extra_body: Body | None = None,
|
|
174
|
+
timeout: float | httpx.Timeout | None = None,
|
|
175
|
+
) -> SyncCursorPage[FileObject]:
|
|
176
|
+
"""Returns a list of files.
|
|
177
|
+
|
|
178
|
+
Args:
|
|
179
|
+
after: A cursor for use in pagination.
|
|
180
|
+
|
|
181
|
+
`after` is an object ID that defines your place
|
|
182
|
+
in the list. For instance, if you make a list request and receive 100 objects,
|
|
183
|
+
ending with obj_foo, your subsequent call can include after=obj_foo in order to
|
|
184
|
+
fetch the next page of the list.
|
|
185
|
+
|
|
186
|
+
limit: A limit on the number of objects to be returned. Limit can range between 1 and
|
|
187
|
+
1000, and the default is 100
|
|
188
|
+
|
|
189
|
+
order: Sort order by the `created_at` timestamp of the objects. `asc` for ascending
|
|
190
|
+
order and `desc` for descending order.
|
|
191
|
+
|
|
192
|
+
purpose: Only return files with the given purpose.
|
|
193
|
+
|
|
194
|
+
extra_headers: Send extra headers
|
|
195
|
+
|
|
196
|
+
extra_query: Add additional query parameters to the request
|
|
197
|
+
|
|
198
|
+
extra_body: Add additional JSON properties to the request
|
|
199
|
+
|
|
200
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
201
|
+
"""
|
|
202
|
+
return self._get_api_list(
|
|
203
|
+
"/files",
|
|
204
|
+
page=SyncCursorPage[FileObject],
|
|
205
|
+
options=make_request_options(
|
|
206
|
+
extra_headers=extra_headers,
|
|
207
|
+
extra_query=extra_query,
|
|
208
|
+
extra_body=extra_body,
|
|
209
|
+
timeout=timeout,
|
|
210
|
+
query=maybe_transform(
|
|
211
|
+
{
|
|
212
|
+
"after": after,
|
|
213
|
+
"limit": limit,
|
|
214
|
+
"order": order,
|
|
215
|
+
"purpose": purpose,
|
|
216
|
+
},
|
|
217
|
+
file_list_params.FileListParams,
|
|
218
|
+
),
|
|
219
|
+
),
|
|
220
|
+
model=FileObject,
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
def delete(
|
|
224
|
+
self,
|
|
225
|
+
file_id: str,
|
|
226
|
+
*,
|
|
227
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
228
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
229
|
+
extra_headers: Headers | None = None,
|
|
230
|
+
extra_query: Query | None = None,
|
|
231
|
+
extra_body: Body | None = None,
|
|
232
|
+
timeout: float | httpx.Timeout | None = None,
|
|
233
|
+
) -> FileDeleted:
|
|
234
|
+
"""
|
|
235
|
+
Delete a file and remove it from all vector stores.
|
|
236
|
+
|
|
237
|
+
Args:
|
|
238
|
+
file_id: The ID of the file to use for this request.
|
|
239
|
+
|
|
240
|
+
extra_headers: Send extra headers
|
|
241
|
+
|
|
242
|
+
extra_query: Add additional query parameters to the request
|
|
243
|
+
|
|
244
|
+
extra_body: Add additional JSON properties to the request
|
|
245
|
+
|
|
246
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
247
|
+
"""
|
|
248
|
+
if not file_id:
|
|
249
|
+
raise ValueError(
|
|
250
|
+
f"Expected a non-empty value for `file_id` but received {file_id!r}"
|
|
251
|
+
)
|
|
252
|
+
return self._delete(
|
|
253
|
+
f"/files/{file_id}",
|
|
254
|
+
options=make_request_options(
|
|
255
|
+
extra_headers=extra_headers,
|
|
256
|
+
extra_query=extra_query,
|
|
257
|
+
extra_body=extra_body,
|
|
258
|
+
timeout=timeout,
|
|
259
|
+
),
|
|
260
|
+
cast_to=FileDeleted,
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
def wait_for_processing(
|
|
264
|
+
self,
|
|
265
|
+
id: str,
|
|
266
|
+
*,
|
|
267
|
+
poll_interval: float = 3.0,
|
|
268
|
+
max_wait_seconds: float = 10 * 60,
|
|
269
|
+
) -> FileObject:
|
|
270
|
+
"""Waits for the given file to be processed, default timeout is 10 mins."""
|
|
271
|
+
TERMINAL_STATES = {"active", "failed"}
|
|
272
|
+
|
|
273
|
+
start = time.time()
|
|
274
|
+
file = self.retrieve(id)
|
|
275
|
+
while file.status not in TERMINAL_STATES:
|
|
276
|
+
self._sleep(poll_interval)
|
|
277
|
+
|
|
278
|
+
file = self.retrieve(id)
|
|
279
|
+
if time.time() - start > max_wait_seconds:
|
|
280
|
+
raise RuntimeError(
|
|
281
|
+
f"Giving up on waiting for file {id} to finish processing after {max_wait_seconds} seconds."
|
|
282
|
+
)
|
|
283
|
+
|
|
284
|
+
return file
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
class AsyncFiles(AsyncAPIResource):
|
|
288
|
+
@cached_property
|
|
289
|
+
def with_raw_response(self) -> AsyncFilesWithRawResponse:
|
|
290
|
+
"""
|
|
291
|
+
This property can be used as a prefix for any HTTP method call to return
|
|
292
|
+
the raw response object instead of the parsed content.
|
|
293
|
+
"""
|
|
294
|
+
return AsyncFilesWithRawResponse(self)
|
|
295
|
+
|
|
296
|
+
@cached_property
|
|
297
|
+
def with_streaming_response(self) -> AsyncFilesWithStreamingResponse:
|
|
298
|
+
"""
|
|
299
|
+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
|
300
|
+
"""
|
|
301
|
+
return AsyncFilesWithStreamingResponse(self)
|
|
302
|
+
|
|
303
|
+
async def create(
|
|
304
|
+
self,
|
|
305
|
+
*,
|
|
306
|
+
file: FileTypes,
|
|
307
|
+
purpose: FilePurpose,
|
|
308
|
+
expire_at: int | None = None,
|
|
309
|
+
preprocess_configs: PreprocessConfigs | None = None,
|
|
310
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
311
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
312
|
+
extra_headers: Headers | None = None,
|
|
313
|
+
extra_query: Query | None = None,
|
|
314
|
+
extra_body: Body | None = None,
|
|
315
|
+
timeout: float | httpx.Timeout | None = None,
|
|
316
|
+
) -> FileObject:
|
|
317
|
+
"""Upload a file that can be used across various endpoints.
|
|
318
|
+
|
|
319
|
+
Individual files can be up to 512 MB.
|
|
320
|
+
|
|
321
|
+
Args:
|
|
322
|
+
file: The File object (not file name) to be uploaded.
|
|
323
|
+
|
|
324
|
+
purpose: The intended purpose of the uploaded file.
|
|
325
|
+
|
|
326
|
+
expire_at: The Unix timestamp in seconds after which the file will be deleted. Defaults to 7 days.
|
|
327
|
+
|
|
328
|
+
extra_headers: Send extra headers
|
|
329
|
+
|
|
330
|
+
extra_query: Add additional query parameters to the request
|
|
331
|
+
|
|
332
|
+
extra_body: Add additional JSON properties to the request
|
|
333
|
+
|
|
334
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
335
|
+
"""
|
|
336
|
+
body = deepcopy_minimal(
|
|
337
|
+
{
|
|
338
|
+
"file": file,
|
|
339
|
+
"purpose": purpose,
|
|
340
|
+
"expire_at": expire_at,
|
|
341
|
+
"preprocess_configs": preprocess_configs,
|
|
342
|
+
}
|
|
343
|
+
)
|
|
344
|
+
files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
|
|
345
|
+
# It should be noted that the actual Content-Type header that will be
|
|
346
|
+
# sent to the server will contain a `boundary` parameter, e.g.
|
|
347
|
+
# multipart/form-data; boundary=---abc--
|
|
348
|
+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
|
|
349
|
+
return await self._post(
|
|
350
|
+
"/files",
|
|
351
|
+
body=await async_maybe_transform(body, file_create_params.FileCreateParams),
|
|
352
|
+
files=files,
|
|
353
|
+
options=make_request_options(
|
|
354
|
+
extra_headers=extra_headers,
|
|
355
|
+
extra_query=extra_query,
|
|
356
|
+
extra_body=extra_body,
|
|
357
|
+
timeout=timeout,
|
|
358
|
+
),
|
|
359
|
+
cast_to=FileObject,
|
|
360
|
+
)
|
|
361
|
+
|
|
362
|
+
async def retrieve(
|
|
363
|
+
self,
|
|
364
|
+
file_id: str,
|
|
365
|
+
*,
|
|
366
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
367
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
368
|
+
extra_headers: Headers | None = None,
|
|
369
|
+
extra_query: Query | None = None,
|
|
370
|
+
extra_body: Body | None = None,
|
|
371
|
+
timeout: float | httpx.Timeout | None = None,
|
|
372
|
+
) -> FileObject:
|
|
373
|
+
"""
|
|
374
|
+
Returns information about a specific file.
|
|
375
|
+
|
|
376
|
+
Args:
|
|
377
|
+
extra_headers: Send extra headers
|
|
378
|
+
|
|
379
|
+
extra_query: Add additional query parameters to the request
|
|
380
|
+
|
|
381
|
+
extra_body: Add additional JSON properties to the request
|
|
382
|
+
|
|
383
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
384
|
+
"""
|
|
385
|
+
if not file_id:
|
|
386
|
+
raise ValueError(
|
|
387
|
+
f"Expected a non-empty value for `file_id` but received {file_id!r}"
|
|
388
|
+
)
|
|
389
|
+
return await self._get(
|
|
390
|
+
f"/files/{file_id}",
|
|
391
|
+
options=make_request_options(
|
|
392
|
+
extra_headers=extra_headers,
|
|
393
|
+
extra_query=extra_query,
|
|
394
|
+
extra_body=extra_body,
|
|
395
|
+
timeout=timeout,
|
|
396
|
+
),
|
|
397
|
+
cast_to=FileObject,
|
|
398
|
+
)
|
|
399
|
+
|
|
400
|
+
def list(
|
|
401
|
+
self,
|
|
402
|
+
*,
|
|
403
|
+
after: str | None = None,
|
|
404
|
+
limit: int | None = None,
|
|
405
|
+
order: Literal["asc", "desc"] | None = None,
|
|
406
|
+
purpose: FilePurpose | None = None,
|
|
407
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
408
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
409
|
+
extra_headers: Headers | None = None,
|
|
410
|
+
extra_query: Query | None = None,
|
|
411
|
+
extra_body: Body | None = None,
|
|
412
|
+
timeout: float | httpx.Timeout | None = None,
|
|
413
|
+
) -> AsyncPaginator[FileObject, AsyncCursorPage[FileObject]]:
|
|
414
|
+
"""Returns a list of files.
|
|
415
|
+
|
|
416
|
+
Args:
|
|
417
|
+
after: A cursor for use in pagination.
|
|
418
|
+
|
|
419
|
+
`after` is an object ID that defines your place
|
|
420
|
+
in the list. For instance, if you make a list request and receive 100 objects,
|
|
421
|
+
ending with obj_foo, your subsequent call can include after=obj_foo in order to
|
|
422
|
+
fetch the next page of the list.
|
|
423
|
+
|
|
424
|
+
limit: A limit on the number of objects to be returned. Limit can range between 1 and
|
|
425
|
+
10,000, and the default is 10,000.
|
|
426
|
+
|
|
427
|
+
order: Sort order by the `created_at` timestamp of the objects. `asc` for ascending
|
|
428
|
+
order and `desc` for descending order.
|
|
429
|
+
|
|
430
|
+
purpose: Only return files with the given purpose.
|
|
431
|
+
|
|
432
|
+
extra_headers: Send extra headers
|
|
433
|
+
|
|
434
|
+
extra_query: Add additional query parameters to the request
|
|
435
|
+
|
|
436
|
+
extra_body: Add additional JSON properties to the request
|
|
437
|
+
|
|
438
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
439
|
+
"""
|
|
440
|
+
return self._get_api_list(
|
|
441
|
+
"/files",
|
|
442
|
+
page=AsyncCursorPage[FileObject],
|
|
443
|
+
options=make_request_options(
|
|
444
|
+
extra_headers=extra_headers,
|
|
445
|
+
extra_query=extra_query,
|
|
446
|
+
extra_body=extra_body,
|
|
447
|
+
timeout=timeout,
|
|
448
|
+
query=maybe_transform(
|
|
449
|
+
{
|
|
450
|
+
"after": after,
|
|
451
|
+
"limit": limit,
|
|
452
|
+
"order": order,
|
|
453
|
+
"purpose": purpose,
|
|
454
|
+
},
|
|
455
|
+
file_list_params.FileListParams,
|
|
456
|
+
),
|
|
457
|
+
),
|
|
458
|
+
model=FileObject,
|
|
459
|
+
)
|
|
460
|
+
|
|
461
|
+
async def delete(
|
|
462
|
+
self,
|
|
463
|
+
file_id: str,
|
|
464
|
+
*,
|
|
465
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
466
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
467
|
+
extra_headers: Headers | None = None,
|
|
468
|
+
extra_query: Query | None = None,
|
|
469
|
+
extra_body: Body | None = None,
|
|
470
|
+
timeout: float | httpx.Timeout | None = None,
|
|
471
|
+
) -> FileDeleted:
|
|
472
|
+
"""
|
|
473
|
+
Delete a file and remove it from all vector stores.
|
|
474
|
+
|
|
475
|
+
Args:
|
|
476
|
+
extra_headers: Send extra headers
|
|
477
|
+
|
|
478
|
+
extra_query: Add additional query parameters to the request
|
|
479
|
+
|
|
480
|
+
extra_body: Add additional JSON properties to the request
|
|
481
|
+
|
|
482
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
483
|
+
"""
|
|
484
|
+
if not file_id:
|
|
485
|
+
raise ValueError(
|
|
486
|
+
f"Expected a non-empty value for `file_id` but received {file_id!r}"
|
|
487
|
+
)
|
|
488
|
+
return await self._delete(
|
|
489
|
+
f"/files/{file_id}",
|
|
490
|
+
options=make_request_options(
|
|
491
|
+
extra_headers=extra_headers,
|
|
492
|
+
extra_query=extra_query,
|
|
493
|
+
extra_body=extra_body,
|
|
494
|
+
timeout=timeout,
|
|
495
|
+
),
|
|
496
|
+
cast_to=FileDeleted,
|
|
497
|
+
)
|
|
498
|
+
|
|
499
|
+
async def wait_for_processing(
|
|
500
|
+
self,
|
|
501
|
+
id: str,
|
|
502
|
+
*,
|
|
503
|
+
poll_interval: float = 3.0,
|
|
504
|
+
max_wait_seconds: float = 10 * 60,
|
|
505
|
+
) -> FileObject:
|
|
506
|
+
"""Waits for the given file to be processed, default timeout is 10 mins."""
|
|
507
|
+
TERMINAL_STATES = {"active", "failed"}
|
|
508
|
+
|
|
509
|
+
start = time.time()
|
|
510
|
+
file = await self.retrieve(id)
|
|
511
|
+
while file.status not in TERMINAL_STATES:
|
|
512
|
+
await self._sleep(poll_interval)
|
|
513
|
+
|
|
514
|
+
file = await self.retrieve(id)
|
|
515
|
+
if time.time() - start > max_wait_seconds:
|
|
516
|
+
raise RuntimeError(
|
|
517
|
+
f"Giving up on waiting for file {id} to finish processing after {max_wait_seconds} seconds."
|
|
518
|
+
)
|
|
519
|
+
|
|
520
|
+
return file
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
class FilesWithRawResponse:
|
|
524
|
+
def __init__(self, files: Files) -> None:
|
|
525
|
+
self._files = files
|
|
526
|
+
|
|
527
|
+
self.create = _legacy_response.to_raw_response_wrapper(
|
|
528
|
+
files.create,
|
|
529
|
+
)
|
|
530
|
+
self.retrieve = _legacy_response.to_raw_response_wrapper(
|
|
531
|
+
files.retrieve,
|
|
532
|
+
)
|
|
533
|
+
self.list = _legacy_response.to_raw_response_wrapper(
|
|
534
|
+
files.list,
|
|
535
|
+
)
|
|
536
|
+
self.delete = _legacy_response.to_raw_response_wrapper(
|
|
537
|
+
files.delete,
|
|
538
|
+
)
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
class AsyncFilesWithRawResponse:
|
|
542
|
+
def __init__(self, files: AsyncFiles) -> None:
|
|
543
|
+
self._files = files
|
|
544
|
+
|
|
545
|
+
self.create = _legacy_response.async_to_raw_response_wrapper(
|
|
546
|
+
files.create,
|
|
547
|
+
)
|
|
548
|
+
self.retrieve = _legacy_response.async_to_raw_response_wrapper(
|
|
549
|
+
files.retrieve,
|
|
550
|
+
)
|
|
551
|
+
self.list = _legacy_response.async_to_raw_response_wrapper(
|
|
552
|
+
files.list,
|
|
553
|
+
)
|
|
554
|
+
self.delete = _legacy_response.async_to_raw_response_wrapper(
|
|
555
|
+
files.delete,
|
|
556
|
+
)
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
class FilesWithStreamingResponse:
|
|
560
|
+
def __init__(self, files: Files) -> None:
|
|
561
|
+
self._files = files
|
|
562
|
+
|
|
563
|
+
self.create = to_streamed_response_wrapper(
|
|
564
|
+
files.create,
|
|
565
|
+
)
|
|
566
|
+
self.retrieve = to_streamed_response_wrapper(
|
|
567
|
+
files.retrieve,
|
|
568
|
+
)
|
|
569
|
+
self.list = to_streamed_response_wrapper(
|
|
570
|
+
files.list,
|
|
571
|
+
)
|
|
572
|
+
self.delete = to_streamed_response_wrapper(
|
|
573
|
+
files.delete,
|
|
574
|
+
)
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
class AsyncFilesWithStreamingResponse:
|
|
578
|
+
def __init__(self, files: AsyncFiles) -> None:
|
|
579
|
+
self._files = files
|
|
580
|
+
|
|
581
|
+
self.create = async_to_streamed_response_wrapper(
|
|
582
|
+
files.create,
|
|
583
|
+
)
|
|
584
|
+
self.retrieve = async_to_streamed_response_wrapper(
|
|
585
|
+
files.retrieve,
|
|
586
|
+
)
|
|
587
|
+
self.list = async_to_streamed_response_wrapper(
|
|
588
|
+
files.list,
|
|
589
|
+
)
|
|
590
|
+
self.delete = async_to_streamed_response_wrapper(
|
|
591
|
+
files.delete,
|
|
592
|
+
)
|