22
33from __future__ import annotations
44
5- from typing import Optional
5+ from typing import Mapping , Optional , cast
66from typing_extensions import Literal
77
88import httpx
99
10- from .file import (
11- FileResource ,
12- AsyncFileResource ,
13- FileResourceWithRawResponse ,
14- AsyncFileResourceWithRawResponse ,
15- FileResourceWithStreamingResponse ,
16- AsyncFileResourceWithStreamingResponse ,
17- )
1810from .meta import (
1911 MetaResource ,
2012 AsyncMetaResource ,
2315 MetaResourceWithStreamingResponse ,
2416 AsyncMetaResourceWithStreamingResponse ,
2517)
26- from ...types import datasource_list_params , datasource_create_params , datasource_update_params
27- from ..._types import NOT_GIVEN , Body , Query , Headers , NotGiven
18+ from ...types import (
19+ datasource_list_params ,
20+ datasource_create_params ,
21+ datasource_update_params ,
22+ datasource_create_from_file_params ,
23+ )
24+ from ..._types import NOT_GIVEN , Body , Query , Headers , NotGiven , FileTypes
2825from ..._utils import (
26+ extract_files ,
2927 maybe_transform ,
28+ deepcopy_minimal ,
3029 async_maybe_transform ,
3130)
3231from ..._compat import cached_property
5352
5453
5554class DatasourcesResource (SyncAPIResource ):
56- @cached_property
57- def file (self ) -> FileResource :
58- return FileResource (self ._client )
59-
6055 @cached_property
6156 def meta (self ) -> MetaResource :
6257 return MetaResource (self ._client )
@@ -331,12 +326,65 @@ def delete(
331326 cast_to = object ,
332327 )
333328
329+ def create_from_file (
330+ self ,
331+ * ,
332+ name : str ,
333+ file : FileTypes ,
334+ async_process_meta : bool | NotGiven = NOT_GIVEN ,
335+ skip_process_meta : bool | NotGiven = NOT_GIVEN ,
336+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
337+ # The extra values given here take precedence over values defined on the client or passed to this method.
338+ extra_headers : Headers | None = None ,
339+ extra_query : Query | None = None ,
340+ extra_body : Body | None = None ,
341+ timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
342+ ) -> DataSource :
343+ """
344+ 上传文件并创建数据源
345+
346+ Args:
347+ async_process_meta: 是否异步处理元数据
334348
335- class AsyncDatasourcesResource (AsyncAPIResource ):
336- @cached_property
337- def file (self ) -> AsyncFileResource :
338- return AsyncFileResource (self ._client )
349+ skip_process_meta: 是否跳过元数据处理
350+
351+ extra_headers: Send extra headers
352+
353+ extra_query: Add additional query parameters to the request
339354
355+ extra_body: Add additional JSON properties to the request
356+
357+ timeout: Override the client-level default timeout for this request, in seconds
358+ """
359+ body = deepcopy_minimal ({"file" : file })
360+ files = extract_files (cast (Mapping [str , object ], body ), paths = [["file" ]])
361+ # It should be noted that the actual Content-Type header that will be
362+ # sent to the server will contain a `boundary` parameter, e.g.
363+ # multipart/form-data; boundary=---abc--
364+ extra_headers = {"Content-Type" : "multipart/form-data" , ** (extra_headers or {})}
365+ return self ._post (
366+ "/datasources/file" ,
367+ body = maybe_transform (body , datasource_create_from_file_params .DatasourceCreateFromFileParams ),
368+ files = files ,
369+ options = make_request_options (
370+ extra_headers = extra_headers ,
371+ extra_query = extra_query ,
372+ extra_body = extra_body ,
373+ timeout = timeout ,
374+ query = maybe_transform (
375+ {
376+ "name" : name ,
377+ "async_process_meta" : async_process_meta ,
378+ "skip_process_meta" : skip_process_meta ,
379+ },
380+ datasource_create_from_file_params .DatasourceCreateFromFileParams ,
381+ ),
382+ ),
383+ cast_to = DataSource ,
384+ )
385+
386+
387+ class AsyncDatasourcesResource (AsyncAPIResource ):
340388 @cached_property
341389 def meta (self ) -> AsyncMetaResource :
342390 return AsyncMetaResource (self ._client )
@@ -611,6 +659,63 @@ async def delete(
611659 cast_to = object ,
612660 )
613661
662+ async def create_from_file (
663+ self ,
664+ * ,
665+ name : str ,
666+ file : FileTypes ,
667+ async_process_meta : bool | NotGiven = NOT_GIVEN ,
668+ skip_process_meta : bool | NotGiven = NOT_GIVEN ,
669+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
670+ # The extra values given here take precedence over values defined on the client or passed to this method.
671+ extra_headers : Headers | None = None ,
672+ extra_query : Query | None = None ,
673+ extra_body : Body | None = None ,
674+ timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
675+ ) -> DataSource :
676+ """
677+ 上传文件并创建数据源
678+
679+ Args:
680+ async_process_meta: 是否异步处理元数据
681+
682+ skip_process_meta: 是否跳过元数据处理
683+
684+ extra_headers: Send extra headers
685+
686+ extra_query: Add additional query parameters to the request
687+
688+ extra_body: Add additional JSON properties to the request
689+
690+ timeout: Override the client-level default timeout for this request, in seconds
691+ """
692+ body = deepcopy_minimal ({"file" : file })
693+ files = extract_files (cast (Mapping [str , object ], body ), paths = [["file" ]])
694+ # It should be noted that the actual Content-Type header that will be
695+ # sent to the server will contain a `boundary` parameter, e.g.
696+ # multipart/form-data; boundary=---abc--
697+ extra_headers = {"Content-Type" : "multipart/form-data" , ** (extra_headers or {})}
698+ return await self ._post (
699+ "/datasources/file" ,
700+ body = await async_maybe_transform (body , datasource_create_from_file_params .DatasourceCreateFromFileParams ),
701+ files = files ,
702+ options = make_request_options (
703+ extra_headers = extra_headers ,
704+ extra_query = extra_query ,
705+ extra_body = extra_body ,
706+ timeout = timeout ,
707+ query = await async_maybe_transform (
708+ {
709+ "name" : name ,
710+ "async_process_meta" : async_process_meta ,
711+ "skip_process_meta" : skip_process_meta ,
712+ },
713+ datasource_create_from_file_params .DatasourceCreateFromFileParams ,
714+ ),
715+ ),
716+ cast_to = DataSource ,
717+ )
718+
614719
615720class DatasourcesResourceWithRawResponse :
616721 def __init__ (self , datasources : DatasourcesResource ) -> None :
@@ -631,10 +736,9 @@ def __init__(self, datasources: DatasourcesResource) -> None:
631736 self .delete = to_raw_response_wrapper (
632737 datasources .delete ,
633738 )
634-
635- @cached_property
636- def file (self ) -> FileResourceWithRawResponse :
637- return FileResourceWithRawResponse (self ._datasources .file )
739+ self .create_from_file = to_raw_response_wrapper (
740+ datasources .create_from_file ,
741+ )
638742
639743 @cached_property
640744 def meta (self ) -> MetaResourceWithRawResponse :
@@ -664,10 +768,9 @@ def __init__(self, datasources: AsyncDatasourcesResource) -> None:
664768 self .delete = async_to_raw_response_wrapper (
665769 datasources .delete ,
666770 )
667-
668- @cached_property
669- def file (self ) -> AsyncFileResourceWithRawResponse :
670- return AsyncFileResourceWithRawResponse (self ._datasources .file )
771+ self .create_from_file = async_to_raw_response_wrapper (
772+ datasources .create_from_file ,
773+ )
671774
672775 @cached_property
673776 def meta (self ) -> AsyncMetaResourceWithRawResponse :
@@ -697,10 +800,9 @@ def __init__(self, datasources: DatasourcesResource) -> None:
697800 self .delete = to_streamed_response_wrapper (
698801 datasources .delete ,
699802 )
700-
701- @cached_property
702- def file (self ) -> FileResourceWithStreamingResponse :
703- return FileResourceWithStreamingResponse (self ._datasources .file )
803+ self .create_from_file = to_streamed_response_wrapper (
804+ datasources .create_from_file ,
805+ )
704806
705807 @cached_property
706808 def meta (self ) -> MetaResourceWithStreamingResponse :
@@ -730,10 +832,9 @@ def __init__(self, datasources: AsyncDatasourcesResource) -> None:
730832 self .delete = async_to_streamed_response_wrapper (
731833 datasources .delete ,
732834 )
733-
734- @cached_property
735- def file (self ) -> AsyncFileResourceWithStreamingResponse :
736- return AsyncFileResourceWithStreamingResponse (self ._datasources .file )
835+ self .create_from_file = async_to_streamed_response_wrapper (
836+ datasources .create_from_file ,
837+ )
737838
738839 @cached_property
739840 def meta (self ) -> AsyncMetaResourceWithStreamingResponse :
0 commit comments