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(datasets): upgrade to v2 api, get_dataset() fetches items in pages, add get_dataset_runs() #768

Merged
merged 9 commits into from
Jul 2, 2024
20 changes: 16 additions & 4 deletions langfuse/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
BasePrompt,
ChatMessage,
ChatPrompt,
ConfigCategory,
CreateChatPromptRequest,
CreateDatasetItemRequest,
CreateDatasetRequest,
Expand All @@ -25,12 +26,11 @@
DailyMetrics,
DailyMetricsDetails,
Dataset,
DatasetCore,
DatasetItem,
DatasetRun,
DatasetRunItem,
DatasetRunWithItems,
DatasetStatus,
DatasetWithReferences,
Error,
HealthResponse,
IngestionError,
Expand Down Expand Up @@ -61,6 +61,8 @@
ObservationsViews,
OpenAiUsage,
OptionalObservationBody,
PaginatedDatasetItems,
PaginatedDatasetRuns,
PaginatedDatasets,
Project,
Projects,
Expand All @@ -71,6 +73,9 @@
Prompt_Text,
Score,
ScoreBody,
ScoreConfig,
ScoreConfigs,
ScoreDataType,
ScoreEvent,
ScoreSource,
Scores,
Expand Down Expand Up @@ -107,6 +112,7 @@
projects,
prompts,
score,
score_configs,
sessions,
trace,
utils,
Expand All @@ -118,6 +124,7 @@
"BasePrompt",
"ChatMessage",
"ChatPrompt",
"ConfigCategory",
"CreateChatPromptRequest",
"CreateDatasetItemRequest",
"CreateDatasetRequest",
Expand All @@ -137,12 +144,11 @@
"DailyMetrics",
"DailyMetricsDetails",
"Dataset",
"DatasetCore",
"DatasetItem",
"DatasetRun",
"DatasetRunItem",
"DatasetRunWithItems",
"DatasetStatus",
"DatasetWithReferences",
"Error",
"HealthResponse",
"IngestionError",
Expand Down Expand Up @@ -173,6 +179,8 @@
"ObservationsViews",
"OpenAiUsage",
"OptionalObservationBody",
"PaginatedDatasetItems",
"PaginatedDatasetRuns",
"PaginatedDatasets",
"Project",
"Projects",
Expand All @@ -183,6 +191,9 @@
"Prompt_Text",
"Score",
"ScoreBody",
"ScoreConfig",
"ScoreConfigs",
"ScoreDataType",
"ScoreEvent",
"ScoreSource",
"Scores",
Expand Down Expand Up @@ -219,6 +230,7 @@
"projects",
"prompts",
"score",
"score_configs",
"sessions",
"trace",
"utils",
Expand Down
5 changes: 5 additions & 0 deletions langfuse/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from .resources.projects.client import AsyncProjectsClient, ProjectsClient
from .resources.prompts.client import AsyncPromptsClient, PromptsClient
from .resources.score.client import AsyncScoreClient, ScoreClient
from .resources.score_configs.client import AsyncScoreConfigsClient, ScoreConfigsClient
from .resources.sessions.client import AsyncSessionsClient, SessionsClient
from .resources.trace.client import AsyncTraceClient, TraceClient

