-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: update prompts and invalidate cache #1082
Merged
Merged
Changes from 8 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b6e1af7
feat: update prompts and invalidate cache
maxdeichmann 95b0489
feat: update prompts and invalidate cache
maxdeichmann 9114ed5
feat: update prompts and invalidate cache
maxdeichmann e5a1242
feat: update prompts and invalidate cache
maxdeichmann 1301dcd
feat: update prompts and invalidate cache
maxdeichmann 6847280
push
maxdeichmann 66e8dc6
revert fern test client import path
hassiebp cbda4fe
Merge branch 'main' into max/lfe-3587-update-prompt-versions
maxdeichmann 28a9883
push
maxdeichmann 09fdedb
push
maxdeichmann 80ca5e8
fix
maxdeichmann 74bb976
push
maxdeichmann 682e25d
fix
maxdeichmann 5605c26
Merge branch 'main' into max/lfe-3587-update-prompt-versions
maxdeichmann 71c83cd
push
maxdeichmann eb32652
Merge branch 'max/lfe-3587-update-prompt-versions' of https://github.…
maxdeichmann bb9528e
push
maxdeichmann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# This file was auto-generated by Fern from our API Definition. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
# This file was auto-generated by Fern from our API Definition. | ||
|
||
import typing | ||
from json.decoder import JSONDecodeError | ||
|
||
from ...core.api_error import ApiError | ||
from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper | ||
from ...core.jsonable_encoder import jsonable_encoder | ||
from ...core.pydantic_utilities import pydantic_v1 | ||
from ...core.request_options import RequestOptions | ||
from ..commons.errors.access_denied_error import AccessDeniedError | ||
from ..commons.errors.error import Error | ||
from ..commons.errors.method_not_allowed_error import MethodNotAllowedError | ||
from ..commons.errors.not_found_error import NotFoundError | ||
from ..commons.errors.unauthorized_error import UnauthorizedError | ||
from ..prompts.types.prompt import Prompt | ||
|
||
# this is used as the default value for optional parameters | ||
OMIT = typing.cast(typing.Any, ...) | ||
|
||
|
||
class PromptVersionClient: | ||
def __init__(self, *, client_wrapper: SyncClientWrapper): | ||
self._client_wrapper = client_wrapper | ||
|
||
def update( | ||
self, | ||
prompt_name: str, | ||
version: int, | ||
*, | ||
new_labels: typing.Sequence[str], | ||
request_options: typing.Optional[RequestOptions] = None, | ||
) -> Prompt: | ||
""" | ||
Update labels for a specific prompt version | ||
|
||
Parameters | ||
---------- | ||
prompt_name : str | ||
The name of the prompt | ||
|
||
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 | ||
------- | ||
Prompt | ||
|
||
Examples | ||
-------- | ||
from langfuse.client import FernLangfuse | ||
|
||
client = FernLangfuse( | ||
x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME", | ||
x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION", | ||
x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY", | ||
username="YOUR_USERNAME", | ||
password="YOUR_PASSWORD", | ||
base_url="https://yourhost.com/path/to/api", | ||
) | ||
client.prompt_version.update( | ||
prompt_name="string", | ||
version=1, | ||
new_labels=["string"], | ||
) | ||
""" | ||
_response = self._client_wrapper.httpx_client.request( | ||
f"api/public/v2/prompts/{jsonable_encoder(prompt_name)}/version/{jsonable_encoder(version)}", | ||
maxdeichmann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
method="PATCH", | ||
json={"newLabels": new_labels}, | ||
request_options=request_options, | ||
omit=OMIT, | ||
) | ||
try: | ||
if 200 <= _response.status_code < 300: | ||
return pydantic_v1.parse_obj_as(Prompt, _response.json()) # type: ignore | ||
if _response.status_code == 400: | ||
raise Error(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore | ||
if _response.status_code == 401: | ||
raise UnauthorizedError( | ||
pydantic_v1.parse_obj_as(typing.Any, _response.json()) | ||
) # type: ignore | ||
if _response.status_code == 403: | ||
raise AccessDeniedError( | ||
pydantic_v1.parse_obj_as(typing.Any, _response.json()) | ||
) # type: ignore | ||
if _response.status_code == 405: | ||
raise MethodNotAllowedError( | ||
pydantic_v1.parse_obj_as(typing.Any, _response.json()) | ||
) # type: ignore | ||
if _response.status_code == 404: | ||
raise NotFoundError( | ||
pydantic_v1.parse_obj_as(typing.Any, _response.json()) | ||
) # type: ignore | ||
_response_json = _response.json() | ||
except JSONDecodeError: | ||
raise ApiError(status_code=_response.status_code, body=_response.text) | ||
raise ApiError(status_code=_response.status_code, body=_response_json) | ||
|
||
|
||
class AsyncPromptVersionClient: | ||
def __init__(self, *, client_wrapper: AsyncClientWrapper): | ||
self._client_wrapper = client_wrapper | ||
|
||
async def update( | ||
self, | ||
prompt_name: str, | ||
version: int, | ||
*, | ||
new_labels: typing.Sequence[str], | ||
request_options: typing.Optional[RequestOptions] = None, | ||
) -> Prompt: | ||
""" | ||
Update labels for a specific prompt version | ||
|
||
Parameters | ||
---------- | ||
prompt_name : str | ||
The name of the prompt | ||
|
||
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 | ||
------- | ||
Prompt | ||
|
||
Examples | ||
-------- | ||
import asyncio | ||
|
||
from langfuse.client import AsyncFernLangfuse | ||
|
||
client = AsyncFernLangfuse( | ||
x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME", | ||
x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION", | ||
x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY", | ||
username="YOUR_USERNAME", | ||
password="YOUR_PASSWORD", | ||
base_url="https://yourhost.com/path/to/api", | ||
) | ||
|
||
|
||
async def main() -> None: | ||
await client.prompt_version.update( | ||
prompt_name="string", | ||
version=1, | ||
new_labels=["string"], | ||
) | ||
|
||
|
||
asyncio.run(main()) | ||
""" | ||
_response = await self._client_wrapper.httpx_client.request( | ||
f"api/public/v2/prompts/{jsonable_encoder(prompt_name)}/version/{jsonable_encoder(version)}", | ||
method="PATCH", | ||
json={"newLabels": new_labels}, | ||
request_options=request_options, | ||
omit=OMIT, | ||
) | ||
try: | ||
if 200 <= _response.status_code < 300: | ||
return pydantic_v1.parse_obj_as(Prompt, _response.json()) # type: ignore | ||
if _response.status_code == 400: | ||
raise Error(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore | ||
if _response.status_code == 401: | ||
raise UnauthorizedError( | ||
pydantic_v1.parse_obj_as(typing.Any, _response.json()) | ||
) # type: ignore | ||
if _response.status_code == 403: | ||
raise AccessDeniedError( | ||
pydantic_v1.parse_obj_as(typing.Any, _response.json()) | ||
) # type: ignore | ||
if _response.status_code == 405: | ||
raise MethodNotAllowedError( | ||
pydantic_v1.parse_obj_as(typing.Any, _response.json()) | ||
) # type: ignore | ||
if _response.status_code == 404: | ||
raise NotFoundError( | ||
pydantic_v1.parse_obj_as(typing.Any, _response.json()) | ||
) # type: ignore | ||
_response_json = _response.json() | ||
except JSONDecodeError: | ||
raise ApiError(status_code=_response.status_code, body=_response.text) | ||
raise ApiError(status_code=_response.status_code, body=_response_json) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running this should get rid of all the file diffs due to formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx! do you have an idea where this error here might come from?
Somehow this fern run changed a lot i think.