content.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
  2. from __future__ import annotations
  3. import httpx
  4. from .... import _legacy_response
  5. from ...._types import Body, Query, Headers, NotGiven, not_given
  6. from ...._compat import cached_property
  7. from ...._resource import SyncAPIResource, AsyncAPIResource
  8. from ...._response import (
  9. StreamedBinaryAPIResponse,
  10. AsyncStreamedBinaryAPIResponse,
  11. to_custom_streamed_response_wrapper,
  12. async_to_custom_streamed_response_wrapper,
  13. )
  14. from ...._base_client import make_request_options
  15. __all__ = ["Content", "AsyncContent"]
  16. class Content(SyncAPIResource):
  17. @cached_property
  18. def with_raw_response(self) -> ContentWithRawResponse:
  19. """
  20. This property can be used as a prefix for any HTTP method call to return
  21. the raw response object instead of the parsed content.
  22. For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
  23. """
  24. return ContentWithRawResponse(self)
  25. @cached_property
  26. def with_streaming_response(self) -> ContentWithStreamingResponse:
  27. """
  28. An alternative to `.with_raw_response` that doesn't eagerly read the response body.
  29. For more information, see https://www.github.com/openai/openai-python#with_streaming_response
  30. """
  31. return ContentWithStreamingResponse(self)
  32. def retrieve(
  33. self,
  34. file_id: str,
  35. *,
  36. container_id: str,
  37. # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
  38. # The extra values given here take precedence over values defined on the client or passed to this method.
  39. extra_headers: Headers | None = None,
  40. extra_query: Query | None = None,
  41. extra_body: Body | None = None,
  42. timeout: float | httpx.Timeout | None | NotGiven = not_given,
  43. ) -> _legacy_response.HttpxBinaryResponseContent:
  44. """
  45. Retrieve Container File Content
  46. Args:
  47. extra_headers: Send extra headers
  48. extra_query: Add additional query parameters to the request
  49. extra_body: Add additional JSON properties to the request
  50. timeout: Override the client-level default timeout for this request, in seconds
  51. """
  52. if not container_id:
  53. raise ValueError(f"Expected a non-empty value for `container_id` but received {container_id!r}")
  54. if not file_id:
  55. raise ValueError(f"Expected a non-empty value for `file_id` but received {file_id!r}")
  56. extra_headers = {"Accept": "application/binary", **(extra_headers or {})}
  57. return self._get(
  58. f"/containers/{container_id}/files/{file_id}/content",
  59. options=make_request_options(
  60. extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
  61. ),
  62. cast_to=_legacy_response.HttpxBinaryResponseContent,
  63. )
  64. class AsyncContent(AsyncAPIResource):
  65. @cached_property
  66. def with_raw_response(self) -> AsyncContentWithRawResponse:
  67. """
  68. This property can be used as a prefix for any HTTP method call to return
  69. the raw response object instead of the parsed content.
  70. For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
  71. """
  72. return AsyncContentWithRawResponse(self)
  73. @cached_property
  74. def with_streaming_response(self) -> AsyncContentWithStreamingResponse:
  75. """
  76. An alternative to `.with_raw_response` that doesn't eagerly read the response body.
  77. For more information, see https://www.github.com/openai/openai-python#with_streaming_response
  78. """
  79. return AsyncContentWithStreamingResponse(self)
  80. async def retrieve(
  81. self,
  82. file_id: str,
  83. *,
  84. container_id: str,
  85. # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
  86. # The extra values given here take precedence over values defined on the client or passed to this method.
  87. extra_headers: Headers | None = None,
  88. extra_query: Query | None = None,
  89. extra_body: Body | None = None,
  90. timeout: float | httpx.Timeout | None | NotGiven = not_given,
  91. ) -> _legacy_response.HttpxBinaryResponseContent:
  92. """
  93. Retrieve Container File Content
  94. Args:
  95. extra_headers: Send extra headers
  96. extra_query: Add additional query parameters to the request
  97. extra_body: Add additional JSON properties to the request
  98. timeout: Override the client-level default timeout for this request, in seconds
  99. """
  100. if not container_id:
  101. raise ValueError(f"Expected a non-empty value for `container_id` but received {container_id!r}")
  102. if not file_id:
  103. raise ValueError(f"Expected a non-empty value for `file_id` but received {file_id!r}")
  104. extra_headers = {"Accept": "application/binary", **(extra_headers or {})}
  105. return await self._get(
  106. f"/containers/{container_id}/files/{file_id}/content",
  107. options=make_request_options(
  108. extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
  109. ),
  110. cast_to=_legacy_response.HttpxBinaryResponseContent,
  111. )
  112. class ContentWithRawResponse:
  113. def __init__(self, content: Content) -> None:
  114. self._content = content
  115. self.retrieve = _legacy_response.to_raw_response_wrapper(
  116. content.retrieve,
  117. )
  118. class AsyncContentWithRawResponse:
  119. def __init__(self, content: AsyncContent) -> None:
  120. self._content = content
  121. self.retrieve = _legacy_response.async_to_raw_response_wrapper(
  122. content.retrieve,
  123. )
  124. class ContentWithStreamingResponse:
  125. def __init__(self, content: Content) -> None:
  126. self._content = content
  127. self.retrieve = to_custom_streamed_response_wrapper(
  128. content.retrieve,
  129. StreamedBinaryAPIResponse,
  130. )
  131. class AsyncContentWithStreamingResponse:
  132. def __init__(self, content: AsyncContent) -> None:
  133. self._content = content
  134. self.retrieve = async_to_custom_streamed_response_wrapper(
  135. content.retrieve,
  136. AsyncStreamedBinaryAPIResponse,
  137. )