langfuse.api.prompt_version.raw_client

  1# This file was auto-generated by Fern from our API Definition.
  2
  3import typing
  4from json.decoder import JSONDecodeError
  5
  6from ..commons.errors.access_denied_error import AccessDeniedError
  7from ..commons.errors.error import Error
  8from ..commons.errors.method_not_allowed_error import MethodNotAllowedError
  9from ..commons.errors.not_found_error import NotFoundError
 10from ..commons.errors.unauthorized_error import UnauthorizedError
 11from ..core.api_error import ApiError
 12from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
 13from ..core.http_response import AsyncHttpResponse, HttpResponse
 14from ..core.jsonable_encoder import jsonable_encoder
 15from ..core.pydantic_utilities import parse_obj_as
 16from ..core.request_options import RequestOptions
 17from ..prompts.types.prompt import Prompt
 18
 19# this is used as the default value for optional parameters
 20OMIT = typing.cast(typing.Any, ...)
 21
 22
 23class RawPromptVersionClient:
 24    def __init__(self, *, client_wrapper: SyncClientWrapper):
 25        self._client_wrapper = client_wrapper
 26
 27    def update(
 28        self,
 29        name: str,
 30        version: int,
 31        *,
 32        new_labels: typing.Sequence[str],
 33        request_options: typing.Optional[RequestOptions] = None,
 34    ) -> HttpResponse[Prompt]:
 35        """
 36        Update labels for a specific prompt version
 37
 38        Parameters
 39        ----------
 40        name : str
 41            The name of the prompt. If the prompt is in a folder (e.g., "folder/subfolder/prompt-name"),
 42            the folder path must be URL encoded.
 43
 44        version : int
 45            Version of the prompt to update
 46
 47        new_labels : typing.Sequence[str]
 48            New labels for the prompt version. Labels are unique across versions. The "latest" label is reserved and managed by Langfuse.
 49
 50        request_options : typing.Optional[RequestOptions]
 51            Request-specific configuration.
 52
 53        Returns
 54        -------
 55        HttpResponse[Prompt]
 56        """
 57        _response = self._client_wrapper.httpx_client.request(
 58            f"api/public/v2/prompts/{jsonable_encoder(name)}/versions/{jsonable_encoder(version)}",
 59            method="PATCH",
 60            json={
 61                "newLabels": new_labels,
 62            },
 63            request_options=request_options,
 64            omit=OMIT,
 65        )
 66        try:
 67            if 200 <= _response.status_code < 300:
 68                _data = typing.cast(
 69                    Prompt,
 70                    parse_obj_as(
 71                        type_=Prompt,  # type: ignore
 72                        object_=_response.json(),
 73                    ),
 74                )
 75                return HttpResponse(response=_response, data=_data)
 76            if _response.status_code == 400:
 77                raise Error(
 78                    headers=dict(_response.headers),
 79                    body=typing.cast(
 80                        typing.Any,
 81                        parse_obj_as(
 82                            type_=typing.Any,  # type: ignore
 83                            object_=_response.json(),
 84                        ),
 85                    ),
 86                )
 87            if _response.status_code == 401:
 88                raise UnauthorizedError(
 89                    headers=dict(_response.headers),
 90                    body=typing.cast(
 91                        typing.Any,
 92                        parse_obj_as(
 93                            type_=typing.Any,  # type: ignore
 94                            object_=_response.json(),
 95                        ),
 96                    ),
 97                )
 98            if _response.status_code == 403:
 99                raise AccessDeniedError(
100                    headers=dict(_response.headers),
101                    body=typing.cast(
102                        typing.Any,
103                        parse_obj_as(
104                            type_=typing.Any,  # type: ignore
105                            object_=_response.json(),
106                        ),
107                    ),
108                )
109            if _response.status_code == 405:
110                raise MethodNotAllowedError(
111                    headers=dict(_response.headers),
112                    body=typing.cast(
113                        typing.Any,
114                        parse_obj_as(
115                            type_=typing.Any,  # type: ignore
116                            object_=_response.json(),
117                        ),
118                    ),
119                )
120            if _response.status_code == 404:
121                raise NotFoundError(
122                    headers=dict(_response.headers),
123                    body=typing.cast(
124                        typing.Any,
125                        parse_obj_as(
126                            type_=typing.Any,  # type: ignore
127                            object_=_response.json(),
128                        ),
129                    ),
130                )
131            _response_json = _response.json()
132        except JSONDecodeError:
133            raise ApiError(
134                status_code=_response.status_code,
135                headers=dict(_response.headers),
136                body=_response.text,
137            )
138        raise ApiError(
139            status_code=_response.status_code,
140            headers=dict(_response.headers),
141            body=_response_json,
142        )
143
144
145class AsyncRawPromptVersionClient:
146    def __init__(self, *, client_wrapper: AsyncClientWrapper):
147        self._client_wrapper = client_wrapper
148
149    async def update(
150        self,
151        name: str,
152        version: int,
153        *,
154        new_labels: typing.Sequence[str],
155        request_options: typing.Optional[RequestOptions] = None,
156    ) -> AsyncHttpResponse[Prompt]:
157        """
158        Update labels for a specific prompt version
159
160        Parameters
161        ----------
162        name : str
163            The name of the prompt. If the prompt is in a folder (e.g., "folder/subfolder/prompt-name"),
164            the folder path must be URL encoded.
165
166        version : int
167            Version of the prompt to update
168
169        new_labels : typing.Sequence[str]
170            New labels for the prompt version. Labels are unique across versions. The "latest" label is reserved and managed by Langfuse.
171
172        request_options : typing.Optional[RequestOptions]
173            Request-specific configuration.
174
175        Returns
176        -------
177        AsyncHttpResponse[Prompt]
178        """
179        _response = await self._client_wrapper.httpx_client.request(
180            f"api/public/v2/prompts/{jsonable_encoder(name)}/versions/{jsonable_encoder(version)}",
181            method="PATCH",
182            json={
183                "newLabels": new_labels,
184            },
185            request_options=request_options,
186            omit=OMIT,
187        )
188        try:
189            if 200 <= _response.status_code < 300:
190                _data = typing.cast(
191                    Prompt,
192                    parse_obj_as(
193                        type_=Prompt,  # type: ignore
194                        object_=_response.json(),
195                    ),
196                )
197                return AsyncHttpResponse(response=_response, data=_data)
198            if _response.status_code == 400:
199                raise Error(
200                    headers=dict(_response.headers),
201                    body=typing.cast(
202                        typing.Any,
203                        parse_obj_as(
204                            type_=typing.Any,  # type: ignore
205                            object_=_response.json(),
206                        ),
207                    ),
208                )
209            if _response.status_code == 401:
210                raise UnauthorizedError(
211                    headers=dict(_response.headers),
212                    body=typing.cast(
213                        typing.Any,
214                        parse_obj_as(
215                            type_=typing.Any,  # type: ignore
216                            object_=_response.json(),
217                        ),
218                    ),
219                )
220            if _response.status_code == 403:
221                raise AccessDeniedError(
222                    headers=dict(_response.headers),
223                    body=typing.cast(
224                        typing.Any,
225                        parse_obj_as(
226                            type_=typing.Any,  # type: ignore
227                            object_=_response.json(),
228                        ),
229                    ),
230                )
231            if _response.status_code == 405:
232                raise MethodNotAllowedError(
233                    headers=dict(_response.headers),
234                    body=typing.cast(
235                        typing.Any,
236                        parse_obj_as(
237                            type_=typing.Any,  # type: ignore
238                            object_=_response.json(),
239                        ),
240                    ),
241                )
242            if _response.status_code == 404:
243                raise NotFoundError(
244                    headers=dict(_response.headers),
245                    body=typing.cast(
246                        typing.Any,
247                        parse_obj_as(
248                            type_=typing.Any,  # type: ignore
249                            object_=_response.json(),
250                        ),
251                    ),
252                )
253            _response_json = _response.json()
254        except JSONDecodeError:
255            raise ApiError(
256                status_code=_response.status_code,
257                headers=dict(_response.headers),
258                body=_response.text,
259            )
260        raise ApiError(
261            status_code=_response.status_code,
262            headers=dict(_response.headers),
263            body=_response_json,
264        )
OMIT = Ellipsis
class RawPromptVersionClient:
 24class RawPromptVersionClient:
 25    def __init__(self, *, client_wrapper: SyncClientWrapper):
 26        self._client_wrapper = client_wrapper
 27
 28    def update(
 29        self,
 30        name: str,
 31        version: int,
 32        *,
 33        new_labels: typing.Sequence[str],
 34        request_options: typing.Optional[RequestOptions] = None,
 35    ) -> HttpResponse[Prompt]:
 36        """
 37        Update labels for a specific prompt version
 38
 39        Parameters
 40        ----------
 41        name : str
 42            The name of the prompt. If the prompt is in a folder (e.g., "folder/subfolder/prompt-name"),
 43            the folder path must be URL encoded.
 44
 45        version : int
 46            Version of the prompt to update
 47
 48        new_labels : typing.Sequence[str]
 49            New labels for the prompt version. Labels are unique across versions. The "latest" label is reserved and managed by Langfuse.
 50
 51        request_options : typing.Optional[RequestOptions]
 52            Request-specific configuration.
 53
 54        Returns
 55        -------
 56        HttpResponse[Prompt]
 57        """
 58        _response = self._client_wrapper.httpx_client.request(
 59            f"api/public/v2/prompts/{jsonable_encoder(name)}/versions/{jsonable_encoder(version)}",
 60            method="PATCH",
 61            json={
 62                "newLabels": new_labels,
 63            },
 64            request_options=request_options,
 65            omit=OMIT,
 66        )
 67        try:
 68            if 200 <= _response.status_code < 300:
 69                _data = typing.cast(
 70                    Prompt,
 71                    parse_obj_as(
 72                        type_=Prompt,  # type: ignore
 73                        object_=_response.json(),
 74                    ),
 75                )
 76                return HttpResponse(response=_response, data=_data)
 77            if _response.status_code == 400:
 78                raise Error(
 79                    headers=dict(_response.headers),
 80                    body=typing.cast(
 81                        typing.Any,
 82                        parse_obj_as(
 83                            type_=typing.Any,  # type: ignore
 84                            object_=_response.json(),
 85                        ),
 86                    ),
 87                )
 88            if _response.status_code == 401:
 89                raise UnauthorizedError(
 90                    headers=dict(_response.headers),
 91                    body=typing.cast(
 92                        typing.Any,
 93                        parse_obj_as(
 94                            type_=typing.Any,  # type: ignore
 95                            object_=_response.json(),
 96                        ),
 97                    ),
 98                )
 99            if _response.status_code == 403:
