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,454 @@
|
|
|
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
|
+
from typing import Dict, List, Type, Union, Iterable, Optional, cast
|
|
15
|
+
from functools import partial
|
|
16
|
+
from typing_extensions import Literal
|
|
17
|
+
|
|
18
|
+
import httpx
|
|
19
|
+
|
|
20
|
+
from .... import _legacy_response
|
|
21
|
+
from ...._types import NOT_GIVEN, Body, Query, Headers, NotGiven
|
|
22
|
+
from ...._utils import (
|
|
23
|
+
maybe_transform,
|
|
24
|
+
async_maybe_transform,
|
|
25
|
+
with_sts_token,
|
|
26
|
+
async_with_sts_token,
|
|
27
|
+
)
|
|
28
|
+
from ...._compat import cached_property
|
|
29
|
+
from ...._resource import SyncAPIResource, AsyncAPIResource
|
|
30
|
+
from ...._response import (
|
|
31
|
+
to_streamed_response_wrapper,
|
|
32
|
+
async_to_streamed_response_wrapper,
|
|
33
|
+
)
|
|
34
|
+
from ...._streaming import Stream
|
|
35
|
+
from ....types.chat import completion_create_params
|
|
36
|
+
from ...._base_client import make_request_options
|
|
37
|
+
from ....common._parsing import (
|
|
38
|
+
ResponseFormatT,
|
|
39
|
+
validate_input_tools as _validate_input_tools,
|
|
40
|
+
parse_chat_completion as _parse_chat_completion,
|
|
41
|
+
type_to_response_format_param as _type_to_response_format,
|
|
42
|
+
)
|
|
43
|
+
from ....common.streaming.chat import (
|
|
44
|
+
ChatCompletionStreamManager,
|
|
45
|
+
AsyncChatCompletionStreamManager,
|
|
46
|
+
)
|
|
47
|
+
from ....types.chat.chat_completion import ChatCompletion
|
|
48
|
+
from ....types.chat.chat_completion_chunk import ChatCompletionChunk
|
|
49
|
+
from ....types.chat.parsed_chat_completion import ParsedChatCompletion
|
|
50
|
+
from ....types.chat.chat_completion_tool_param import ChatCompletionToolParam
|
|
51
|
+
from ....types.chat.chat_completion_message_param import ChatCompletionMessageParam
|
|
52
|
+
from ....types.chat.chat_completion_stream_options_param import (
|
|
53
|
+
ChatCompletionStreamOptionsParam,
|
|
54
|
+
)
|
|
55
|
+
from ....types.chat.chat_completion_tool_choice_option_param import (
|
|
56
|
+
ChatCompletionToolChoiceOptionParam,
|
|
57
|
+
)
|
|
58
|
+
from ....types.shared.reasoning_effort import ReasoningEffort
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
__all__ = ["Completions", "AsyncCompletions"]
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class Completions(SyncAPIResource):
|
|
65
|
+
@cached_property
|
|
66
|
+
def with_raw_response(self) -> CompletionsWithRawResponse:
|
|
67
|
+
"""
|
|
68
|
+
This property can be used as a prefix for any HTTP method call to return the
|
|
69
|
+
the raw response object instead of the parsed content.
|
|
70
|
+
"""
|
|
71
|
+
return CompletionsWithRawResponse(self)
|
|
72
|
+
|
|
73
|
+
@cached_property
|
|
74
|
+
def with_streaming_response(self) -> CompletionsWithStreamingResponse:
|
|
75
|
+
"""
|
|
76
|
+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
|
77
|
+
"""
|
|
78
|
+
return CompletionsWithStreamingResponse(self)
|
|
79
|
+
|
|
80
|
+
@with_sts_token
|
|
81
|
+
def parse(
|
|
82
|
+
self,
|
|
83
|
+
*,
|
|
84
|
+
messages: Iterable[ChatCompletionMessageParam],
|
|
85
|
+
model: str,
|
|
86
|
+
response_format: type[ResponseFormatT] | NotGiven = NOT_GIVEN,
|
|
87
|
+
frequency_penalty: Optional[float] | NotGiven = NOT_GIVEN,
|
|
88
|
+
logit_bias: Optional[Dict[str, int]] | NotGiven = NOT_GIVEN,
|
|
89
|
+
logprobs: Optional[bool] | NotGiven = NOT_GIVEN,
|
|
90
|
+
max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
|
|
91
|
+
n: Optional[int] | NotGiven = NOT_GIVEN,
|
|
92
|
+
parallel_tool_calls: bool | NotGiven = NOT_GIVEN,
|
|
93
|
+
presence_penalty: Optional[float] | NotGiven = NOT_GIVEN,
|
|
94
|
+
service_tier: Optional[Literal["auto", "default"]] | NotGiven = NOT_GIVEN,
|
|
95
|
+
stop: Union[Optional[str], List[str], None] | NotGiven = NOT_GIVEN,
|
|
96
|
+
stream_options: Optional[ChatCompletionStreamOptionsParam]
|
|
97
|
+
| NotGiven = NOT_GIVEN,
|
|
98
|
+
temperature: Optional[float] | NotGiven = NOT_GIVEN,
|
|
99
|
+
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
|
|
100
|
+
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
|
|
101
|
+
top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
|
|
102
|
+
top_p: Optional[float] | NotGiven = NOT_GIVEN,
|
|
103
|
+
user: str | NotGiven = NOT_GIVEN,
|
|
104
|
+
reasoning_effort: Optional[ReasoningEffort] | NotGiven = NOT_GIVEN,
|
|
105
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
106
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
107
|
+
extra_headers: Headers | None = None,
|
|
108
|
+
extra_query: Query | None = None,
|
|
109
|
+
extra_body: Body | None = None,
|
|
110
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
111
|
+
) -> ParsedChatCompletion[ResponseFormatT]:
|
|
112
|
+
_validate_input_tools(tools)
|
|
113
|
+
|
|
114
|
+
extra_headers = {
|
|
115
|
+
"X-Stainless-Helper-Method": "beta.chat.completions.parse",
|
|
116
|
+
**(extra_headers or {}),
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
def parser(
|
|
120
|
+
raw_completion: ChatCompletion,
|
|
121
|
+
) -> ParsedChatCompletion[ResponseFormatT]:
|
|
122
|
+
return _parse_chat_completion(
|
|
123
|
+
response_format=response_format,
|
|
124
|
+
chat_completion=raw_completion,
|
|
125
|
+
input_tools=tools,
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
return self._post(
|
|
129
|
+
"/chat/completions",
|
|
130
|
+
body=maybe_transform(
|
|
131
|
+
{
|
|
132
|
+
"messages": messages,
|
|
133
|
+
"model": model,
|
|
134
|
+
"frequency_penalty": frequency_penalty,
|
|
135
|
+
"logit_bias": logit_bias,
|
|
136
|
+
"logprobs": logprobs,
|
|
137
|
+
"max_tokens": max_tokens,
|
|
138
|
+
"n": n,
|
|
139
|
+
"parallel_tool_calls": parallel_tool_calls,
|
|
140
|
+
"presence_penalty": presence_penalty,
|
|
141
|
+
"response_format": _type_to_response_format(response_format),
|
|
142
|
+
"service_tier": service_tier,
|
|
143
|
+
"stop": stop,
|
|
144
|
+
"stream": False,
|
|
145
|
+
"stream_options": stream_options,
|
|
146
|
+
"temperature": temperature,
|
|
147
|
+
"tool_choice": tool_choice,
|
|
148
|
+
"tools": tools,
|
|
149
|
+
"top_logprobs": top_logprobs,
|
|
150
|
+
"top_p": top_p,
|
|
151
|
+
"user": user,
|
|
152
|
+
"reasoning_effort": reasoning_effort,
|
|
153
|
+
},
|
|
154
|
+
completion_create_params.CompletionCreateParams,
|
|
155
|
+
),
|
|
156
|
+
options=make_request_options(
|
|
157
|
+
extra_headers=extra_headers,
|
|
158
|
+
extra_query=extra_query,
|
|
159
|
+
extra_body=extra_body,
|
|
160
|
+
timeout=timeout,
|
|
161
|
+
post_parser=parser,
|
|
162
|
+
),
|
|
163
|
+
# we turn the `ChatCompletion` instance into a `ParsedChatCompletion`
|
|
164
|
+
# in the `parser` function above
|
|
165
|
+
cast_to=cast(Type[ParsedChatCompletion[ResponseFormatT]], ChatCompletion),
|
|
166
|
+
stream=False,
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
def stream(
|
|
170
|
+
self,
|
|
171
|
+
*,
|
|
172
|
+
messages: Iterable[ChatCompletionMessageParam],
|
|
173
|
+
model: str,
|
|
174
|
+
response_format: completion_create_params.ResponseFormat
|
|
175
|
+
| type[ResponseFormatT]
|
|
176
|
+
| NotGiven = NOT_GIVEN,
|
|
177
|
+
frequency_penalty: Optional[float] | NotGiven = NOT_GIVEN,
|
|
178
|
+
logit_bias: Optional[Dict[str, int]] | NotGiven = NOT_GIVEN,
|
|
179
|
+
logprobs: Optional[bool] | NotGiven = NOT_GIVEN,
|
|
180
|
+
max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
|
|
181
|
+
n: Optional[int] | NotGiven = NOT_GIVEN,
|
|
182
|
+
parallel_tool_calls: bool | NotGiven = NOT_GIVEN,
|
|
183
|
+
presence_penalty: Optional[float] | NotGiven = NOT_GIVEN,
|
|
184
|
+
service_tier: Optional[Literal["auto", "default"]] | NotGiven = NOT_GIVEN,
|
|
185
|
+
stop: Union[Optional[str], List[str], None] | NotGiven = NOT_GIVEN,
|
|
186
|
+
stream_options: Optional[ChatCompletionStreamOptionsParam]
|
|
187
|
+
| NotGiven = NOT_GIVEN,
|
|
188
|
+
temperature: Optional[float] | NotGiven = NOT_GIVEN,
|
|
189
|
+
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
|
|
190
|
+
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
|
|
191
|
+
top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
|
|
192
|
+
top_p: Optional[float] | NotGiven = NOT_GIVEN,
|
|
193
|
+
user: str | NotGiven = NOT_GIVEN,
|
|
194
|
+
reasoning_effort: Optional[ReasoningEffort] | NotGiven = NOT_GIVEN,
|
|
195
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
196
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
197
|
+
extra_headers: Headers | None = None,
|
|
198
|
+
extra_query: Query | None = None,
|
|
199
|
+
extra_body: Body | None = None,
|
|
200
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
201
|
+
) -> ChatCompletionStreamManager[ResponseFormatT]:
|
|
202
|
+
extra_headers = {
|
|
203
|
+
"X-Stainless-Helper-Method": "beta.chat.completions.stream",
|
|
204
|
+
**(extra_headers or {}),
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
api_request: partial[Stream[ChatCompletionChunk]] = partial(
|
|
208
|
+
self._client.chat.completions.create,
|
|
209
|
+
reasoning_effort=reasoning_effort,
|
|
210
|
+
messages=messages,
|
|
211
|
+
model=model,
|
|
212
|
+
stream=True,
|
|
213
|
+
response_format=_type_to_response_format(response_format),
|
|
214
|
+
frequency_penalty=frequency_penalty,
|
|
215
|
+
logit_bias=logit_bias,
|
|
216
|
+
logprobs=logprobs,
|
|
217
|
+
max_tokens=max_tokens,
|
|
218
|
+
n=n,
|
|
219
|
+
parallel_tool_calls=parallel_tool_calls,
|
|
220
|
+
presence_penalty=presence_penalty,
|
|
221
|
+
service_tier=service_tier,
|
|
222
|
+
stop=stop,
|
|
223
|
+
stream_options=stream_options,
|
|
224
|
+
temperature=temperature,
|
|
225
|
+
tool_choice=tool_choice,
|
|
226
|
+
tools=tools,
|
|
227
|
+
top_logprobs=top_logprobs,
|
|
228
|
+
top_p=top_p,
|
|
229
|
+
user=user,
|
|
230
|
+
extra_headers=extra_headers,
|
|
231
|
+
extra_query=extra_query,
|
|
232
|
+
extra_body=extra_body,
|
|
233
|
+
timeout=timeout,
|
|
234
|
+
)
|
|
235
|
+
return ChatCompletionStreamManager(
|
|
236
|
+
api_request,
|
|
237
|
+
response_format=response_format,
|
|
238
|
+
input_tools=tools,
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
class AsyncCompletions(AsyncAPIResource):
|
|
243
|
+
@cached_property
|
|
244
|
+
def with_raw_response(self) -> AsyncCompletionsWithRawResponse:
|
|
245
|
+
"""
|
|
246
|
+
This property can be used as a prefix for any HTTP method call to return the
|
|
247
|
+
the raw response object instead of the parsed content.
|
|
248
|
+
"""
|
|
249
|
+
return AsyncCompletionsWithRawResponse(self)
|
|
250
|
+
|
|
251
|
+
@cached_property
|
|
252
|
+
def with_streaming_response(self) -> AsyncCompletionsWithStreamingResponse:
|
|
253
|
+
"""
|
|
254
|
+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
|
255
|
+
"""
|
|
256
|
+
return AsyncCompletionsWithStreamingResponse(self)
|
|
257
|
+
|
|
258
|
+
@async_with_sts_token
|
|
259
|
+
async def parse(
|
|
260
|
+
self,
|
|
261
|
+
*,
|
|
262
|
+
messages: Iterable[ChatCompletionMessageParam],
|
|
263
|
+
model: str,
|
|
264
|
+
response_format: type[ResponseFormatT] | NotGiven = NOT_GIVEN,
|
|
265
|
+
frequency_penalty: Optional[float] | NotGiven = NOT_GIVEN,
|
|
266
|
+
logit_bias: Optional[Dict[str, int]] | NotGiven = NOT_GIVEN,
|
|
267
|
+
logprobs: Optional[bool] | NotGiven = NOT_GIVEN,
|
|
268
|
+
max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
|
|
269
|
+
n: Optional[int] | NotGiven = NOT_GIVEN,
|
|
270
|
+
parallel_tool_calls: bool | NotGiven = NOT_GIVEN,
|
|
271
|
+
presence_penalty: Optional[float] | NotGiven = NOT_GIVEN,
|
|
272
|
+
service_tier: Optional[Literal["auto", "default"]] | NotGiven = NOT_GIVEN,
|
|
273
|
+
stop: Union[Optional[str], List[str], None] | NotGiven = NOT_GIVEN,
|
|
274
|
+
stream_options: Optional[ChatCompletionStreamOptionsParam]
|
|
275
|
+
| NotGiven = NOT_GIVEN,
|
|
276
|
+
temperature: Optional[float] | NotGiven = NOT_GIVEN,
|
|
277
|
+
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
|
|
278
|
+
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
|
|
279
|
+
top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
|
|
280
|
+
top_p: Optional[float] | NotGiven = NOT_GIVEN,
|
|
281
|
+
user: str | NotGiven = NOT_GIVEN,
|
|
282
|
+
reasoning_effort: Optional[ReasoningEffort] | NotGiven = NOT_GIVEN,
|
|
283
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
284
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
285
|
+
extra_headers: Headers | None = None,
|
|
286
|
+
extra_query: Query | None = None,
|
|
287
|
+
extra_body: Body | None = None,
|
|
288
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
289
|
+
) -> ParsedChatCompletion[ResponseFormatT]:
|
|
290
|
+
_validate_input_tools(tools)
|
|
291
|
+
|
|
292
|
+
extra_headers = {
|
|
293
|
+
"X-Stainless-Helper-Method": "beta.chat.completions.parse",
|
|
294
|
+
**(extra_headers or {}),
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
def parser(
|
|
298
|
+
raw_completion: ChatCompletion,
|
|
299
|
+
) -> ParsedChatCompletion[ResponseFormatT]:
|
|
300
|
+
return _parse_chat_completion(
|
|
301
|
+
response_format=response_format,
|
|
302
|
+
chat_completion=raw_completion,
|
|
303
|
+
input_tools=tools,
|
|
304
|
+
)
|
|
305
|
+
|
|
306
|
+
return await self._post(
|
|
307
|
+
"/chat/completions",
|
|
308
|
+
body=await async_maybe_transform(
|
|
309
|
+
{
|
|
310
|
+
"messages": messages,
|
|
311
|
+
"model": model,
|
|
312
|
+
"frequency_penalty": frequency_penalty,
|
|
313
|
+
"logit_bias": logit_bias,
|
|
314
|
+
"logprobs": logprobs,
|
|
315
|
+
"max_tokens": max_tokens,
|
|
316
|
+
"n": n,
|
|
317
|
+
"parallel_tool_calls": parallel_tool_calls,
|
|
318
|
+
"presence_penalty": presence_penalty,
|
|
319
|
+
"response_format": _type_to_response_format(response_format),
|
|
320
|
+
"service_tier": service_tier,
|
|
321
|
+
"stop": stop,
|
|
322
|
+
"stream": False,
|
|
323
|
+
"stream_options": stream_options,
|
|
324
|
+
"temperature": temperature,
|
|
325
|
+
"tool_choice": tool_choice,
|
|
326
|
+
"tools": tools,
|
|
327
|
+
"top_logprobs": top_logprobs,
|
|
328
|
+
"top_p": top_p,
|
|
329
|
+
"user": user,
|
|
330
|
+
"reasoning_effort": reasoning_effort,
|
|
331
|
+
},
|
|
332
|
+
completion_create_params.CompletionCreateParams,
|
|
333
|
+
),
|
|
334
|
+
options=make_request_options(
|
|
335
|
+
extra_headers=extra_headers,
|
|
336
|
+
extra_query=extra_query,
|
|
337
|
+
extra_body=extra_body,
|
|
338
|
+
timeout=timeout,
|
|
339
|
+
post_parser=parser,
|
|
340
|
+
),
|
|
341
|
+
# we turn the `ChatCompletion` instance into a `ParsedChatCompletion`
|
|
342
|
+
# in the `parser` function above
|
|
343
|
+
cast_to=cast(Type[ParsedChatCompletion[ResponseFormatT]], ChatCompletion),
|
|
344
|
+
stream=False,
|
|
345
|
+
)
|
|
346
|
+
|
|
347
|
+
def stream(
|
|
348
|
+
self,
|
|
349
|
+
*,
|
|
350
|
+
messages: Iterable[ChatCompletionMessageParam],
|
|
351
|
+
model: str,
|
|
352
|
+
response_format: completion_create_params.ResponseFormat
|
|
353
|
+
| type[ResponseFormatT]
|
|
354
|
+
| NotGiven = NOT_GIVEN,
|
|
355
|
+
frequency_penalty: Optional[float] | NotGiven = NOT_GIVEN,
|
|
356
|
+
logit_bias: Optional[Dict[str, int]] | NotGiven = NOT_GIVEN,
|
|
357
|
+
logprobs: Optional[bool] | NotGiven = NOT_GIVEN,
|
|
358
|
+
max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
|
|
359
|
+
n: Optional[int] | NotGiven = NOT_GIVEN,
|
|
360
|
+
parallel_tool_calls: bool | NotGiven = NOT_GIVEN,
|
|
361
|
+
presence_penalty: Optional[float] | NotGiven = NOT_GIVEN,
|
|
362
|
+
service_tier: Optional[Literal["auto", "default"]] | NotGiven = NOT_GIVEN,
|
|
363
|
+
stop: Union[Optional[str], List[str], None] | NotGiven = NOT_GIVEN,
|
|
364
|
+
stream_options: Optional[ChatCompletionStreamOptionsParam]
|
|
365
|
+
| NotGiven = NOT_GIVEN,
|
|
366
|
+
temperature: Optional[float] | NotGiven = NOT_GIVEN,
|
|
367
|
+
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
|
|
368
|
+
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
|
|
369
|
+
top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
|
|
370
|
+
top_p: Optional[float] | NotGiven = NOT_GIVEN,
|
|
371
|
+
user: str | NotGiven = NOT_GIVEN,
|
|
372
|
+
reasoning_effort: Optional[ReasoningEffort] | NotGiven = NOT_GIVEN,
|
|
373
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
374
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
375
|
+
extra_headers: Headers | None = None,
|
|
376
|
+
extra_query: Query | None = None,
|
|
377
|
+
extra_body: Body | None = None,
|
|
378
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
379
|
+
) -> AsyncChatCompletionStreamManager[ResponseFormatT]:
|
|
380
|
+
_validate_input_tools(tools)
|
|
381
|
+
|
|
382
|
+
extra_headers = {
|
|
383
|
+
"X-Stainless-Helper-Method": "beta.chat.completions.stream",
|
|
384
|
+
**(extra_headers or {}),
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
api_request = self._client.chat.completions.create(
|
|
388
|
+
messages=messages,
|
|
389
|
+
model=model,
|
|
390
|
+
stream=True,
|
|
391
|
+
response_format=_type_to_response_format(response_format),
|
|
392
|
+
frequency_penalty=frequency_penalty,
|
|
393
|
+
logit_bias=logit_bias,
|
|
394
|
+
logprobs=logprobs,
|
|
395
|
+
max_tokens=max_tokens,
|
|
396
|
+
n=n,
|
|
397
|
+
parallel_tool_calls=parallel_tool_calls,
|
|
398
|
+
presence_penalty=presence_penalty,
|
|
399
|
+
service_tier=service_tier,
|
|
400
|
+
stop=stop,
|
|
401
|
+
stream_options=stream_options,
|
|
402
|
+
temperature=temperature,
|
|
403
|
+
tool_choice=tool_choice,
|
|
404
|
+
tools=tools,
|
|
405
|
+
top_logprobs=top_logprobs,
|
|
406
|
+
top_p=top_p,
|
|
407
|
+
user=user,
|
|
408
|
+
reasoning_effort=reasoning_effort,
|
|
409
|
+
extra_headers=extra_headers,
|
|
410
|
+
extra_query=extra_query,
|
|
411
|
+
extra_body=extra_body,
|
|
412
|
+
timeout=timeout,
|
|
413
|
+
)
|
|
414
|
+
return AsyncChatCompletionStreamManager(
|
|
415
|
+
api_request,
|
|
416
|
+
response_format=response_format,
|
|
417
|
+
input_tools=tools,
|
|
418
|
+
)
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
class CompletionsWithRawResponse:
|
|
422
|
+
def __init__(self, completions: Completions) -> None:
|
|
423
|
+
self._completions = completions
|
|
424
|
+
|
|
425
|
+
self.parse = _legacy_response.to_raw_response_wrapper(
|
|
426
|
+
completions.parse,
|
|
427
|
+
)
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
class AsyncCompletionsWithRawResponse:
|
|
431
|
+
def __init__(self, completions: AsyncCompletions) -> None:
|
|
432
|
+
self._completions = completions
|
|
433
|
+
|
|
434
|
+
self.parse = _legacy_response.async_to_raw_response_wrapper(
|
|
435
|
+
completions.parse,
|
|
436
|
+
)
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
class CompletionsWithStreamingResponse:
|
|
440
|
+
def __init__(self, completions: Completions) -> None:
|
|
441
|
+
self._completions = completions
|
|
442
|
+
|
|
443
|
+
self.parse = to_streamed_response_wrapper(
|
|
444
|
+
completions.parse,
|
|
445
|
+
)
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
class AsyncCompletionsWithStreamingResponse:
|
|
449
|
+
def __init__(self, completions: AsyncCompletions) -> None:
|
|
450
|
+
self._completions = completions
|
|
451
|
+
|
|
452
|
+
self.parse = async_to_streamed_response_wrapper(
|
|
453
|
+
completions.parse,
|
|
454
|
+
)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from .completions import Completions, AsyncCompletions
|
|
6
|
+
from ..._compat import cached_property
|
|
7
|
+
from ..._resource import SyncAPIResource, AsyncAPIResource
|
|
8
|
+
|
|
9
|
+
__all__ = ["Chat", "AsyncChat"]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Chat(SyncAPIResource):
|
|
13
|
+
@cached_property
|
|
14
|
+
def completions(self) -> Completions:
|
|
15
|
+
return Completions(self._client)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class AsyncChat(AsyncAPIResource):
|
|
19
|
+
@cached_property
|
|
20
|
+
def completions(self) -> AsyncCompletions:
|
|
21
|
+
return AsyncCompletions(self._client)
|