|
| 1 | +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +import httpx |
| 6 | + |
| 7 | +from ..._files import read_file_content |
| 8 | +from ..._types import Body, Query, Headers, NotGiven, FileContent, not_given |
| 9 | +from ..._compat import cached_property |
| 10 | +from ..._resource import SyncAPIResource, AsyncAPIResource |
| 11 | +from ..._response import ( |
| 12 | + to_raw_response_wrapper, |
| 13 | + to_streamed_response_wrapper, |
| 14 | + async_to_raw_response_wrapper, |
| 15 | + async_to_streamed_response_wrapper, |
| 16 | +) |
| 17 | +from ...pagination import SyncSinglePage, AsyncSinglePage |
| 18 | +from ..._base_client import AsyncPaginator, make_request_options |
| 19 | +from ...types.ai.to_markdown_transform_response import ToMarkdownTransformResponse |
| 20 | + |
| 21 | +__all__ = ["ToMarkdownResource", "AsyncToMarkdownResource"] |
| 22 | + |
| 23 | + |
| 24 | +class ToMarkdownResource(SyncAPIResource): |
| 25 | + @cached_property |
| 26 | + def with_raw_response(self) -> ToMarkdownResourceWithRawResponse: |
| 27 | + """ |
| 28 | + This property can be used as a prefix for any HTTP method call to return |
| 29 | + the raw response object instead of the parsed content. |
| 30 | +
|
| 31 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers |
| 32 | + """ |
| 33 | + return ToMarkdownResourceWithRawResponse(self) |
| 34 | + |
| 35 | + @cached_property |
| 36 | + def with_streaming_response(self) -> ToMarkdownResourceWithStreamingResponse: |
| 37 | + """ |
| 38 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 39 | +
|
| 40 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response |
| 41 | + """ |
| 42 | + return ToMarkdownResourceWithStreamingResponse(self) |
| 43 | + |
| 44 | + def transform( |
| 45 | + self, |
| 46 | + body: FileContent, |
| 47 | + *, |
| 48 | + account_id: str, |
| 49 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 50 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 51 | + extra_headers: Headers | None = None, |
| 52 | + extra_query: Query | None = None, |
| 53 | + extra_body: Body | None = None, |
| 54 | + timeout: float | httpx.Timeout | None | NotGiven = not_given, |
| 55 | + ) -> SyncSinglePage[ToMarkdownTransformResponse]: |
| 56 | + """ |
| 57 | + Convert Files into Markdown |
| 58 | +
|
| 59 | + Args: |
| 60 | + extra_headers: Send extra headers |
| 61 | +
|
| 62 | + extra_query: Add additional query parameters to the request |
| 63 | +
|
| 64 | + extra_body: Add additional JSON properties to the request |
| 65 | +
|
| 66 | + timeout: Override the client-level default timeout for this request, in seconds |
| 67 | + """ |
| 68 | + if not account_id: |
| 69 | + raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}") |
| 70 | + extra_headers = {"Content-Type": "application/octet-stream", **(extra_headers or {})} |
| 71 | + return self._get_api_list( |
| 72 | + f"/accounts/{account_id}/ai/tomarkdown", |
| 73 | + page=SyncSinglePage[ToMarkdownTransformResponse], |
| 74 | + body=read_file_content(body), |
| 75 | + options=make_request_options( |
| 76 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 77 | + ), |
| 78 | + model=ToMarkdownTransformResponse, |
| 79 | + method="post", |
| 80 | + ) |
| 81 | + |
| 82 | + |
| 83 | +class AsyncToMarkdownResource(AsyncAPIResource): |
| 84 | + @cached_property |
| 85 | + def with_raw_response(self) -> AsyncToMarkdownResourceWithRawResponse: |
| 86 | + """ |
| 87 | + This property can be used as a prefix for any HTTP method call to return |
| 88 | + the raw response object instead of the parsed content. |
| 89 | +
|
| 90 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers |
| 91 | + """ |
| 92 | + return AsyncToMarkdownResourceWithRawResponse(self) |
| 93 | + |
| 94 | + @cached_property |
| 95 | + def with_streaming_response(self) -> AsyncToMarkdownResourceWithStreamingResponse: |
| 96 | + """ |
| 97 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 98 | +
|
| 99 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response |
| 100 | + """ |
| 101 | + return AsyncToMarkdownResourceWithStreamingResponse(self) |
| 102 | + |
| 103 | + def transform( |
| 104 | + self, |
| 105 | + body: FileContent, |
| 106 | + *, |
| 107 | + account_id: str, |
| 108 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 109 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 110 | + extra_headers: Headers | None = None, |
| 111 | + extra_query: Query | None = None, |
| 112 | + extra_body: Body | None = None, |
| 113 | + timeout: float | httpx.Timeout | None | NotGiven = not_given, |
| 114 | + ) -> AsyncPaginator[ToMarkdownTransformResponse, AsyncSinglePage[ToMarkdownTransformResponse]]: |
| 115 | + """ |
| 116 | + Convert Files into Markdown |
| 117 | +
|
| 118 | + Args: |
| 119 | + extra_headers: Send extra headers |
| 120 | +
|
| 121 | + extra_query: Add additional query parameters to the request |
| 122 | +
|
| 123 | + extra_body: Add additional JSON properties to the request |
| 124 | +
|
| 125 | + timeout: Override the client-level default timeout for this request, in seconds |
| 126 | + """ |
| 127 | + if not account_id: |
| 128 | + raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}") |
| 129 | + extra_headers = {"Content-Type": "application/octet-stream", **(extra_headers or {})} |
| 130 | + return self._get_api_list( |
| 131 | + f"/accounts/{account_id}/ai/tomarkdown", |
| 132 | + page=AsyncSinglePage[ToMarkdownTransformResponse], |
| 133 | + body=read_file_content(body), |
| 134 | + options=make_request_options( |
| 135 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 136 | + ), |
| 137 | + model=ToMarkdownTransformResponse, |
| 138 | + method="post", |
| 139 | + ) |
| 140 | + |
| 141 | + |
| 142 | +class ToMarkdownResourceWithRawResponse: |
| 143 | + def __init__(self, to_markdown: ToMarkdownResource) -> None: |
| 144 | + self._to_markdown = to_markdown |
| 145 | + |
| 146 | + self.transform = to_raw_response_wrapper( |
| 147 | + to_markdown.transform, |
| 148 | + ) |
| 149 | + |
| 150 | + |
| 151 | +class AsyncToMarkdownResourceWithRawResponse: |
| 152 | + def __init__(self, to_markdown: AsyncToMarkdownResource) -> None: |
| 153 | + self._to_markdown = to_markdown |
| 154 | + |
| 155 | + self.transform = async_to_raw_response_wrapper( |
| 156 | + to_markdown.transform, |
| 157 | + ) |
| 158 | + |
| 159 | + |
| 160 | +class ToMarkdownResourceWithStreamingResponse: |
| 161 | + def __init__(self, to_markdown: ToMarkdownResource) -> None: |
| 162 | + self._to_markdown = to_markdown |
| 163 | + |
| 164 | + self.transform = to_streamed_response_wrapper( |
| 165 | + to_markdown.transform, |
| 166 | + ) |
| 167 | + |
| 168 | + |
| 169 | +class AsyncToMarkdownResourceWithStreamingResponse: |
| 170 | + def __init__(self, to_markdown: AsyncToMarkdownResource) -> None: |
| 171 | + self._to_markdown = to_markdown |
| 172 | + |
| 173 | + self.transform = async_to_streamed_response_wrapper( |
| 174 | + to_markdown.transform, |
| 175 | + ) |
0 commit comments