Expand Down Expand Up @@ -100,6 +101,7 @@ def __init__(
self.observations = ObservationsClient(client_wrapper=self._client_wrapper)
self.projects = ProjectsClient(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)
self.sessions = SessionsClient(client_wrapper=self._client_wrapper)
self.trace = TraceClient(client_wrapper=self._client_wrapper)
Expand Down Expand Up @@ -185,6 +187,9 @@ def __init__(
self.observations = AsyncObservationsClient(client_wrapper=self._client_wrapper)
self.projects = AsyncProjectsClient(client_wrapper=self._client_wrapper)
self.prompts = AsyncPromptsClient(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)
22 changes: 16 additions & 6 deletions langfuse/api/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@
projects,
prompts,
score,
score_configs,
sessions,
trace,
utils,
)
from .commons import (
AccessDeniedError,
ConfigCategory,
Dataset,
DatasetCore,
DatasetItem,
DatasetRun,
DatasetRunItem,
DatasetRunWithItems,
DatasetStatus,
DatasetWithReferences,
Error,
MapValue,
MethodNotAllowedError,
Expand All @@ -34,6 +35,8 @@
ObservationLevel,
ObservationsView,
Score,
ScoreConfig,
ScoreDataType,
ScoreSource,
Session,
SessionWithTraces,
Expand All @@ -43,9 +46,9 @@
UnauthorizedError,
Usage,
)
from .dataset_items import CreateDatasetItemRequest
from .dataset_items import CreateDatasetItemRequest, PaginatedDatasetItems
from .dataset_run_items import CreateDatasetRunItemRequest
from .datasets import CreateDatasetRequest, PaginatedDatasets
from .datasets import CreateDatasetRequest, PaginatedDatasetRuns, PaginatedDatasets
from .health import HealthResponse, ServiceUnavailableError
from .ingestion import (
BaseEvent,
Expand Down Expand Up @@ -108,6 +111,7 @@
TextPrompt,
)
from .score import CreateScoreRequest, Scores
from .score_configs import ScoreConfigs
from .trace import Sort, Traces

__all__ = [
Expand All @@ -116,6 +120,7 @@
"BasePrompt",
"ChatMessage",
"ChatPrompt",
"ConfigCategory",
"CreateChatPromptRequest",
"CreateDatasetItemRequest",
"CreateDatasetRequest",
Expand All @@ -135,12 +140,11 @@
"DailyMetrics",
"DailyMetricsDetails",
"Dataset",
"DatasetCore",
"DatasetItem",
"DatasetRun",
"DatasetRunItem",
"DatasetRunWithItems",
"DatasetStatus",
"DatasetWithReferences",
"Error",
"HealthResponse",
"IngestionError",
Expand Down Expand Up @@ -171,6 +175,8 @@
"ObservationsViews",
"OpenAiUsage",
"OptionalObservationBody",
"PaginatedDatasetItems",
"PaginatedDatasetRuns",
"PaginatedDatasets",
"Project",
"Projects",
Expand All @@ -181,6 +187,9 @@
"Prompt_Text",
"Score",
"ScoreBody",
"ScoreConfig",
"ScoreConfigs",
"ScoreDataType",
"ScoreEvent",
"ScoreSource",
"Scores",
Expand Down Expand Up @@ -217,6 +226,7 @@
"projects",
"prompts",
"score",
"score_configs",
"sessions",
"trace",
"utils",
Expand Down
12 changes: 8 additions & 4 deletions langfuse/api/resources/commons/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
# This file was auto-generated by Fern from our API Definition.

from .types import (
ConfigCategory,
Dataset,
DatasetCore,
DatasetItem,
DatasetRun,
DatasetRunItem,
DatasetRunWithItems,
DatasetStatus,
DatasetWithReferences,
MapValue,
ModelUsageUnit,
Observation,
ObservationLevel,
ObservationsView,
Score,
ScoreConfig,
ScoreDataType,
ScoreSource,
Session,
SessionWithTraces,
Expand All @@ -32,13 +34,13 @@

__all__ = [
"AccessDeniedError",
"ConfigCategory",
"Dataset",
"DatasetCore",
"DatasetItem",
"DatasetRun",
"DatasetRunItem",
"DatasetRunWithItems",
"DatasetStatus",
"DatasetWithReferences",
"Error",
"MapValue",
"MethodNotAllowedError",
Expand All @@ -48,6 +50,8 @@
"ObservationLevel",
"ObservationsView",
"Score",
"ScoreConfig",
"ScoreDataType",
"ScoreSource",
"Session",
"SessionWithTraces",
Expand Down
12 changes: 8 additions & 4 deletions langfuse/api/resources/commons/types/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# This file was auto-generated by Fern from our API Definition.

from .config_category import ConfigCategory
from .dataset import Dataset
from .dataset_core import DatasetCore
from .dataset_item import DatasetItem
from .dataset_run import DatasetRun
from .dataset_run_item import DatasetRunItem
from .dataset_run_with_items import DatasetRunWithItems
from .dataset_status import DatasetStatus
from .dataset_with_references import DatasetWithReferences
from .map_value import MapValue
from .model_usage_unit import ModelUsageUnit
from .observation import Observation
from .observation_level import ObservationLevel
from .observations_view import ObservationsView
from .score import Score
from .score_config import ScoreConfig
from .score_data_type import ScoreDataType
from .score_source import ScoreSource
from .session import Session
from .session_with_traces import SessionWithTraces
Expand All @@ -22,19 +24,21 @@
from .usage import Usage

__all__ = [
"ConfigCategory",
"Dataset",
"DatasetCore",
"DatasetItem",
"DatasetRun",
"DatasetRunItem",
"DatasetRunWithItems",
"DatasetStatus",
"DatasetWithReferences",
"MapValue",
"ModelUsageUnit",
"Observation",
"ObservationLevel",
"ObservationsView",
"Score",
"ScoreConfig",
"ScoreDataType",
"ScoreSource",
"Session",
"SessionWithTraces",
Expand Down
34 changes: 34 additions & 0 deletions langfuse/api/resources/commons/types/config_category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This file was auto-generated by Fern from our API Definition.

import datetime as dt
import typing

from ....core.datetime_utils import serialize_datetime
from ....core.pydantic_utilities import pydantic_v1


class ConfigCategory(pydantic_v1.BaseModel):
value: float
label: str

def json(self, **kwargs: typing.Any) -> str:
kwargs_with_defaults: typing.Any = {
"by_alias": True,
"exclude_unset": True,
**kwargs,
}
return super().json(**kwargs_with_defaults)

def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
kwargs_with_defaults: typing.Any = {
"by_alias": True,
"exclude_unset": True,
**kwargs,
}
return super().dict(**kwargs_with_defaults)

class Config:
frozen = True
smart_union = True
extra = pydantic_v1.Extra.allow
json_encoders = {dt.datetime: serialize_datetime}
17 changes: 8 additions & 9 deletions langfuse/api/resources/commons/types/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@

from ....core.datetime_utils import serialize_datetime
from ....core.pydantic_utilities import pydantic_v1
from .dataset_core import DatasetCore
from .dataset_item import DatasetItem


class Dataset(DatasetCore):
"""
Dataset including all items
"""

items: typing.List[DatasetItem]
runs: typing.List[str]
class Dataset(pydantic_v1.BaseModel):
id: str
name: str
description: typing.Optional[str] = None
metadata: typing.Optional[typing.Any] = None
project_id: str = pydantic_v1.Field(alias="projectId")
created_at: dt.datetime = pydantic_v1.Field(alias="createdAt")
updated_at: dt.datetime = pydantic_v1.Field(alias="updatedAt")

def json(self, **kwargs: typing.Any) -> str:
kwargs_with_defaults: typing.Any = {
Expand Down
4 changes: 0 additions & 4 deletions langfuse/api/resources/commons/types/dataset_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from ....core.datetime_utils import serialize_datetime
from ....core.pydantic_utilities import pydantic_v1
from .dataset_run_item import DatasetRunItem


class DatasetRun(pydantic_v1.BaseModel):
Expand All @@ -17,9 +16,6 @@ class DatasetRun(pydantic_v1.BaseModel):
dataset_name: str = pydantic_v1.Field(alias="datasetName")
created_at: dt.datetime = pydantic_v1.Field(alias="createdAt")
updated_at: dt.datetime = pydantic_v1.Field(alias="updatedAt")
dataset_run_items: typing.List[DatasetRunItem] = pydantic_v1.Field(
alias="datasetRunItems"
)

def json(self, **kwargs: typing.Any) -> str:
kwargs_with_defaults: typing.Any = {
Expand Down
Loading
Loading