100                raise AccessDeniedError(
101                    headers=dict(_response.headers),
102                    body=typing.cast(
103                        typing.Any,
104                        parse_obj_as(
105                            type_=typing.Any,  # type: ignore
106                            object_=_response.json(),
107                        ),
108                    ),
109                )
110            if _response.status_code == 405:
111                raise MethodNotAllowedError(
112                    headers=dict(_response.headers),
113                    body=typing.cast(
114                        typing.Any,
115                        parse_obj_as(
116                            type_=typing.Any,  # type: ignore
117                            object_=_response.json(),
118                        ),
119                    ),
120                )
121            if _response.status_code == 404:
122                raise NotFoundError(
123                    headers=dict(_response.headers),
124                    body=typing.cast(
125                        typing.Any,
126                        parse_obj_as(
127                            type_=typing.Any,  # type: ignore
128                            object_=_response.json(),
129                        ),
130                    ),
131                )
132            _response_json = _response.json()
133        except JSONDecodeError:
134            raise ApiError(
135                status_code=_response.status_code,
136                headers=dict(_response.headers),
137                body=_response.text,
138            )
139        raise ApiError(
140            status_code=_response.status_code,
141            headers=dict(_response.headers),
142            body=_response_json,
143        )
RawPromptVersionClient( *, client_wrapper: langfuse.api.core.client_wrapper.SyncClientWrapper)
25    def __init__(self, *, client_wrapper: SyncClientWrapper):
26        self._client_wrapper = client_wrapper
def update( self, name: str, version: int, *, new_labels: Sequence[str], request_options: Optional[langfuse.api.core.request_options.RequestOptions] = None) -> langfuse.api.core.http_response.HttpResponse[typing.Annotated[typing.Union[langfuse.api.Prompt_Chat, langfuse.api.Prompt_Text], FieldInfo(annotation=NoneType, required=True, discriminator='type')]]:
 28    def update(
 29        self,
 30        name: str,
 31        version: int,
 32        *,
 33        new_labels: typing.Sequence[str],
 34        request_options: typing.Optional[RequestOptions] = None,
 35    ) -> HttpResponse[Prompt]:
 36        """
 37        Update labels for a specific prompt version
 38
 39        Parameters
 40        ----------
 41        name : str
 42            The name of the prompt. If the prompt is in a folder (e.g., "folder/subfolder/prompt-name"),
 43            the folder path must be URL encoded.
 44
 45        version : int
 46            Version of the prompt to update
 47
 48        new_labels : typing.Sequence[str]
 49            New labels for the prompt version. Labels are unique across versions. The "latest" label is reserved and managed by Langfuse.
 50
 51        request_options : typing.Optional[RequestOptions]
 52            Request-specific configuration.
 53
 54        Returns
 55        -------
 56        HttpResponse[Prompt]
 57        """
 58        _response = self._client_wrapper.httpx_client.request(
 59            f"api/public/v2/prompts/{jsonable_encoder(name)}/versions/{jsonable_encoder(version)}",
 60            method="PATCH",
 61            json={
 62                "newLabels": new_labels,
 63            },
 64            request_options=request_options,
 65            omit=OMIT,
 66        )
 67        try:
 68            if 200 <= _response.status_code < 300:
 69                _data = typing.cast(
 70                    Prompt,
 71                    parse_obj_as(
 72                        type_=Prompt,  # type: ignore
 73                        object_=_response.json(),
 74                    ),
 75                )
 76                return HttpResponse(response=_response, data=_data)
 77            if _response.status_code == 400:
 78                raise Error(
 79                    headers=dict(_response.headers),
 80                    body=typing.cast(
 81                        typing.Any,
 82                        parse_obj_as(
 83                            type_=typing.Any,  # type: ignore
 84                            object_=_response.json(),
 85                        ),
 86                    ),
 87                )
 88            if _response.status_code == 401:
 89                raise UnauthorizedError(
 90                    headers=dict(_response.headers),
 91                    body=typing.cast(
 92                        typing.Any,
 93                        parse_obj_as(
 94                            type_=typing.Any,  # type: ignore
 95                            object_=_response.json(),
 96                        ),
 97                    ),
 98                )
 99            if _response.status_code == 403:
100                raise AccessDeniedError(
101                    headers=dict(_response.headers),
102                    body=typing.cast(
103                        typing.Any,
104                        parse_obj_as(
105                            type_=typing.Any,  # type: ignore
106                            object_=_response.json(),
107                        ),
108                    ),
109                )
110            if _response.status_code == 405:
111                raise MethodNotAllowedError(
112                    headers=dict(_response.headers),
113                    body=typing.cast(
114                        typing.Any,
115                        parse_obj_as(
116                            type_=typing.Any,  # type: ignore
117                            object_=_response.json(),
118                        ),
119                    ),
120                )
121            if _response.status_code == 404:
122                raise NotFoundError(
123                    headers=dict(_response.headers),
124                    body=typing.cast(
125                        typing.Any,
126                        parse_obj_as(
127                            type_=typing.Any,  # type: ignore
128                            object_=_response.json(),
129                        ),
130                    ),
131                )
132            _response_json = _response.json()
133        except JSONDecodeError:
134            raise ApiError(
135                status_code=_response.status_code,
136                headers=dict(_response.headers),
137                body=_response.text,
138            )
139        raise ApiError(
140            status_code=_response.status_code,
141            headers=dict(_response.headers),
142            body=_response_json,
143        )

Update labels for a specific prompt version

