Skip to content
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 17 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions langfuse/api/__init__.py
Copy link
Contributor

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

poetry run ruff format langfuse/api --config ruff.toml

Copy link
Member Author

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?

ImportError while importing test module '/Users/maximiliandeichmann/development/github.com/langfuse/langfuse-python/tests/test_updating_prompt.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../../../.pyenv/versions/3.9.1/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_updating_prompt.py:1: in <module>
    from langfuse.client import Langfuse
langfuse/__init__.py:3: in <module>
    from .client import Langfuse  # noqa
langfuse/client.py:43: in <module>
    from langfuse.api.resources.prompts.types import (
E   ImportError: cannot import name 'Prompt_Chat' from 'langfuse.api.resources.prompts.types' (/Users/maximiliandeichmann/development/github.com/langfuse/langfuse-python/langfuse/api/resources/prompts/types/__init__.py)

Somehow this fern run changed a lot i think.

Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
models,
observations,
projects,
prompt_version,
prompts,
score,
score_configs,
Expand Down Expand Up @@ -302,6 +303,7 @@
"models",
"observations",
"projects",
"prompt_version",
"prompts",
"score",
"score_configs",
Expand Down
44 changes: 14 additions & 30 deletions langfuse/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from .resources.comments.client import AsyncCommentsClient, CommentsClient
from .resources.dataset_items.client import AsyncDatasetItemsClient, DatasetItemsClient
from .resources.dataset_run_items.client import (
AsyncDatasetRunItemsClient,
DatasetRunItemsClient,
)
from .resources.dataset_run_items.client import AsyncDatasetRunItemsClient, DatasetRunItemsClient
from .resources.datasets.client import AsyncDatasetsClient, DatasetsClient
from .resources.health.client import AsyncHealthClient, HealthClient
from .resources.ingestion.client import AsyncIngestionClient, IngestionClient
Expand All @@ -19,6 +16,7 @@
from .resources.models.client import AsyncModelsClient, ModelsClient
from .resources.observations.client import AsyncObservationsClient, ObservationsClient
from .resources.projects.client import AsyncProjectsClient, ProjectsClient
from .resources.prompt_version.client import AsyncPromptVersionClient, PromptVersionClient
from .resources.prompts.client import AsyncPromptsClient, PromptsClient
from .resources.score.client import AsyncScoreClient, ScoreClient
from .resources.score_configs.client import AsyncScoreConfigsClient, ScoreConfigsClient
Expand Down Expand Up @@ -74,11 +72,9 @@ def __init__(
password: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
timeout: typing.Optional[float] = None,
follow_redirects: typing.Optional[bool] = True,
httpx_client: typing.Optional[httpx.Client] = None,
httpx_client: typing.Optional[httpx.Client] = None
):
_defaulted_timeout = (
timeout if timeout is not None else 60 if httpx_client is None else None
)
_defaulted_timeout = timeout if timeout is not None else 60 if httpx_client is None else None
self._client_wrapper = SyncClientWrapper(
base_url=base_url,
x_langfuse_sdk_name=x_langfuse_sdk_name,
Expand All @@ -88,18 +84,14 @@ def __init__(
password=password,
httpx_client=httpx_client
if httpx_client is not None
else httpx.Client(
timeout=_defaulted_timeout, follow_redirects=follow_redirects
)
else httpx.Client(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
if follow_redirects is not None
else httpx.Client(timeout=_defaulted_timeout),
timeout=_defaulted_timeout,
)
self.comments = CommentsClient(client_wrapper=self._client_wrapper)
self.dataset_items = DatasetItemsClient(client_wrapper=self._client_wrapper)
self.dataset_run_items = DatasetRunItemsClient(
client_wrapper=self._client_wrapper
)
self.dataset_run_items = DatasetRunItemsClient(client_wrapper=self._client_wrapper)
self.datasets = DatasetsClient(client_wrapper=self._client_wrapper)
self.health = HealthClient(client_wrapper=self._client_wrapper)
self.ingestion = IngestionClient(client_wrapper=self._client_wrapper)
Expand All @@ -108,6 +100,7 @@ def __init__(
self.models = ModelsClient(client_wrapper=self._client_wrapper)
self.observations = ObservationsClient(client_wrapper=self._client_wrapper)
self.projects = ProjectsClient(client_wrapper=self._client_wrapper)
self.prompt_version = PromptVersionClient(client_wrapper=self._client_wrapper)
self.prompts = PromptsClient(client_wrapper=self._client_wrapper)
self.score_configs = ScoreConfigsClient(client_wrapper=self._client_wrapper)
self.score = ScoreClient(client_wrapper=self._client_wrapper)
Expand Down Expand Up @@ -163,11 +156,9 @@ def __init__(
password: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
timeout: typing.Optional[float] = None,
follow_redirects: typing.Optional[bool] = True,
httpx_client: typing.Optional[httpx.AsyncClient] = None,
httpx_client: typing.Optional[httpx.AsyncClient] = None
):
_defaulted_timeout = (
timeout if timeout is not None else 60 if httpx_client is None else None
)
_defaulted_timeout = timeout if timeout is not None else 60 if httpx_client is None else None
self._client_wrapper = AsyncClientWrapper(
base_url=base_url,
x_langfuse_sdk_name=x_langfuse_sdk_name,
Expand All @@ -177,20 +168,14 @@ def __init__(
password=password,
httpx_client=httpx_client
if httpx_client is not None
else httpx.AsyncClient(
timeout=_defaulted_timeout, follow_redirects=follow_redirects
)
else httpx.AsyncClient(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
if follow_redirects is not None
else httpx.AsyncClient(timeout=_defaulted_timeout),
timeout=_defaulted_timeout,
)
self.comments = AsyncCommentsClient(client_wrapper=self._client_wrapper)
self.dataset_items = AsyncDatasetItemsClient(
client_wrapper=self._client_wrapper
)
self.dataset_run_items = AsyncDatasetRunItemsClient(
client_wrapper=self._client_wrapper
)
self.dataset_items = AsyncDatasetItemsClient(client_wrapper=self._client_wrapper)
self.dataset_run_items = AsyncDatasetRunItemsClient(client_wrapper=self._client_wrapper)
self.datasets = AsyncDatasetsClient(client_wrapper=self._client_wrapper)
self.health = AsyncHealthClient(client_wrapper=self._client_wrapper)
self.ingestion = AsyncIngestionClient(client_wrapper=self._client_wrapper)
Expand All @@ -199,10 +184,9 @@ def __init__(
self.models = AsyncModelsClient(client_wrapper=self._client_wrapper)
self.observations = AsyncObservationsClient(client_wrapper=self._client_wrapper)
self.projects = AsyncProjectsClient(client_wrapper=self._client_wrapper)
self.prompt_version = AsyncPromptVersionClient(client_wrapper=self._client_wrapper)
self.prompts = AsyncPromptsClient(client_wrapper=self._client_wrapper)
self.score_configs = AsyncScoreConfigsClient(
client_wrapper=self._client_wrapper
)
self.score_configs = AsyncScoreConfigsClient(client_wrapper=self._client_wrapper)
self.score = AsyncScoreClient(client_wrapper=self._client_wrapper)
self.sessions = AsyncSessionsClient(client_wrapper=self._client_wrapper)
self.trace = AsyncTraceClient(client_wrapper=self._client_wrapper)
4 changes: 1 addition & 3 deletions langfuse/api/core/api_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ class ApiError(Exception):
status_code: typing.Optional[int]
body: typing.Any

def __init__(
self, *, status_code: typing.Optional[int] = None, body: typing.Any = None
):
def __init__(self, *, status_code: typing.Optional[int] = None, body: typing.Any = None):
self.status_code = status_code
self.body = body

Expand Down
6 changes: 3 additions & 3 deletions langfuse/api/core/client_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(
username: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
password: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
base_url: str,
timeout: typing.Optional[float] = None,
timeout: typing.Optional[float] = None
):
self._x_langfuse_sdk_name = x_langfuse_sdk_name
self._x_langfuse_sdk_version = x_langfuse_sdk_version
Expand Down Expand Up @@ -71,7 +71,7 @@ def __init__(
password: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
base_url: str,
timeout: typing.Optional[float] = None,
httpx_client: httpx.Client,
httpx_client: httpx.Client
):
super().__init__(
x_langfuse_sdk_name=x_langfuse_sdk_name,
Expand Down Expand Up @@ -101,7 +101,7 @@ def __init__(
password: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
base_url: str,
timeout: typing.Optional[float] = None,
httpx_client: httpx.AsyncClient,
httpx_client: httpx.AsyncClient
):
super().__init__(
x_langfuse_sdk_name=x_langfuse_sdk_name,
Expand Down
4 changes: 1 addition & 3 deletions langfuse/api/core/datetime_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ def serialize_datetime(v: dt.datetime) -> str:
"""

def _serialize_zoned_datetime(v: dt.datetime) -> str:
if v.tzinfo is not None and v.tzinfo.tzname(None) == dt.timezone.utc.tzname(
None
):
if v.tzinfo is not None and v.tzinfo.tzname(None) == dt.timezone.utc.tzname(None):
# UTC is a special case where we use "Z" at the end instead of "+00:00"
return v.isoformat().replace("+00:00", "Z")
else:
Expand Down
9 changes: 2 additions & 7 deletions langfuse/api/core/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,12 @@
# (filename, file (or bytes), content_type)
typing.Tuple[typing.Optional[str], FileContent, typing.Optional[str]],
# (filename, file (or bytes), content_type, headers)
typing.Tuple[
typing.Optional[str],
FileContent,
typing.Optional[str],
typing.Mapping[str, str],
],
typing.Tuple[typing.Optional[str], FileContent, typing.Optional[str], typing.Mapping[str, str]],
]


def convert_file_dict_to_httpx_tuples(
d: typing.Dict[str, typing.Union[File, typing.List[File]]],
d: typing.Dict[str, typing.Union[File, typing.List[File]]]
) -> typing.List[typing.Tuple[str, File]]:
"""
The format we use is a list of tuples, where the first element is the
Expand Down
Loading
Loading