|
| 1 | +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from typing import Iterable |
| 6 | + |
| 7 | +import httpx |
| 8 | + |
| 9 | +from ..types import vision_analyze_images_params |
| 10 | +from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven |
| 11 | +from .._utils import ( |
| 12 | + maybe_transform, |
| 13 | + async_maybe_transform, |
| 14 | +) |
| 15 | +from .._compat import cached_property |
| 16 | +from .._resource import SyncAPIResource, AsyncAPIResource |
| 17 | +from .._response import ( |
| 18 | + to_raw_response_wrapper, |
| 19 | + to_streamed_response_wrapper, |
| 20 | + async_to_raw_response_wrapper, |
| 21 | + async_to_streamed_response_wrapper, |
| 22 | +) |
| 23 | +from .._base_client import make_request_options |
| 24 | +from ..types.vision_response import VisionResponse |
| 25 | + |
| 26 | +__all__ = ["VisionResource", "AsyncVisionResource"] |
| 27 | + |
| 28 | + |
| 29 | +class VisionResource(SyncAPIResource): |
| 30 | + @cached_property |
| 31 | + def with_raw_response(self) -> VisionResourceWithRawResponse: |
| 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 | +
|
| 36 | + For more information, see https://www.github.com/writer/writer-python#accessing-raw-response-data-eg-headers |
| 37 | + """ |
| 38 | + return VisionResourceWithRawResponse(self) |
| 39 | + |
| 40 | + @cached_property |
| 41 | + def with_streaming_response(self) -> VisionResourceWithStreamingResponse: |
| 42 | + """ |
| 43 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 44 | +
|
| 45 | + For more information, see https://www.github.com/writer/writer-python#with_streaming_response |
| 46 | + """ |
| 47 | + return VisionResourceWithStreamingResponse(self) |
| 48 | + |
| 49 | + def analyze_images( |
| 50 | + self, |
| 51 | + *, |
| 52 | + model: str, |
| 53 | + prompt: str, |
| 54 | + variables: Iterable[vision_analyze_images_params.Variable], |
| 55 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 56 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 57 | + extra_headers: Headers | None = None, |
| 58 | + extra_query: Query | None = None, |
| 59 | + extra_body: Body | None = None, |
| 60 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 61 | + ) -> VisionResponse: |
| 62 | + """ |
| 63 | + Submit images and a prompt to generate an analysis of the images. |
| 64 | +
|
| 65 | + Args: |
| 66 | + model: The model to be used for image analysis. Currently only supports |
| 67 | + `palmyra-vision`. |
| 68 | +
|
| 69 | + prompt: The prompt to use for the image analysis. The prompt must include the name of |
| 70 | + each image variable, surrounded by double curly braces (`{{}}`). For example, |
| 71 | + `Describe the difference between the image {{image_1}} and the image {{image_2}}`. |
| 72 | +
|
| 73 | + extra_headers: Send extra headers |
| 74 | +
|
| 75 | + extra_query: Add additional query parameters to the request |
| 76 | +
|
| 77 | + extra_body: Add additional JSON properties to the request |
| 78 | +
|
| 79 | + timeout: Override the client-level default timeout for this request, in seconds |
| 80 | + """ |
| 81 | + return self._post( |
| 82 | + "/v1/vision", |
| 83 | + body=maybe_transform( |
| 84 | + { |
| 85 | + "model": model, |
| 86 | + "prompt": prompt, |
| 87 | + "variables": variables, |
| 88 | + }, |
| 89 | + vision_analyze_images_params.VisionAnalyzeImagesParams, |
| 90 | + ), |
| 91 | + options=make_request_options( |
| 92 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 93 | + ), |
| 94 | + cast_to=VisionResponse, |
| 95 | + ) |
| 96 | + |
| 97 | + |
| 98 | +class AsyncVisionResource(AsyncAPIResource): |
| 99 | + @cached_property |
| 100 | + def with_raw_response(self) -> AsyncVisionResourceWithRawResponse: |
| 101 | + """ |
| 102 | + This property can be used as a prefix for any HTTP method call to return |
| 103 | + the raw response object instead of the parsed content. |
| 104 | +
|
| 105 | + For more information, see https://www.github.com/writer/writer-python#accessing-raw-response-data-eg-headers |
| 106 | + """ |
| 107 | + return AsyncVisionResourceWithRawResponse(self) |
| 108 | + |
| 109 | + @cached_property |
| 110 | + def with_streaming_response(self) -> AsyncVisionResourceWithStreamingResponse: |
| 111 | + """ |
| 112 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 113 | +
|
| 114 | + For more information, see https://www.github.com/writer/writer-python#with_streaming_response |
| 115 | + """ |
| 116 | + return AsyncVisionResourceWithStreamingResponse(self) |
| 117 | + |
| 118 | + async def analyze_images( |
| 119 | + self, |
| 120 | + *, |
| 121 | + model: str, |
| 122 | + prompt: str, |
| 123 | + variables: Iterable[vision_analyze_images_params.Variable], |
| 124 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 125 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 126 | + extra_headers: Headers | None = None, |
| 127 | + extra_query: Query | None = None, |
| 128 | + extra_body: Body | None = None, |
| 129 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 130 | + ) -> VisionResponse: |
| 131 | + """ |
| 132 | + Submit images and a prompt to generate an analysis of the images. |
| 133 | +
|
| 134 | + Args: |
| 135 | + model: The model to be used for image analysis. Currently only supports |
| 136 | + `palmyra-vision`. |
| 137 | +
|
| 138 | + prompt: The prompt to use for the image analysis. The prompt must include the name of |
| 139 | + each image variable, surrounded by double curly braces (`{{}}`). For example, |
| 140 | + `Describe the difference between the image {{image_1}} and the image {{image_2}}`. |
| 141 | +
|
| 142 | + extra_headers: Send extra headers |
| 143 | +
|
| 144 | + extra_query: Add additional query parameters to the request |
| 145 | +
|
| 146 | + extra_body: Add additional JSON properties to the request |
| 147 | +
|
| 148 | + timeout: Override the client-level default timeout for this request, in seconds |
| 149 | + """ |
| 150 | + return await self._post( |
| 151 | + "/v1/vision", |
| 152 | + body=await async_maybe_transform( |
| 153 | + { |
| 154 | + "model": model, |
| 155 | + "prompt": prompt, |
| 156 | + "variables": variables, |
| 157 | + }, |
| 158 | + vision_analyze_images_params.VisionAnalyzeImagesParams, |
| 159 | + ), |
| 160 | + options=make_request_options( |
| 161 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 162 | + ), |
| 163 | + cast_to=VisionResponse, |
| 164 | + ) |
| 165 | + |
| 166 | + |
| 167 | +class VisionResourceWithRawResponse: |
| 168 | + def __init__(self, vision: VisionResource) -> None: |
| 169 | + self._vision = vision |
| 170 | + |
| 171 | + self.analyze_images = to_raw_response_wrapper( |
| 172 | + vision.analyze_images, |
| 173 | + ) |
| 174 | + |
| 175 | + |
| 176 | +class AsyncVisionResourceWithRawResponse: |
| 177 | + def __init__(self, vision: AsyncVisionResource) -> None: |
| 178 | + self._vision = vision |
| 179 | + |
| 180 | + self.analyze_images = async_to_raw_response_wrapper( |
| 181 | + vision.analyze_images, |
| 182 | + ) |
| 183 | + |
| 184 | + |
| 185 | +class VisionResourceWithStreamingResponse: |
| 186 | + def __init__(self, vision: VisionResource) -> None: |
| 187 | + self._vision = vision |
| 188 | + |
| 189 | + self.analyze_images = to_streamed_response_wrapper( |
| 190 | + vision.analyze_images, |
| 191 | + ) |
| 192 | + |
| 193 | + |
| 194 | +class AsyncVisionResourceWithStreamingResponse: |
| 195 | + def __init__(self, vision: AsyncVisionResource) -> None: |
| 196 | + self._vision = vision |
| 197 | + |
| 198 | + self.analyze_images = async_to_streamed_response_wrapper( |
| 199 | + vision.analyze_images, |
| 200 | + ) |
0 commit comments