Skip to content

Commit

Permalink
feat(datasets): add status as kwarg to create_dataset_item (#684)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcklingen authored May 15, 2024
1 parent 4d91426 commit 8c1b8a4
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 13 deletions.
6 changes: 4 additions & 2 deletions langfuse/api/resources/dataset_items/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def create(
- request_options: typing.Optional[RequestOptions]. Request-specific configuration.
---
from finto import CreateDatasetItemRequest
from finto import CreateDatasetItemRequest, DatasetStatus
from finto.client import FernLangfuse
client = FernLangfuse(
Expand All @@ -60,6 +60,7 @@ def create(
source_trace_id="string",
source_observation_id="string",
id="string",
status=DatasetStatus.ACTIVE,
),
)
"""
Expand Down Expand Up @@ -231,7 +232,7 @@ async def create(
- request_options: typing.Optional[RequestOptions]. Request-specific configuration.
---
from finto import CreateDatasetItemRequest
from finto import CreateDatasetItemRequest, DatasetStatus
from finto.client import AsyncFernLangfuse
client = AsyncFernLangfuse(
Expand All @@ -251,6 +252,7 @@ async def create(
source_trace_id="string",
source_observation_id="string",
id="string",
status=DatasetStatus.ACTIVE,
),
)
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from ....core.datetime_utils import serialize_datetime
from ....core.pydantic_utilities import pydantic_v1
from ...commons.types.dataset_status import DatasetStatus


class CreateDatasetItemRequest(pydantic_v1.BaseModel):
Expand All @@ -25,6 +26,11 @@ class CreateDatasetItemRequest(pydantic_v1.BaseModel):
Dataset items are upserted on their id
"""

status: typing.Optional[DatasetStatus] = pydantic_v1.Field(default=None)
"""
Defaults to ACTIVE for newly created items
"""

def json(self, **kwargs: typing.Any) -> str:
kwargs_with_defaults: typing.Any = {
"by_alias": True,
Expand Down
8 changes: 4 additions & 4 deletions langfuse/api/resources/metrics/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def daily(
- tags: typing.Optional[typing.Union[str, typing.Sequence[str]]]. Optional filter for metrics where traces include all of these tags
- from_timestamp: typing.Optional[dt.datetime]. Optional filter to only include traces on or after a certain timestamp
- from_timestamp: typing.Optional[dt.datetime]. Optional filter to only include traces on or after a certain datetime (ISO 8601)
- to_timestamp: typing.Optional[dt.datetime]. Optional filter to only include traces before a certain timestamp
- to_timestamp: typing.Optional[dt.datetime]. Optional filter to only include traces before a certain datetime (ISO 8601)
- request_options: typing.Optional[RequestOptions]. Request-specific configuration.
---
Expand Down Expand Up @@ -185,9 +185,9 @@ async def daily(
- tags: typing.Optional[typing.Union[str, typing.Sequence[str]]]. Optional filter for metrics where traces include all of these tags
- from_timestamp: typing.Optional[dt.datetime]. Optional filter to only include traces on or after a certain timestamp
- from_timestamp: typing.Optional[dt.datetime]. Optional filter to only include traces on or after a certain datetime (ISO 8601)
- to_timestamp: typing.Optional[dt.datetime]. Optional filter to only include traces before a certain timestamp
- to_timestamp: typing.Optional[dt.datetime]. Optional filter to only include traces before a certain datetime (ISO 8601)
- request_options: typing.Optional[RequestOptions]. Request-specific configuration.
---
Expand Down
4 changes: 2 additions & 2 deletions langfuse/api/resources/observations/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def get_many(
- parent_observation_id: typing.Optional[str].
- from_start_time: typing.Optional[dt.datetime]. Retrieve only observations with a start_time greater than this timestamp.
- from_start_time: typing.Optional[dt.datetime]. Retrieve only observations with a start_time greater than this datetime (ISO 8601).
- request_options: typing.Optional[RequestOptions]. Request-specific configuration.
---
Expand Down Expand Up @@ -360,7 +360,7 @@ async def get_many(
- parent_observation_id: typing.Optional[str].
- from_start_time: typing.Optional[dt.datetime]. Retrieve only observations with a start_time greater than this timestamp.
- from_start_time: typing.Optional[dt.datetime]. Retrieve only observations with a start_time greater than this datetime (ISO 8601).
- request_options: typing.Optional[RequestOptions]. Request-specific configuration.
---
Expand Down
4 changes: 2 additions & 2 deletions langfuse/api/resources/score/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def get(
- name: typing.Optional[str].
- from_timestamp: typing.Optional[dt.datetime]. Retrieve only scores newer than this timestamp.
- from_timestamp: typing.Optional[dt.datetime]. Retrieve only scores newer than this datetime (ISO 8601).
- source: ScoreSource. Retrieve only scores from a specific source.
Expand Down Expand Up @@ -562,7 +562,7 @@ async def get(
- name: typing.Optional[str].
- from_timestamp: typing.Optional[dt.datetime]. Retrieve only scores newer than this timestamp.
- from_timestamp: typing.Optional[dt.datetime]. Retrieve only scores newer than this datetime (ISO 8601).
- source: ScoreSource. Retrieve only scores from a specific source.
Expand Down
4 changes: 2 additions & 2 deletions langfuse/api/resources/trace/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def list(
- name: typing.Optional[str].
- from_timestamp: typing.Optional[dt.datetime]. Retrieve only traces newer than this timestamp.
- from_timestamp: typing.Optional[dt.datetime]. Retrieve only traces newer than this datetime (ISO 8601).
- order_by: typing.Optional[str]. Format of the string [field].[asc/desc]. Fields: id, timestamp, name, userId, release, version, public, bookmarked, sessionId. Example: timestamp.asc
Expand Down Expand Up @@ -342,7 +342,7 @@ async def list(
- name: typing.Optional[str].
- from_timestamp: typing.Optional[dt.datetime]. Retrieve only traces newer than this timestamp.
- from_timestamp: typing.Optional[dt.datetime]. Retrieve only traces newer than this datetime (ISO 8601).
- order_by: typing.Optional[str]. Format of the string [field].[asc/desc]. Fields: id, timestamp, name, userId, release, version, public, bookmarked, sessionId. Example: timestamp.asc
Expand Down
3 changes: 3 additions & 0 deletions langfuse/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ def create_dataset_item(
metadata: Optional[Any] = None,
source_trace_id: Optional[str] = None,
source_observation_id: Optional[str] = None,
status: Optional[DatasetStatus] = None,
id: Optional[str] = None,
) -> DatasetItem:
"""Create a dataset item.
Expand All @@ -367,6 +368,7 @@ def create_dataset_item(
metadata: Additional metadata. Defaults to None. Can contain any dict, list or scalar.
source_trace_id: Id of the source trace. Defaults to None.
source_observation_id: Id of the source observation. Defaults to None.
status: Status of the dataset item. Defaults to ACTIVE for newly created items.
id: Id of the dataset item. Defaults to None.
Returns:
Expand Down Expand Up @@ -395,6 +397,7 @@ def create_dataset_item(
metadata=metadata,
sourceTraceId=source_trace_id,
sourceObservationId=source_observation_id,
status=status,
id=id,
)
self.log.debug(f"Creating dataset item {body}")
Expand Down
7 changes: 6 additions & 1 deletion tests/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,17 @@ def test_upsert_and_get_dataset_item():

new_input = {"input": "Hello World 2"}
langfuse.create_dataset_item(
dataset_name=name, input=new_input, id=item.id, expected_output=new_input
dataset_name=name,
input=new_input,
id=item.id,
expected_output=new_input,
status="ARCHIVED",
)
get_new_item = langfuse.get_dataset_item(item.id)
assert get_new_item.input == new_input
assert get_new_item.id == item.id
assert get_new_item.expected_output == new_input
assert get_new_item.status == "ARCHIVED"


def test_linking_observation():
Expand Down

0 comments on commit 8c1b8a4

Please sign in to comment.