22
33from __future__ import annotations
44
5- from typing import Any , Mapping , cast
6-
7- import httpx
8-
9- from .... import _legacy_response
105from .threads import (
116 Threads ,
127 AsyncThreads ,
2318 SessionsWithStreamingResponse ,
2419 AsyncSessionsWithStreamingResponse ,
2520)
26- from ...._types import Body , Query , Headers , NotGiven , FileTypes , not_given
27- from ...._utils import extract_files , maybe_transform , deepcopy_minimal , async_maybe_transform
2821from ...._compat import cached_property
2922from ...._resource import SyncAPIResource , AsyncAPIResource
30- from ...._response import to_streamed_response_wrapper , async_to_streamed_response_wrapper
31- from ....types .beta import chatkit_upload_file_params
32- from ...._base_client import make_request_options
33- from ....types .beta .chatkit_upload_file_response import ChatKitUploadFileResponse
3423
3524__all__ = ["ChatKit" , "AsyncChatKit" ]
3625
@@ -63,55 +52,6 @@ def with_streaming_response(self) -> ChatKitWithStreamingResponse:
6352 """
6453 return ChatKitWithStreamingResponse (self )
6554
66- def upload_file (
67- self ,
68- * ,
69- file : FileTypes ,
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 | NotGiven = not_given ,
76- ) -> ChatKitUploadFileResponse :
77- """
78- Upload a ChatKit file
79-
80- Args:
81- file: Binary file contents to store with the ChatKit session. Supports PDFs and PNG,
82- JPG, JPEG, GIF, or WEBP images.
83-
84- extra_headers: Send extra headers
85-
86- extra_query: Add additional query parameters to the request
87-
88- extra_body: Add additional JSON properties to the request
89-
90- timeout: Override the client-level default timeout for this request, in seconds
91- """
92- extra_headers = {"OpenAI-Beta" : "chatkit_beta=v1" , ** (extra_headers or {})}
93- body = deepcopy_minimal ({"file" : file })
94- files = extract_files (cast (Mapping [str , object ], body ), paths = [["file" ]])
95- if files :
96- # It should be noted that the actual Content-Type header that will be
97- # sent to the server will contain a `boundary` parameter, e.g.
98- # multipart/form-data; boundary=---abc--
99- extra_headers ["Content-Type" ] = "multipart/form-data"
100- return cast (
101- ChatKitUploadFileResponse ,
102- self ._post (
103- "/chatkit/files" ,
104- body = maybe_transform (body , chatkit_upload_file_params .ChatKitUploadFileParams ),
105- files = files ,
106- options = make_request_options (
107- extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
108- ),
109- cast_to = cast (
110- Any , ChatKitUploadFileResponse
111- ), # Union types cannot be passed in as arguments in the type system
112- ),
113- )
114-
11555
11656class AsyncChatKit (AsyncAPIResource ):
11757 @cached_property
@@ -141,64 +81,11 @@ def with_streaming_response(self) -> AsyncChatKitWithStreamingResponse:
14181 """
14282 return AsyncChatKitWithStreamingResponse (self )
14383
144- async def upload_file (
145- self ,
146- * ,
147- file : FileTypes ,
148- # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
149- # The extra values given here take precedence over values defined on the client or passed to this method.
150- extra_headers : Headers | None = None ,
151- extra_query : Query | None = None ,
152- extra_body : Body | None = None ,
153- timeout : float | httpx .Timeout | None | NotGiven = not_given ,
154- ) -> ChatKitUploadFileResponse :
155- """
156- Upload a ChatKit file
157-
158- Args:
159- file: Binary file contents to store with the ChatKit session. Supports PDFs and PNG,
160- JPG, JPEG, GIF, or WEBP images.
161-
162- extra_headers: Send extra headers
163-
164- extra_query: Add additional query parameters to the request
165-
166- extra_body: Add additional JSON properties to the request
167-
168- timeout: Override the client-level default timeout for this request, in seconds
169- """
170- extra_headers = {"OpenAI-Beta" : "chatkit_beta=v1" , ** (extra_headers or {})}
171- body = deepcopy_minimal ({"file" : file })
172- files = extract_files (cast (Mapping [str , object ], body ), paths = [["file" ]])
173- if files :
174- # It should be noted that the actual Content-Type header that will be
175- # sent to the server will contain a `boundary` parameter, e.g.
176- # multipart/form-data; boundary=---abc--
177- extra_headers ["Content-Type" ] = "multipart/form-data"
178- return cast (
179- ChatKitUploadFileResponse ,
180- await self ._post (
181- "/chatkit/files" ,
182- body = await async_maybe_transform (body , chatkit_upload_file_params .ChatKitUploadFileParams ),
183- files = files ,
184- options = make_request_options (
185- extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
186- ),
187- cast_to = cast (
188- Any , ChatKitUploadFileResponse
189- ), # Union types cannot be passed in as arguments in the type system
190- ),
191- )
192-
19384
19485class ChatKitWithRawResponse :
19586 def __init__ (self , chatkit : ChatKit ) -> None :
19687 self ._chatkit = chatkit
19788
198- self .upload_file = _legacy_response .to_raw_response_wrapper (
199- chatkit .upload_file ,
200- )
201-
20289 @cached_property
20390 def sessions (self ) -> SessionsWithRawResponse :
20491 return SessionsWithRawResponse (self ._chatkit .sessions )
@@ -212,10 +99,6 @@ class AsyncChatKitWithRawResponse:
21299 def __init__ (self , chatkit : AsyncChatKit ) -> None :
213100 self ._chatkit = chatkit
214101
215- self .upload_file = _legacy_response .async_to_raw_response_wrapper (
216- chatkit .upload_file ,
217- )
218-
219102 @cached_property
220103 def sessions (self ) -> AsyncSessionsWithRawResponse :
221104 return AsyncSessionsWithRawResponse (self ._chatkit .sessions )
@@ -229,10 +112,6 @@ class ChatKitWithStreamingResponse:
229112 def __init__ (self , chatkit : ChatKit ) -> None :
230113 self ._chatkit = chatkit
231114
232- self .upload_file = to_streamed_response_wrapper (
233- chatkit .upload_file ,
234- )
235-
236115 @cached_property
237116 def sessions (self ) -> SessionsWithStreamingResponse :
238117 return SessionsWithStreamingResponse (self ._chatkit .sessions )
@@ -246,10 +125,6 @@ class AsyncChatKitWithStreamingResponse:
246125 def __init__ (self , chatkit : AsyncChatKit ) -> None :
247126 self ._chatkit = chatkit
248127
249- self .upload_file = async_to_streamed_response_wrapper (
250- chatkit .upload_file ,
251- )
252-
253128 @cached_property
254129 def sessions (self ) -> AsyncSessionsWithStreamingResponse :
255130 return AsyncSessionsWithStreamingResponse (self ._chatkit .sessions )
0 commit comments