Skip to content

feat: make datasetId optional for experiments #91

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions literalai/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1104,25 +1104,25 @@ def delete_dataset(self, id: str):

def create_experiment(
self,
dataset_id: str,
name: str,
dataset_id: Optional[str] = None,
prompt_id: Optional[str] = None,
params: Optional[Dict] = None,
) -> "DatasetExperiment":
"""
Creates a new experiment associated with a specific dataset.

Args:
dataset_id (str): The unique identifier of the dataset.
name (str): The name of the experiment.
dataset_id (Optional[str]): The unique identifier of the dataset.
prompt_id (Optional[str]): The identifier of the prompt associated with the experiment.
params (Optional[Dict]): Additional parameters for the experiment.

Returns:
DatasetExperiment: The newly created experiment object.
"""
return self.gql_helper(
*create_experiment_helper(self, dataset_id, name, prompt_id, params)
*create_experiment_helper(self, name, dataset_id, prompt_id, params)
)

def create_experiment_item(
Expand Down Expand Up @@ -2315,15 +2315,15 @@ async def delete_dataset(self, id: str):

async def create_experiment(
self,
dataset_id: str,
name: str,
dataset_id: Optional[str] = None,
prompt_id: Optional[str] = None,
params: Optional[Dict] = None,
) -> "DatasetExperiment":
sync_api = LiteralAPI(self.api_key, self.url)

return await self.gql_helper(
*create_experiment_helper(sync_api, dataset_id, name, prompt_id, params)
*create_experiment_helper(sync_api, name, dataset_id, prompt_id, params)
)

create_experiment.__doc__ = LiteralAPI.create_experiment.__doc__
Expand Down
4 changes: 2 additions & 2 deletions literalai/api/dataset_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ def process_response(response):

def create_experiment_helper(
api: "LiteralAPI",
dataset_id: str,
name: str,
dataset_id: Optional[str] = None,
prompt_id: Optional[str] = None,
params: Optional[Dict] = None,
):
Expand All @@ -119,7 +119,7 @@ def process_response(response):

def create_experiment_item_helper(
dataset_experiment_id: str,
dataset_item_id: str,
dataset_item_id: Optional[str] = None,
input: Optional[Dict] = None,
output: Optional[Dict] = None,
):
Expand Down
4 changes: 2 additions & 2 deletions literalai/api/gql.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@
CREATE_EXPERIMENT = """
mutation CreateDatasetExperiment(
$name: String!
$datasetId: String!
$datasetId: String
$promptId: String
$params: Json
) {
Expand All @@ -854,7 +854,7 @@
CREATE_EXPERIMENT_ITEM = """
mutation CreateDatasetExperimentItem(
$datasetExperimentId: String!
$datasetItemId: String!
$datasetItemId: String
$input: Json
$output: Json
) {
Expand Down
18 changes: 7 additions & 11 deletions literalai/dataset_experiment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from dataclasses import dataclass, field
from typing import Dict, List, Optional, TypedDict
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Dict, List, Optional, TypedDict

from literalai.my_types import ScoreDict, Utils

Expand All @@ -11,7 +10,7 @@
class DatasetExperimentItemDict(TypedDict, total=False):
id: str
datasetExperimentId: str
datasetItemId: str
datasetItemId: Optional[str]
scores: List[ScoreDict]
input: Optional[Dict]
output: Optional[Dict]
Expand All @@ -21,7 +20,7 @@ class DatasetExperimentItemDict(TypedDict, total=False):
class DatasetExperimentItem(Utils):
id: str
dataset_experiment_id: str
dataset_item_id: str
dataset_item_id: Optional[str]
scores: List[ScoreDict]
input: Optional[Dict]
output: Optional[Dict]
Expand All @@ -41,7 +40,7 @@ def from_dict(cls, item: DatasetExperimentItemDict) -> "DatasetExperimentItem":
return cls(
id=item.get("id", ""),
dataset_experiment_id=item.get("datasetExperimentId", ""),
dataset_item_id=item.get("datasetItemId", ""),
dataset_item_id=item.get("datasetItemId"),
scores=item.get("scores", []),
input=item.get("input"),
output=item.get("output"),
Expand All @@ -64,7 +63,7 @@ class DatasetExperiment(Utils):
id: str
created_at: str
name: str
dataset_id: str
dataset_id: Optional[str]
params: Optional[Dict]
prompt_id: Optional[str] = None
items: List[DatasetExperimentItem] = field(default_factory=lambda: [])
Expand All @@ -73,7 +72,7 @@ def log(self, item_dict: DatasetExperimentItemDict) -> DatasetExperimentItem:
dataset_experiment_item = DatasetExperimentItem.from_dict(
{
"datasetExperimentId": self.id,
"datasetItemId": item_dict.get("datasetItemId", ""),
"datasetItemId": item_dict.get("datasetItemId"),
"input": item_dict.get("input", {}),
"output": item_dict.get("output", {}),
"scores": item_dict.get("scores", []),
Expand Down Expand Up @@ -110,8 +109,5 @@ def from_dict(
dataset_id=dataset_experiment.get("datasetId", ""),
params=dataset_experiment.get("params"),
prompt_id=dataset_experiment.get("promptId"),
items=[
DatasetExperimentItem.from_dict(item)
for item in items
],
items=[DatasetExperimentItem.from_dict(item) for item in items],
)
Loading