22
33from __future__ import annotations
44
5- from typing import Optional
5+ from typing import List , Mapping , Optional , cast
66from typing_extensions import Literal
77
88import httpx
1515 MetaResourceWithStreamingResponse ,
1616 AsyncMetaResourceWithStreamingResponse ,
1717)
18- from ...types import datasource_list_params , datasource_create_params , datasource_update_params
18+ from ...types import (
19+ datasource_list_params ,
20+ datasource_create_params ,
21+ datasource_update_params ,
22+ datasource_add_file_params ,
23+ )
1924from .indexes import (
2025 IndexesResource ,
2126 AsyncIndexesResource ,
2429 IndexesResourceWithStreamingResponse ,
2530 AsyncIndexesResourceWithStreamingResponse ,
2631)
27- from ..._types import NOT_GIVEN , Body , Query , Headers , NotGiven
32+ from ..._types import NOT_GIVEN , Body , Query , Headers , NotGiven , FileTypes
2833from ..._utils import (
34+ extract_files ,
2935 maybe_transform ,
36+ deepcopy_minimal ,
3037 async_maybe_transform ,
3138)
3239from ..._compat import cached_property
@@ -340,6 +347,84 @@ def delete(
340347 cast_to = object ,
341348 )
342349
350+ def add_file (
351+ self ,
352+ datasource_id : str ,
353+ * ,
354+ files : List [FileTypes ],
355+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
356+ # The extra values given here take precedence over values defined on the client or passed to this method.
357+ extra_headers : Headers | None = None ,
358+ extra_query : Query | None = None ,
359+ extra_body : Body | None = None ,
360+ timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
361+ ) -> object :
362+ """
363+ 为数据源添加文件
364+
365+ Args:
366+ extra_headers: Send extra headers
367+
368+ extra_query: Add additional query parameters to the request
369+
370+ extra_body: Add additional JSON properties to the request
371+
372+ timeout: Override the client-level default timeout for this request, in seconds
373+ """
374+ if not datasource_id :
375+ raise ValueError (f"Expected a non-empty value for `datasource_id` but received { datasource_id !r} " )
376+ body = deepcopy_minimal ({"files" : files })
377+ extracted_files = extract_files (cast (Mapping [str , object ], body ), paths = [["files" , "<array>" ]])
378+ # It should be noted that the actual Content-Type header that will be
379+ # sent to the server will contain a `boundary` parameter, e.g.
380+ # multipart/form-data; boundary=---abc--
381+ extra_headers = {"Content-Type" : "multipart/form-data" , ** (extra_headers or {})}
382+ return self ._post (
383+ f"/datasources/{ datasource_id } /files" ,
384+ body = maybe_transform (body , datasource_add_file_params .DatasourceAddFileParams ),
385+ files = extracted_files ,
386+ options = make_request_options (
387+ extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
388+ ),
389+ cast_to = object ,
390+ )
391+
392+ def delete_file (
393+ self ,
394+ file_id : str ,
395+ * ,
396+ datasource_id : str ,
397+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
398+ # The extra values given here take precedence over values defined on the client or passed to this method.
399+ extra_headers : Headers | None = None ,
400+ extra_query : Query | None = None ,
401+ extra_body : Body | None = None ,
402+ timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
403+ ) -> object :
404+ """
405+ 删除数据源的单个文件
406+
407+ Args:
408+ extra_headers: Send extra headers
409+
410+ extra_query: Add additional query parameters to the request
411+
412+ extra_body: Add additional JSON properties to the request
413+
414+ timeout: Override the client-level default timeout for this request, in seconds
415+ """
416+ if not datasource_id :
417+ raise ValueError (f"Expected a non-empty value for `datasource_id` but received { datasource_id !r} " )
418+ if not file_id :
419+ raise ValueError (f"Expected a non-empty value for `file_id` but received { file_id !r} " )
420+ return self ._delete (
421+ f"/datasources/{ datasource_id } /files/{ file_id } " ,
422+ options = make_request_options (
423+ extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
424+ ),
425+ cast_to = object ,
426+ )
427+
343428
344429class AsyncDatasourcesResource (AsyncAPIResource ):
345430 @cached_property
@@ -628,6 +713,84 @@ async def delete(
628713 cast_to = object ,
629714 )
630715
716+ async def add_file (
717+ self ,
718+ datasource_id : str ,
719+ * ,
720+ files : List [FileTypes ],
721+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
722+ # The extra values given here take precedence over values defined on the client or passed to this method.
723+ extra_headers : Headers | None = None ,
724+ extra_query : Query | None = None ,
725+ extra_body : Body | None = None ,
726+ timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
727+ ) -> object :
728+ """
729+ 为数据源添加文件
730+
731+ Args:
732+ extra_headers: Send extra headers
733+
734+ extra_query: Add additional query parameters to the request
735+
736+ extra_body: Add additional JSON properties to the request
737+
738+ timeout: Override the client-level default timeout for this request, in seconds
739+ """
740+ if not datasource_id :
741+ raise ValueError (f"Expected a non-empty value for `datasource_id` but received { datasource_id !r} " )
742+ body = deepcopy_minimal ({"files" : files })
743+ extracted_files = extract_files (cast (Mapping [str , object ], body ), paths = [["files" , "<array>" ]])
744+ # It should be noted that the actual Content-Type header that will be
745+ # sent to the server will contain a `boundary` parameter, e.g.
746+ # multipart/form-data; boundary=---abc--
747+ extra_headers = {"Content-Type" : "multipart/form-data" , ** (extra_headers or {})}
748+ return await self ._post (
749+ f"/datasources/{ datasource_id } /files" ,
750+ body = await async_maybe_transform (body , datasource_add_file_params .DatasourceAddFileParams ),
751+ files = extracted_files ,
752+ options = make_request_options (
753+ extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
754+ ),
755+ cast_to = object ,
756+ )
757+
758+ async def delete_file (
759+ self ,
760+ file_id : str ,
761+ * ,
762+ datasource_id : str ,
763+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
764+ # The extra values given here take precedence over values defined on the client or passed to this method.
765+ extra_headers : Headers | None = None ,
766+ extra_query : Query | None = None ,
767+ extra_body : Body | None = None ,
768+ timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
769+ ) -> object :
770+ """
771+ 删除数据源的单个文件
772+
773+ Args:
774+ extra_headers: Send extra headers
775+
776+ extra_query: Add additional query parameters to the request
777+
778+ extra_body: Add additional JSON properties to the request
779+
780+ timeout: Override the client-level default timeout for this request, in seconds
781+ """
782+ if not datasource_id :
783+ raise ValueError (f"Expected a non-empty value for `datasource_id` but received { datasource_id !r} " )
784+ if not file_id :
785+ raise ValueError (f"Expected a non-empty value for `file_id` but received { file_id !r} " )
786+ return await self ._delete (
787+ f"/datasources/{ datasource_id } /files/{ file_id } " ,
788+ options = make_request_options (
789+ extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
790+ ),
791+ cast_to = object ,
792+ )
793+
631794
632795class DatasourcesResourceWithRawResponse :
633796 def __init__ (self , datasources : DatasourcesResource ) -> None :
@@ -648,6 +811,12 @@ def __init__(self, datasources: DatasourcesResource) -> None:
648811 self .delete = to_raw_response_wrapper (
649812 datasources .delete ,
650813 )
814+ self .add_file = to_raw_response_wrapper (
815+ datasources .add_file ,
816+ )
817+ self .delete_file = to_raw_response_wrapper (
818+ datasources .delete_file ,
819+ )
651820
652821 @cached_property
653822 def meta (self ) -> MetaResourceWithRawResponse :
@@ -681,6 +850,12 @@ def __init__(self, datasources: AsyncDatasourcesResource) -> None:
681850 self .delete = async_to_raw_response_wrapper (
682851 datasources .delete ,
683852 )
853+ self .add_file = async_to_raw_response_wrapper (
854+ datasources .add_file ,
855+ )
856+ self .delete_file = async_to_raw_response_wrapper (
857+ datasources .delete_file ,
858+ )
684859
685860 @cached_property
686861 def meta (self ) -> AsyncMetaResourceWithRawResponse :
@@ -714,6 +889,12 @@ def __init__(self, datasources: DatasourcesResource) -> None:
714889 self .delete = to_streamed_response_wrapper (
715890 datasources .delete ,
716891 )
892+ self .add_file = to_streamed_response_wrapper (
893+ datasources .add_file ,
894+ )
895+ self .delete_file = to_streamed_response_wrapper (
896+ datasources .delete_file ,
897+ )
717898
718899 @cached_property
719900 def meta (self ) -> MetaResourceWithStreamingResponse :
@@ -747,6 +928,12 @@ def __init__(self, datasources: AsyncDatasourcesResource) -> None:
747928 self .delete = async_to_streamed_response_wrapper (
748929 datasources .delete ,
749930 )
931+ self .add_file = async_to_streamed_response_wrapper (
932+ datasources .add_file ,
933+ )
934+ self .delete_file = async_to_streamed_response_wrapper (
935+ datasources .delete_file ,
936+ )
750937
751938 @cached_property
752939 def meta (self ) -> AsyncMetaResourceWithStreamingResponse :
0 commit comments