|
| 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 List, Union |
| 6 | + |
| 7 | +import httpx |
| 8 | + |
| 9 | +from ..types import moderation_create_params |
| 10 | +from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven |
| 11 | +from .._utils import maybe_transform, async_maybe_transform |
| 12 | +from .._compat import cached_property |
| 13 | +from .._resource import SyncAPIResource, AsyncAPIResource |
| 14 | +from .._response import ( |
| 15 | + to_raw_response_wrapper, |
| 16 | + to_streamed_response_wrapper, |
| 17 | + async_to_raw_response_wrapper, |
| 18 | + async_to_streamed_response_wrapper, |
| 19 | +) |
| 20 | +from .._base_client import make_request_options |
| 21 | +from ..types.create_response import CreateResponse |
| 22 | + |
| 23 | +__all__ = ["ModerationsResource", "AsyncModerationsResource"] |
| 24 | + |
| 25 | + |
| 26 | +class ModerationsResource(SyncAPIResource): |
| 27 | + @cached_property |
| 28 | + def with_raw_response(self) -> ModerationsResourceWithRawResponse: |
| 29 | + """ |
| 30 | + This property can be used as a prefix for any HTTP method call to return |
| 31 | + the raw response object instead of the parsed content. |
| 32 | +
|
| 33 | + For more information, see https://www.github.com/llamastack/llama-stack-client-python#accessing-raw-response-data-eg-headers |
| 34 | + """ |
| 35 | + return ModerationsResourceWithRawResponse(self) |
| 36 | + |
| 37 | + @cached_property |
| 38 | + def with_streaming_response(self) -> ModerationsResourceWithStreamingResponse: |
| 39 | + """ |
| 40 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 41 | +
|
| 42 | + For more information, see https://www.github.com/llamastack/llama-stack-client-python#with_streaming_response |
| 43 | + """ |
| 44 | + return ModerationsResourceWithStreamingResponse(self) |
| 45 | + |
| 46 | + def create( |
| 47 | + self, |
| 48 | + *, |
| 49 | + input: Union[str, List[str]], |
| 50 | + model: str, |
| 51 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 52 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 53 | + extra_headers: Headers | None = None, |
| 54 | + extra_query: Query | None = None, |
| 55 | + extra_body: Body | None = None, |
| 56 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 57 | + ) -> CreateResponse: |
| 58 | + """ |
| 59 | + Classifies if text and/or image inputs are potentially harmful. |
| 60 | +
|
| 61 | + Args: |
| 62 | + input: Input (or inputs) to classify. Can be a single string, an array of strings, or |
| 63 | + an array of multi-modal input objects similar to other models. |
| 64 | +
|
| 65 | + model: The content moderation model you would like to use. |
| 66 | +
|
| 67 | + extra_headers: Send extra headers |
| 68 | +
|
| 69 | + extra_query: Add additional query parameters to the request |
| 70 | +
|
| 71 | + extra_body: Add additional JSON properties to the request |
| 72 | +
|
| 73 | + timeout: Override the client-level default timeout for this request, in seconds |
| 74 | + """ |
| 75 | + return self._post( |
| 76 | + "/v1/openai/v1/moderations", |
| 77 | + body=maybe_transform( |
| 78 | + { |
| 79 | + "input": input, |
| 80 | + "model": model, |
| 81 | + }, |
| 82 | + moderation_create_params.ModerationCreateParams, |
| 83 | + ), |
| 84 | + options=make_request_options( |
| 85 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 86 | + ), |
| 87 | + cast_to=CreateResponse, |
| 88 | + ) |
| 89 | + |
| 90 | + |
| 91 | +class AsyncModerationsResource(AsyncAPIResource): |
| 92 | + @cached_property |
| 93 | + def with_raw_response(self) -> AsyncModerationsResourceWithRawResponse: |
| 94 | + """ |
| 95 | + This property can be used as a prefix for any HTTP method call to return |
| 96 | + the raw response object instead of the parsed content. |
| 97 | +
|
| 98 | + For more information, see https://www.github.com/llamastack/llama-stack-client-python#accessing-raw-response-data-eg-headers |
| 99 | + """ |
| 100 | + return AsyncModerationsResourceWithRawResponse(self) |
| 101 | + |
| 102 | + @cached_property |
| 103 | + def with_streaming_response(self) -> AsyncModerationsResourceWithStreamingResponse: |
| 104 | + """ |
| 105 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 106 | +
|
| 107 | + For more information, see https://www.github.com/llamastack/llama-stack-client-python#with_streaming_response |
| 108 | + """ |
| 109 | + return AsyncModerationsResourceWithStreamingResponse(self) |
| 110 | + |
| 111 | + async def create( |
| 112 | + self, |
| 113 | + *, |
| 114 | + input: Union[str, List[str]], |
| 115 | + model: str, |
| 116 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 117 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 118 | + extra_headers: Headers | None = None, |
| 119 | + extra_query: Query | None = None, |
| 120 | + extra_body: Body | None = None, |
| 121 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 122 | + ) -> CreateResponse: |
| 123 | + """ |
| 124 | + Classifies if text and/or image inputs are potentially harmful. |
| 125 | +
|
| 126 | + Args: |
| 127 | + input: Input (or inputs) to classify. Can be a single string, an array of strings, or |
| 128 | + an array of multi-modal input objects similar to other models. |
| 129 | +
|
| 130 | + model: The content moderation model you would like to use. |
| 131 | +
|
| 132 | + extra_headers: Send extra headers |
| 133 | +
|
| 134 | + extra_query: Add additional query parameters to the request |
| 135 | +
|
| 136 | + extra_body: Add additional JSON properties to the request |
| 137 | +
|
| 138 | + timeout: Override the client-level default timeout for this request, in seconds |
| 139 | + """ |
| 140 | + return await self._post( |
| 141 | + "/v1/openai/v1/moderations", |
| 142 | + body=await async_maybe_transform( |
| 143 | + { |
| 144 | + "input": input, |
| 145 | + "model": model, |
| 146 | + }, |
| 147 | + moderation_create_params.ModerationCreateParams, |
| 148 | + ), |
| 149 | + options=make_request_options( |
| 150 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 151 | + ), |
| 152 | + cast_to=CreateResponse, |
| 153 | + ) |
| 154 | + |
| 155 | + |
| 156 | +class ModerationsResourceWithRawResponse: |
| 157 | + def __init__(self, moderations: ModerationsResource) -> None: |
| 158 | + self._moderations = moderations |
| 159 | + |
| 160 | + self.create = to_raw_response_wrapper( |
| 161 | + moderations.create, |
| 162 | + ) |
| 163 | + |
| 164 | + |
| 165 | +class AsyncModerationsResourceWithRawResponse: |
| 166 | + def __init__(self, moderations: AsyncModerationsResource) -> None: |
| 167 | + self._moderations = moderations |
| 168 | + |
| 169 | + self.create = async_to_raw_response_wrapper( |
| 170 | + moderations.create, |
| 171 | + ) |
| 172 | + |
| 173 | + |
| 174 | +class ModerationsResourceWithStreamingResponse: |
| 175 | + def __init__(self, moderations: ModerationsResource) -> None: |
| 176 | + self._moderations = moderations |
| 177 | + |
| 178 | + self.create = to_streamed_response_wrapper( |
| 179 | + moderations.create, |
| 180 | + ) |
| 181 | + |
| 182 | + |
| 183 | +class AsyncModerationsResourceWithStreamingResponse: |
| 184 | + def __init__(self, moderations: AsyncModerationsResource) -> None: |
| 185 | + self._moderations = moderations |
| 186 | + |
| 187 | + self.create = async_to_streamed_response_wrapper( |
| 188 | + moderations.create, |
| 189 | + ) |
0 commit comments