# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. from __future__ import annotations from typing import Iterable import httpx from ...._types import Body, Omit, Query, Headers, NoneType, NotGiven, omit, not_given from ...._utils import path_template, maybe_transform, async_maybe_transform from ...._compat import cached_property from ...._resource import SyncAPIResource, AsyncAPIResource from ...._response import ( to_raw_response_wrapper, to_streamed_response_wrapper, async_to_raw_response_wrapper, async_to_streamed_response_wrapper, ) from ...._base_client import make_request_options from ....types.ai.collections import SourceType, source_create_params, source_replace_params from ....types.ai.collections.source_type import SourceType from ....types.ai.collections.source_list_response import SourceListResponse from ....types.ai.collections.source_request_param import SourceRequestParam from ....types.ai.collections.source_create_response import SourceCreateResponse from ....types.ai.collections.source_replace_response import SourceReplaceResponse __all__ = ["SourcesResource", "AsyncSourcesResource"] class SourcesResource(SyncAPIResource): """ Create and manage logical collections of your Telnyx data, tune retrieval settings, manage sources, and run collection-scoped semantic search. """ @cached_property def with_raw_response(self) -> SourcesResourceWithRawResponse: """ This property can be used as a prefix for any HTTP method call to return the raw response object instead of the parsed content. For more information, see https://www.github.com/team-telnyx/telnyx-python#accessing-raw-response-data-eg-headers """ return SourcesResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> SourcesResourceWithStreamingResponse: """ An alternative to `.with_raw_response` that doesn't eagerly read the response body. For more information, see https://www.github.com/team-telnyx/telnyx-python#with_streaming_response """ return SourcesResourceWithStreamingResponse(self) def create( self, uuid: str, *, source_type: SourceType, bucket_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> SourceCreateResponse: """ Attaches a new content source to the specified collection and returns the created source. The source's content is ingested and embedded so it becomes searchable within the collection. Args: source_type: The type of Telnyx data attached as a source. `bucket` requires an additional `bucket_id`. Only `voice` is searchable today; `meeting_bot`, `message`, and `bucket` attach but are not yet searchable (Coming soon). bucket_id: The Telnyx Storage bucket name. Required when `source_type` is `bucket`; ignored otherwise. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not uuid: raise ValueError(f"Expected a non-empty value for `uuid` but received {uuid!r}") return self._post( path_template("/ai/collections/{uuid}/sources", uuid=uuid), body=maybe_transform( { "source_type": source_type, "bucket_id": bucket_id, }, source_create_params.SourceCreateParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=SourceCreateResponse, ) def list( self, uuid: str, *, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> SourceListResponse: """ Returns the sources attached to a collection. Args: extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not uuid: raise ValueError(f"Expected a non-empty value for `uuid` but received {uuid!r}") return self._get( path_template("/ai/collections/{uuid}/sources", uuid=uuid), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=SourceListResponse, ) def delete( self, source_id: str, *, uuid: str, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> None: """ Removes a single source from a collection. Args: extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not uuid: raise ValueError(f"Expected a non-empty value for `uuid` but received {uuid!r}") if not source_id: raise ValueError(f"Expected a non-empty value for `source_id` but received {source_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._delete( path_template("/ai/collections/{uuid}/sources/{source_id}", uuid=uuid, source_id=source_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=NoneType, ) def replace( self, uuid: str, *, sources: Iterable[SourceRequestParam], # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> SourceReplaceResponse: """Replaces the collection's entire source set. The response `meta` reports which sources were added, retained, and removed. Args: extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not uuid: raise ValueError(f"Expected a non-empty value for `uuid` but received {uuid!r}") return self._put( path_template("/ai/collections/{uuid}/sources", uuid=uuid), body=maybe_transform({"sources": sources}, source_replace_params.SourceReplaceParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=SourceReplaceResponse, ) class AsyncSourcesResource(AsyncAPIResource): """ Create and manage logical collections of your Telnyx data, tune retrieval settings, manage sources, and run collection-scoped semantic search. """ @cached_property def with_raw_response(self) -> AsyncSourcesResourceWithRawResponse: """ This property can be used as a prefix for any HTTP method call to return the raw response object instead of the parsed content. For more information, see https://www.github.com/team-telnyx/telnyx-python#accessing-raw-response-data-eg-headers """ return AsyncSourcesResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> AsyncSourcesResourceWithStreamingResponse: """ An alternative to `.with_raw_response` that doesn't eagerly read the response body. For more information, see https://www.github.com/team-telnyx/telnyx-python#with_streaming_response """ return AsyncSourcesResourceWithStreamingResponse(self) async def create( self, uuid: str, *, source_type: SourceType, bucket_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> SourceCreateResponse: """ Attaches a new content source to the specified collection and returns the created source. The source's content is ingested and embedded so it becomes searchable within the collection. Args: source_type: The type of Telnyx data attached as a source. `bucket` requires an additional `bucket_id`. Only `voice` is searchable today; `meeting_bot`, `message`, and `bucket` attach but are not yet searchable (Coming soon). bucket_id: The Telnyx Storage bucket name. Required when `source_type` is `bucket`; ignored otherwise. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not uuid: raise ValueError(f"Expected a non-empty value for `uuid` but received {uuid!r}") return await self._post( path_template("/ai/collections/{uuid}/sources", uuid=uuid), body=await async_maybe_transform( { "source_type": source_type, "bucket_id": bucket_id, }, source_create_params.SourceCreateParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=SourceCreateResponse, ) async def list( self, uuid: str, *, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> SourceListResponse: """ Returns the sources attached to a collection. Args: extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not uuid: raise ValueError(f"Expected a non-empty value for `uuid` but received {uuid!r}") return await self._get( path_template("/ai/collections/{uuid}/sources", uuid=uuid), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=SourceListResponse, ) async def delete( self, source_id: str, *, uuid: str, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> None: """ Removes a single source from a collection. Args: extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not uuid: raise ValueError(f"Expected a non-empty value for `uuid` but received {uuid!r}") if not source_id: raise ValueError(f"Expected a non-empty value for `source_id` but received {source_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._delete( path_template("/ai/collections/{uuid}/sources/{source_id}", uuid=uuid, source_id=source_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=NoneType, ) async def replace( self, uuid: str, *, sources: Iterable[SourceRequestParam], # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> SourceReplaceResponse: """Replaces the collection's entire source set. The response `meta` reports which sources were added, retained, and removed. Args: extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not uuid: raise ValueError(f"Expected a non-empty value for `uuid` but received {uuid!r}") return await self._put( path_template("/ai/collections/{uuid}/sources", uuid=uuid), body=await async_maybe_transform({"sources": sources}, source_replace_params.SourceReplaceParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=SourceReplaceResponse, ) class SourcesResourceWithRawResponse: def __init__(self, sources: SourcesResource) -> None: self._sources = sources self.create = to_raw_response_wrapper( sources.create, ) self.list = to_raw_response_wrapper( sources.list, ) self.delete = to_raw_response_wrapper( sources.delete, ) self.replace = to_raw_response_wrapper( sources.replace, ) class AsyncSourcesResourceWithRawResponse: def __init__(self, sources: AsyncSourcesResource) -> None: self._sources = sources self.create = async_to_raw_response_wrapper( sources.create, ) self.list = async_to_raw_response_wrapper( sources.list, ) self.delete = async_to_raw_response_wrapper( sources.delete, ) self.replace = async_to_raw_response_wrapper( sources.replace, ) class SourcesResourceWithStreamingResponse: def __init__(self, sources: SourcesResource) -> None: self._sources = sources self.create = to_streamed_response_wrapper( sources.create, ) self.list = to_streamed_response_wrapper( sources.list, ) self.delete = to_streamed_response_wrapper( sources.delete, ) self.replace = to_streamed_response_wrapper( sources.replace, ) class AsyncSourcesResourceWithStreamingResponse: def __init__(self, sources: AsyncSourcesResource) -> None: self._sources = sources self.create = async_to_streamed_response_wrapper( sources.create, ) self.list = async_to_streamed_response_wrapper( sources.list, ) self.delete = async_to_streamed_response_wrapper( sources.delete, ) self.replace = async_to_streamed_response_wrapper( sources.replace, )