containers.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
  2. from __future__ import annotations
  3. from typing_extensions import Literal
  4. import httpx
  5. from ... import _legacy_response
  6. from ...types import container_list_params, container_create_params
  7. from ..._types import Body, Omit, Query, Headers, NoneType, NotGiven, SequenceNotStr, omit, not_given
  8. from ..._utils import maybe_transform, async_maybe_transform
  9. from ..._compat import cached_property
  10. from ..._resource import SyncAPIResource, AsyncAPIResource
  11. from ..._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
  12. from .files.files import (
  13. Files,
  14. AsyncFiles,
  15. FilesWithRawResponse,
  16. AsyncFilesWithRawResponse,
  17. FilesWithStreamingResponse,
  18. AsyncFilesWithStreamingResponse,
  19. )
  20. from ...pagination import SyncCursorPage, AsyncCursorPage
  21. from ..._base_client import AsyncPaginator, make_request_options
  22. from ...types.container_list_response import ContainerListResponse
  23. from ...types.container_create_response import ContainerCreateResponse
  24. from ...types.container_retrieve_response import ContainerRetrieveResponse
  25. __all__ = ["Containers", "AsyncContainers"]
  26. class Containers(SyncAPIResource):
  27. @cached_property
  28. def files(self) -> Files:
  29. return Files(self._client)
  30. @cached_property
  31. def with_raw_response(self) -> ContainersWithRawResponse:
  32. """
  33. This property can be used as a prefix for any HTTP method call to return
  34. the raw response object instead of the parsed content.
  35. For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
  36. """
  37. return ContainersWithRawResponse(self)
  38. @cached_property
  39. def with_streaming_response(self) -> ContainersWithStreamingResponse:
  40. """
  41. An alternative to `.with_raw_response` that doesn't eagerly read the response body.
  42. For more information, see https://www.github.com/openai/openai-python#with_streaming_response
  43. """
  44. return ContainersWithStreamingResponse(self)
  45. def create(
  46. self,
  47. *,
  48. name: str,
  49. expires_after: container_create_params.ExpiresAfter | Omit = omit,
  50. file_ids: SequenceNotStr[str] | Omit = omit,
  51. memory_limit: Literal["1g", "4g", "16g", "64g"] | Omit = omit,
  52. # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
  53. # The extra values given here take precedence over values defined on the client or passed to this method.
  54. extra_headers: Headers | None = None,
  55. extra_query: Query | None = None,
  56. extra_body: Body | None = None,
  57. timeout: float | httpx.Timeout | None | NotGiven = not_given,
  58. ) -> ContainerCreateResponse:
  59. """
  60. Create Container
  61. Args:
  62. name: Name of the container to create.
  63. expires_after: Container expiration time in seconds relative to the 'anchor' time.
  64. file_ids: IDs of files to copy to the container.
  65. memory_limit: Optional memory limit for the container. Defaults to "1g".
  66. extra_headers: Send extra headers
  67. extra_query: Add additional query parameters to the request
  68. extra_body: Add additional JSON properties to the request
  69. timeout: Override the client-level default timeout for this request, in seconds
  70. """
  71. return self._post(
  72. "/containers",
  73. body=maybe_transform(
  74. {
  75. "name": name,
  76. "expires_after": expires_after,
  77. "file_ids": file_ids,
  78. "memory_limit": memory_limit,
  79. },
  80. container_create_params.ContainerCreateParams,
  81. ),
  82. options=make_request_options(
  83. extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
  84. ),
  85. cast_to=ContainerCreateResponse,
  86. )
  87. def retrieve(
  88. self,
  89. container_id: str,
  90. *,
  91. # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
  92. # The extra values given here take precedence over values defined on the client or passed to this method.
  93. extra_headers: Headers | None = None,
  94. extra_query: Query | None = None,
  95. extra_body: Body | None = None,
  96. timeout: float | httpx.Timeout | None | NotGiven = not_given,
  97. ) -> ContainerRetrieveResponse:
  98. """
  99. Retrieve Container
  100. Args:
  101. extra_headers: Send extra headers
  102. extra_query: Add additional query parameters to the request
  103. extra_body: Add additional JSON properties to the request
  104. timeout: Override the client-level default timeout for this request, in seconds
  105. """
  106. if not container_id:
  107. raise ValueError(f"Expected a non-empty value for `container_id` but received {container_id!r}")
  108. return self._get(
  109. f"/containers/{container_id}",
  110. options=make_request_options(
  111. extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
  112. ),
  113. cast_to=ContainerRetrieveResponse,
  114. )
  115. def list(
  116. self,
  117. *,
  118. after: str | Omit = omit,
  119. limit: int | Omit = omit,
  120. order: Literal["asc", "desc"] | Omit = omit,
  121. # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
  122. # The extra values given here take precedence over values defined on the client or passed to this method.
  123. extra_headers: Headers | None = None,
  124. extra_query: Query | None = None,
  125. extra_body: Body | None = None,
  126. timeout: float | httpx.Timeout | None | NotGiven = not_given,
  127. ) -> SyncCursorPage[ContainerListResponse]:
  128. """List Containers
  129. Args:
  130. after: A cursor for use in pagination.
  131. `after` is an object ID that defines your place
  132. in the list. For instance, if you make a list request and receive 100 objects,
  133. ending with obj_foo, your subsequent call can include after=obj_foo in order to
  134. fetch the next page of the list.
  135. limit: A limit on the number of objects to be returned. Limit can range between 1 and
  136. 100, and the default is 20.
  137. order: Sort order by the `created_at` timestamp of the objects. `asc` for ascending
  138. order and `desc` for descending order.
  139. extra_headers: Send extra headers
  140. extra_query: Add additional query parameters to the request
  141. extra_body: Add additional JSON properties to the request
  142. timeout: Override the client-level default timeout for this request, in seconds
  143. """
  144. return self._get_api_list(
  145. "/containers",
  146. page=SyncCursorPage[ContainerListResponse],
  147. options=make_request_options(
  148. extra_headers=extra_headers,
  149. extra_query=extra_query,
  150. extra_body=extra_body,
  151. timeout=timeout,
  152. query=maybe_transform(
  153. {
  154. "after": after,
  155. "limit": limit,
  156. "order": order,
  157. },
  158. container_list_params.ContainerListParams,
  159. ),
  160. ),
  161. model=ContainerListResponse,
  162. )
  163. def delete(
  164. self,
  165. container_id: str,
  166. *,
  167. # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
  168. # The extra values given here take precedence over values defined on the client or passed to this method.
  169. extra_headers: Headers | None = None,
  170. extra_query: Query | None = None,
  171. extra_body: Body | None = None,
  172. timeout: float | httpx.Timeout | None | NotGiven = not_given,
  173. ) -> None:
  174. """
  175. Delete Container
  176. Args:
  177. extra_headers: Send extra headers
  178. extra_query: Add additional query parameters to the request
  179. extra_body: Add additional JSON properties to the request
  180. timeout: Override the client-level default timeout for this request, in seconds
  181. """
  182. if not container_id:
  183. raise ValueError(f"Expected a non-empty value for `container_id` but received {container_id!r}")
  184. extra_headers = {"Accept": "*/*", **(extra_headers or {})}
  185. return self._delete(
  186. f"/containers/{container_id}",
  187. options=make_request_options(
  188. extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
  189. ),
  190. cast_to=NoneType,
  191. )
  192. class AsyncContainers(AsyncAPIResource):
  193. @cached_property
  194. def files(self) -> AsyncFiles:
  195. return AsyncFiles(self._client)
  196. @cached_property
  197. def with_raw_response(self) -> AsyncContainersWithRawResponse:
  198. """
  199. This property can be used as a prefix for any HTTP method call to return
  200. the raw response object instead of the parsed content.
  201. For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
  202. """
  203. return AsyncContainersWithRawResponse(self)
  204. @cached_property
  205. def with_streaming_response(self) -> AsyncContainersWithStreamingResponse:
  206. """
  207. An alternative to `.with_raw_response` that doesn't eagerly read the response body.
  208. For more information, see https://www.github.com/openai/openai-python#with_streaming_response
  209. """
  210. return AsyncContainersWithStreamingResponse(self)
  211. async def create(
  212. self,
  213. *,
  214. name: str,
  215. expires_after: container_create_params.ExpiresAfter | Omit = omit,
  216. file_ids: SequenceNotStr[str] | Omit = omit,
  217. memory_limit: Literal["1g", "4g", "16g", "64g"] | Omit = omit,
  218. # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
  219. # The extra values given here take precedence over values defined on the client or passed to this method.
  220. extra_headers: Headers | None = None,
  221. extra_query: Query | None = None,
  222. extra_body: Body | None = None,
  223. timeout: float | httpx.Timeout | None | NotGiven = not_given,
  224. ) -> ContainerCreateResponse:
  225. """
  226. Create Container
  227. Args:
  228. name: Name of the container to create.
  229. expires_after: Container expiration time in seconds relative to the 'anchor' time.
  230. file_ids: IDs of files to copy to the container.
  231. memory_limit: Optional memory limit for the container. Defaults to "1g".
  232. extra_headers: Send extra headers
  233. extra_query: Add additional query parameters to the request
  234. extra_body: Add additional JSON properties to the request
  235. timeout: Override the client-level default timeout for this request, in seconds
  236. """
  237. return await self._post(
  238. "/containers",
  239. body=await async_maybe_transform(
  240. {
  241. "name": name,
  242. "expires_after": expires_after,
  243. "file_ids": file_ids,
  244. "memory_limit": memory_limit,
  245. },
  246. container_create_params.ContainerCreateParams,
  247. ),
  248. options=make_request_options(
  249. extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
  250. ),
  251. cast_to=ContainerCreateResponse,
  252. )
  253. async def retrieve(
  254. self,
  255. container_id: str,
  256. *,
  257. # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
  258. # The extra values given here take precedence over values defined on the client or passed to this method.
  259. extra_headers: Headers | None = None,
  260. extra_query: Query | None = None,
  261. extra_body: Body | None = None,
  262. timeout: float | httpx.Timeout | None | NotGiven = not_given,
  263. ) -> ContainerRetrieveResponse:
  264. """
  265. Retrieve Container
  266. Args:
  267. extra_headers: Send extra headers
  268. extra_query: Add additional query parameters to the request
  269. extra_body: Add additional JSON properties to the request
  270. timeout: Override the client-level default timeout for this request, in seconds
  271. """
  272. if not container_id:
  273. raise ValueError(f"Expected a non-empty value for `container_id` but received {container_id!r}")
  274. return await self._get(
  275. f"/containers/{container_id}",
  276. options=make_request_options(
  277. extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
  278. ),
  279. cast_to=ContainerRetrieveResponse,
  280. )
  281. def list(
  282. self,
  283. *,
  284. after: str | Omit = omit,
  285. limit: int | Omit = omit,
  286. order: Literal["asc", "desc"] | Omit = omit,
  287. # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
  288. # The extra values given here take precedence over values defined on the client or passed to this method.
  289. extra_headers: Headers | None = None,
  290. extra_query: Query | None = None,
  291. extra_body: Body | None = None,
  292. timeout: float | httpx.Timeout | None | NotGiven = not_given,
  293. ) -> AsyncPaginator[ContainerListResponse, AsyncCursorPage[ContainerListResponse]]:
  294. """List Containers
  295. Args:
  296. after: A cursor for use in pagination.
  297. `after` is an object ID that defines your place
  298. in the list. For instance, if you make a list request and receive 100 objects,
  299. ending with obj_foo, your subsequent call can include after=obj_foo in order to
  300. fetch the next page of the list.
  301. limit: A limit on the number of objects to be returned. Limit can range between 1 and
  302. 100, and the default is 20.
  303. order: Sort order by the `created_at` timestamp of the objects. `asc` for ascending
  304. order and `desc` for descending order.
  305. extra_headers: Send extra headers
  306. extra_query: Add additional query parameters to the request
  307. extra_body: Add additional JSON properties to the request
  308. timeout: Override the client-level default timeout for this request, in seconds
  309. """
  310. return self._get_api_list(
  311. "/containers",
  312. page=AsyncCursorPage[ContainerListResponse],
  313. options=make_request_options(
  314. extra_headers=extra_headers,
  315. extra_query=extra_query,
  316. extra_body=extra_body,
  317. timeout=timeout,
  318. query=maybe_transform(
  319. {
  320. "after": after,
  321. "limit": limit,
  322. "order": order,
  323. },
  324. container_list_params.ContainerListParams,
  325. ),
  326. ),
  327. model=ContainerListResponse,
  328. )
  329. async def delete(
  330. self,
  331. container_id: str,
  332. *,
  333. # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
  334. # The extra values given here take precedence over values defined on the client or passed to this method.
  335. extra_headers: Headers | None = None,
  336. extra_query: Query | None = None,
  337. extra_body: Body | None = None,
  338. timeout: float | httpx.Timeout | None | NotGiven = not_given,
  339. ) -> None:
  340. """
  341. Delete Container
  342. Args:
  343. extra_headers: Send extra headers
  344. extra_query: Add additional query parameters to the request
  345. extra_body: Add additional JSON properties to the request
  346. timeout: Override the client-level default timeout for this request, in seconds
  347. """
  348. if not container_id:
  349. raise ValueError(f"Expected a non-empty value for `container_id` but received {container_id!r}")
  350. extra_headers = {"Accept": "*/*", **(extra_headers or {})}
  351. return await self._delete(
  352. f"/containers/{container_id}",
  353. options=make_request_options(
  354. extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
  355. ),
  356. cast_to=NoneType,
  357. )
  358. class ContainersWithRawResponse:
  359. def __init__(self, containers: Containers) -> None:
  360. self._containers = containers
  361. self.create = _legacy_response.to_raw_response_wrapper(
  362. containers.create,
  363. )
  364. self.retrieve = _legacy_response.to_raw_response_wrapper(
  365. containers.retrieve,
  366. )
  367. self.list = _legacy_response.to_raw_response_wrapper(
  368. containers.list,
  369. )
  370. self.delete = _legacy_response.to_raw_response_wrapper(
  371. containers.delete,
  372. )
  373. @cached_property
  374. def files(self) -> FilesWithRawResponse:
  375. return FilesWithRawResponse(self._containers.files)
  376. class AsyncContainersWithRawResponse:
  377. def __init__(self, containers: AsyncContainers) -> None:
  378. self._containers = containers
  379. self.create = _legacy_response.async_to_raw_response_wrapper(
  380. containers.create,
  381. )
  382. self.retrieve = _legacy_response.async_to_raw_response_wrapper(
  383. containers.retrieve,
  384. )
  385. self.list = _legacy_response.async_to_raw_response_wrapper(
  386. containers.list,
  387. )
  388. self.delete = _legacy_response.async_to_raw_response_wrapper(
  389. containers.delete,
  390. )
  391. @cached_property
  392. def files(self) -> AsyncFilesWithRawResponse:
  393. return AsyncFilesWithRawResponse(self._containers.files)
  394. class ContainersWithStreamingResponse:
  395. def __init__(self, containers: Containers) -> None:
  396. self._containers = containers
  397. self.create = to_streamed_response_wrapper(
  398. containers.create,
  399. )
  400. self.retrieve = to_streamed_response_wrapper(
  401. containers.retrieve,
  402. )
  403. self.list = to_streamed_response_wrapper(
  404. containers.list,
  405. )
  406. self.delete = to_streamed_response_wrapper(
  407. containers.delete,
  408. )
  409. @cached_property
  410. def files(self) -> FilesWithStreamingResponse:
  411. return FilesWithStreamingResponse(self._containers.files)
  412. class AsyncContainersWithStreamingResponse:
  413. def __init__(self, containers: AsyncContainers) -> None:
  414. self._containers = containers
  415. self.create = async_to_streamed_response_wrapper(
  416. containers.create,
  417. )
  418. self.retrieve = async_to_streamed_response_wrapper(
  419. containers.retrieve,
  420. )
  421. self.list = async_to_streamed_response_wrapper(
  422. containers.list,
  423. )
  424. self.delete = async_to_streamed_response_wrapper(
  425. containers.delete,
  426. )
  427. @cached_property
  428. def files(self) -> AsyncFilesWithStreamingResponse:
  429. return AsyncFilesWithStreamingResponse(self._containers.files)