Parameters

name : str The name of the prompt. If the prompt is in a folder (e.g., "folder/subfolder/prompt-name"), the folder path must be URL encoded.

version : int Version of the prompt to update

new_labels : typing.Sequence[str] New labels for the prompt version. Labels are unique across versions. The "latest" label is reserved and managed by Langfuse.

request_options : typing.Optional[RequestOptions] Request-specific configuration.

Returns

HttpResponse[Prompt]

class AsyncRawPromptVersionClient:
146class AsyncRawPromptVersionClient:
147    def __init__(self, *, client_wrapper: AsyncClientWrapper):
148        self._client_wrapper = client_wrapper
149
150    async def update(
151        self,
152        name: str,
153        version: int,
154        *,
155        new_labels: typing.Sequence[str],
156        request_options: typing.Optional[RequestOptions] = None,
157    ) -> AsyncHttpResponse[Prompt]:
158        """
159        Update labels for a specific prompt version
160
161        Parameters
162        ----------
163        name : str
164            The name of the prompt. If the prompt is in a folder (e.g., "folder/subfolder/prompt-name"),
165            the folder path must be URL encoded.
166
167        version : int
168            Version of the prompt to update
169
170        new_labels : typing.Sequence[str]
171            New labels for the prompt version. Labels are unique across versions. The "latest" label is reserved and managed by Langfuse.
172
173        request_options : typing.Optional[RequestOptions]
174            Request-specific configuration.
175
176        Returns
177        -------
178        AsyncHttpResponse[Prompt]
179        """
180        _response = await self._client_wrapper.httpx_client.request(
181            f"api/public/v2/prompts/{jsonable_encoder(name)}/versions/{jsonable_encoder(version)}",
182            method="PATCH",
183            json={
184                "newLabels": new_labels,
185            },
186            request_options=request_options,
187            omit=OMIT,
188        )
189        try:
190            if 200 <= _response.status_code < 300:
191                _data = typing.cast(
192                    Prompt,
193                    parse_obj_as(
194                        type_=Prompt,  # type: ignore
195                        object_=_response.json(),
196                    ),
197                )
198                return AsyncHttpResponse(response=_response, data=_data)
199            if _response.status_code == 400:
200                raise Error(
201                    headers=dict(_response.headers),
202                    body=typing.cast(
203                        typing.Any,
204                        parse_obj_as(
205                            type_=typing.Any,  # type: ignore
206                            object_=_response.json(),
207                        ),
208                    ),
209                )
210            if _response.status_code == 401:
211                raise UnauthorizedError(
212                    headers=dict(_response.headers),
213                    body=typing.cast(
214                        typing.Any,
215                        parse_obj_as(
216                            type_=typing.Any,  # type: ignore
217                            object_=_response.json(),
218                        ),
219                    ),
220                )
221            if _response.status_code == 403:
222                raise AccessDeniedError(
223                    headers=dict(_response.headers),
224                    body=typing.cast(
225                        typing.Any,
226                        parse_obj_as(
227                            type_=typing.Any,  # type: ignore
228                            object_=_response.json(),
229                        ),
230                    ),
231                )
232            if _response.status_code == 405:
233                raise MethodNotAllowedError(
234                    headers=dict(_response.headers),
235                    body=typing.cast(
236                        typing.Any,
237                        parse_obj_as(
238                            type_=typing.Any,  # type: ignore
239                            object_=_response.json(),
240                        ),
241                    ),
242                )
243            if _response.status_code == 404:
244                raise NotFoundError(
245                    headers=dict(_response.headers),
246                    body=typing.cast(
247                        typing.Any,
248                        parse_obj_as(
249                            type_=typing.Any,  # type: ignore
250                            object_=_response.json(),
251                        ),
252                    ),
253                )
254            _response_json = _response.json()
255        except JSONDecodeError:
256            raise ApiError(
257                status_code=_response.status_code,
258                headers=dict(_response.headers),
259                body=_response.text,
260            )
261        raise ApiError(
262            status_code=_response.status_code,
263            headers=dict(_response.headers),
264            body=_response_json,
265        )
AsyncRawPromptVersionClient( *, client_wrapper: langfuse.api.core.client_wrapper.AsyncClientWrapper)
147    def __init__(self, *, client_wrapper: AsyncClientWrapper):
148        self._client_wrapper = client_wrapper
async def update( self, name: str, version: int, *, new_labels: Sequence[str], request_options: Optional[langfuse.api.core.request_options.RequestOptions] = None) -> langfuse.api.core.http_response.AsyncHttpResponse[typing.Annotated[typing.Union[langfuse.api.Prompt_Chat, langfuse.api.Prompt_Text], FieldInfo(annotation=NoneType, required=True, discriminator='type')]]:
150    async def update(
151        self,
152        name: str,
153        version: int,
154        *,
155        new_labels: typing.Sequence[str],
156        request_options: typing.Optional[RequestOptions] = None,
157    ) -> AsyncHttpResponse[Prompt]:
158        """
159        Update labels for a specific prompt version
160
161        Parameters
162        ----------
163        name : str
164            The name of the prompt. If the prompt is in a folder (e.g., "folder/subfolder/prompt-name"),
165            the folder path must be URL encoded.
166
167        version : int
168            Version of the prompt to update
169
170        new_labels : typing.Sequence[str]
171            New labels for the prompt version. Labels are unique across versions. The "latest" label is reserved and managed by Langfuse.
172
173        request_options : typing.Optional[RequestOptions]
174            Request-specific configuration.
175
176        Returns
177        -------
178        AsyncHttpResponse[Prompt]
179        """
180        _response = await self._client_wrapper.httpx_client.request(
181            f"api/public/v2/prompts/{jsonable_encoder(name)}/versions/{jsonable_encoder(version)}",
182            method="PATCH",
183            json={
184                "newLabels": new_labels,
185            },
186            request_options=request_options,
187            omit=OMIT,
188        )
189        try:
190            if 200 <= _response.status_code < 300:
191                _data = typing.cast(
192                    Prompt,
193                    parse_obj_as(
194                        type_=Prompt,  # type: ignore
195                        object_=_response.json(),
196                    ),
197                )
198                return AsyncHttpResponse(response=_response, data=_data)
199            if _response.status_code == 400:
200                raise Error(
201                    headers=dict(_response.headers),
202                    body=typing.cast(
203                        typing.Any,
204                        parse_obj_as(
205                            type_=typing.Any,  # type: ignore
206                            object_=_response.json(),
207                        ),
208                    ),
209                )
210            if _response.status_code == 401:
211                raise UnauthorizedError(
212                    headers=dict(_response.headers),
213                    body=typing.cast(
214                        typing.Any,
215                        parse_obj_as(
216                            type_=typing.Any,  # type: ignore
217                            object_=_response.json(),
218                        ),
219                    ),
220                )
221            if _response.status_code == 403:
222                raise AccessDeniedError(
223                    headers=dict(_response.headers),
224                    body=typing.cast(
225                        typing.Any,
226                        parse_obj_as(
227                            type_=typing.Any,  # type: ignore
228                            object_=_response.json(),
229                        ),
230                    ),
231                )
232            if _response.status_code == 405:
233                raise MethodNotAllowedError(
234                    headers=dict(_response.headers),
235                    body=typing.cast(
236                        typing.Any,
237                        parse_obj_as(
238                            type_=typing.Any,  # type: ignore
239                            object_=_response.json(),
240                        ),
241                    ),
242                )
243            if _response.status_code == 404:
244                raise NotFoundError(
245                    headers=dict(_response.headers),
246                    body=typing.cast(
247                        typing.Any,
248                        parse_obj_as(
249                            type_=typing.Any,  # type: ignore
250                            object_=_response.json(),
251                        ),
252                    ),
253                )
254            _response_json = _response.json()
255        except JSONDecodeError:
256            raise ApiError(
257                status_code=_response.status_code,
258                headers=dict(_response.headers),
259                body=_response.text,
260            )
261        raise ApiError(
262            status_code=_response.status_code,
263            headers=dict(_response.headers),
264            body=_response_json,
265        )

Update labels for a specific prompt version

Parameters

name : str The name of the prompt. If the prompt is in a folder (e.g., "folder/subfolder/prompt-name"), the folder path must be URL encoded.

version : int Version of the prompt to update

new_labels : typing.Sequence[str] New labels for the prompt version. Labels are unique across versions. The "latest" label is reserved and managed by Langfuse.

request_options : typing.Optional[RequestOptions] Request-specific configuration.

Returns

AsyncHttpResponse[Prompt]