|
| 1 | +# This file was auto-generated by Fern from our API Definition. |
| 2 | + |
| 3 | +import typing |
| 4 | +from json.decoder import JSONDecodeError |
| 5 | + |
| 6 | +from ...core.api_error import ApiError |
| 7 | +from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper |
| 8 | +from ...core.jsonable_encoder import jsonable_encoder |
| 9 | +from ...core.pydantic_utilities import pydantic_v1 |
| 10 | +from ...core.request_options import RequestOptions |
| 11 | +from ..commons.errors.access_denied_error import AccessDeniedError |
| 12 | +from ..commons.errors.error import Error |
| 13 | +from ..commons.errors.method_not_allowed_error import MethodNotAllowedError |
| 14 | +from ..commons.errors.not_found_error import NotFoundError |
| 15 | +from ..commons.errors.unauthorized_error import UnauthorizedError |
| 16 | +from ..prompts.types.prompt import Prompt |
| 17 | + |
| 18 | +# this is used as the default value for optional parameters |
| 19 | +OMIT = typing.cast(typing.Any, ...) |
| 20 | + |
| 21 | + |
| 22 | +class PromptVersionClient: |
| 23 | + def __init__(self, *, client_wrapper: SyncClientWrapper): |
| 24 | + self._client_wrapper = client_wrapper |
| 25 | + |
| 26 | + def update( |
| 27 | + self, |
| 28 | + name: str, |
| 29 | + version: int, |
| 30 | + *, |
| 31 | + new_labels: typing.Sequence[str], |
| 32 | + request_options: typing.Optional[RequestOptions] = None, |
| 33 | + ) -> Prompt: |
| 34 | + """ |
| 35 | + Update labels for a specific prompt version |
| 36 | +
|
| 37 | + Parameters |
| 38 | + ---------- |
| 39 | + name : str |
| 40 | + The name of the prompt |
| 41 | +
|
| 42 | + version : int |
| 43 | + Version of the prompt to update |
| 44 | +
|
| 45 | + new_labels : typing.Sequence[str] |
| 46 | + New labels for the prompt version. Labels are unique across versions. The "latest" label is reserved and managed by Langfuse. |
| 47 | +
|
| 48 | + request_options : typing.Optional[RequestOptions] |
| 49 | + Request-specific configuration. |
| 50 | +
|
| 51 | + Returns |
| 52 | + ------- |
| 53 | + Prompt |
| 54 | +
|
| 55 | + Examples |
| 56 | + -------- |
| 57 | + from langfuse.client import FernLangfuse |
| 58 | +
|
| 59 | + client = FernLangfuse( |
| 60 | + x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME", |
| 61 | + x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION", |
| 62 | + x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY", |
| 63 | + username="YOUR_USERNAME", |
| 64 | + password="YOUR_PASSWORD", |
| 65 | + base_url="https://yourhost.com/path/to/api", |
| 66 | + ) |
| 67 | + client.prompt_version.update( |
| 68 | + name="string", |
| 69 | + version=1, |
| 70 | + new_labels=["string"], |
| 71 | + ) |
| 72 | + """ |
| 73 | + _response = self._client_wrapper.httpx_client.request( |
| 74 | + f"api/public/v2/prompts/{jsonable_encoder(name)}/versions/{jsonable_encoder(version)}", |
| 75 | + method="PATCH", |
| 76 | + json={"newLabels": new_labels}, |
| 77 | + request_options=request_options, |
| 78 | + omit=OMIT, |
| 79 | + ) |
| 80 | + try: |
| 81 | + if 200 <= _response.status_code < 300: |
| 82 | + return pydantic_v1.parse_obj_as(Prompt, _response.json()) # type: ignore |
| 83 | + if _response.status_code == 400: |
| 84 | + raise Error(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore |
| 85 | + if _response.status_code == 401: |
| 86 | + raise UnauthorizedError( |
| 87 | + pydantic_v1.parse_obj_as(typing.Any, _response.json()) |
| 88 | + ) # type: ignore |
| 89 | + if _response.status_code == 403: |
| 90 | + raise AccessDeniedError( |
| 91 | + pydantic_v1.parse_obj_as(typing.Any, _response.json()) |
| 92 | + ) # type: ignore |
| 93 | + if _response.status_code == 405: |
| 94 | + raise MethodNotAllowedError( |
| 95 | + pydantic_v1.parse_obj_as(typing.Any, _response.json()) |
| 96 | + ) # type: ignore |
| 97 | + if _response.status_code == 404: |
| 98 | + raise NotFoundError( |
| 99 | + pydantic_v1.parse_obj_as(typing.Any, _response.json()) |
| 100 | + ) # type: ignore |
| 101 | + _response_json = _response.json() |
| 102 | + except JSONDecodeError: |
| 103 | + raise ApiError(status_code=_response.status_code, body=_response.text) |
| 104 | + raise ApiError(status_code=_response.status_code, body=_response_json) |
| 105 | + |
| 106 | + |
| 107 | +class AsyncPromptVersionClient: |
| 108 | + def __init__(self, *, client_wrapper: AsyncClientWrapper): |
| 109 | + self._client_wrapper = client_wrapper |
| 110 | + |
| 111 | + async def update( |
| 112 | + self, |
| 113 | + name: str, |
| 114 | + version: int, |
| 115 | + *, |
| 116 | + new_labels: typing.Sequence[str], |
| 117 | + request_options: typing.Optional[RequestOptions] = None, |
| 118 | + ) -> Prompt: |
| 119 | + """ |
| 120 | + Update labels for a specific prompt version |
| 121 | +
|
| 122 | + Parameters |
| 123 | + ---------- |
| 124 | + name : str |
| 125 | + The name of the prompt |
| 126 | +
|
| 127 | + version : int |
| 128 | + Version of the prompt to update |
| 129 | +
|
| 130 | + new_labels : typing.Sequence[str] |
| 131 | + New labels for the prompt version. Labels are unique across versions. The "latest" label is reserved and managed by Langfuse. |
| 132 | +
|
| 133 | + request_options : typing.Optional[RequestOptions] |
| 134 | + Request-specific configuration. |
| 135 | +
|
| 136 | + Returns |
| 137 | + ------- |
| 138 | + Prompt |
| 139 | +
|
| 140 | + Examples |
| 141 | + -------- |
| 142 | + import asyncio |
| 143 | +
|
| 144 | + from langfuse.client import AsyncFernLangfuse |
| 145 | +
|
| 146 | + client = AsyncFernLangfuse( |
| 147 | + x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME", |
| 148 | + x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION", |
| 149 | + x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY", |
| 150 | + username="YOUR_USERNAME", |
| 151 | + password="YOUR_PASSWORD", |
| 152 | + base_url="https://yourhost.com/path/to/api", |
| 153 | + ) |
| 154 | +
|
| 155 | +
|
| 156 | + async def main() -> None: |
| 157 | + await client.prompt_version.update( |
| 158 | + name="string", |
| 159 | + version=1, |
| 160 | + new_labels=["string"], |
| 161 | + ) |
| 162 | +
|
| 163 | +
|
| 164 | + asyncio.run(main()) |
| 165 | + """ |
| 166 | + _response = await self._client_wrapper.httpx_client.request( |
| 167 | + f"api/public/v2/prompts/{jsonable_encoder(name)}/versions/{jsonable_encoder(version)}", |
| 168 | + method="PATCH", |
| 169 | + json={"newLabels": new_labels}, |
| 170 | + request_options=request_options, |
| 171 | + omit=OMIT, |
| 172 | + ) |
| 173 | + try: |
| 174 | + if 200 <= _response.status_code < 300: |
| 175 | + return pydantic_v1.parse_obj_as(Prompt, _response.json()) # type: ignore |
| 176 | + if _response.status_code == 400: |
| 177 | + raise Error(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore |
| 178 | + if _response.status_code == 401: |
| 179 | + raise UnauthorizedError( |
| 180 | + pydantic_v1.parse_obj_as(typing.Any, _response.json()) |
| 181 | + ) # type: ignore |
| 182 | + if _response.status_code == 403: |
| 183 | + raise AccessDeniedError( |
| 184 | + pydantic_v1.parse_obj_as(typing.Any, _response.json()) |
| 185 | + ) # type: ignore |
| 186 | + if _response.status_code == 405: |
| 187 | + raise MethodNotAllowedError( |
| 188 | + pydantic_v1.parse_obj_as(typing.Any, _response.json()) |
| 189 | + ) # type: ignore |
| 190 | + if _response.status_code == 404: |
| 191 | + raise NotFoundError( |
| 192 | + pydantic_v1.parse_obj_as(typing.Any, _response.json()) |
| 193 | + ) # type: ignore |
| 194 | + _response_json = _response.json() |
| 195 | + except JSONDecodeError: |
| 196 | + raise ApiError(status_code=_response.status_code, body=_response.text) |
| 197 | + raise ApiError(status_code=_response.status_code, body=_response_json) |
0 commit comments