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: PHS-392 added metadata to Example #902

Merged
merged 1 commit into from
Jun 11, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- `Lineages` now contain `Tracer` for individual `Output`s.
- `convert_to_pandas_data_frame` now also creates a column containing the `Tracer`s.
- `run_dataset` now has a flag `trace_examples_individually` to create `Tracer`s for each example. Defaults to True.
- Added optional `metadata` field to `Example`.

### Fixes
- ControlModels throw a warning instead of an error in case a not-recommended model is selected.
Expand Down
3 changes: 3 additions & 0 deletions src/documentation/how_tos/how_to_create_a_dataset.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
" Example(\n",
" input=StoryTaskInput(topic=\"rain\", targeted_word_count=42),\n",
" expected_output=StoryTaskExpectedOutput(keywords=[\"wet\"]),\n",
" metadata={\n",
" \"author\": \"Shakespeare\"\n",
" }, # the metadata is optional and can contain custom information\n",
" ),\n",
" # ...\n",
"]\n",
Expand Down
2 changes: 2 additions & 0 deletions src/intelligence_layer/connectors/base/json_serializable.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@
| Sequence["JsonSerializable"]
| Mapping[str, "JsonSerializable"],
)

SerializableDict = dict[str, JsonSerializable]
7 changes: 6 additions & 1 deletion src/intelligence_layer/evaluation/dataset/domain.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from typing import Generic, TypeVar
from typing import Generic, Optional, TypeVar
from uuid import uuid4

from pydantic import BaseModel, Field
from rich.tree import Tree

from intelligence_layer.connectors.base.json_serializable import SerializableDict
from intelligence_layer.core.task import Input
from intelligence_layer.core.tracer.tracer import PydanticSerializable

Expand All @@ -30,6 +31,7 @@ class Example(BaseModel, Generic[Input, ExpectedOutput]):
input: Input
expected_output: ExpectedOutput
id: str = Field(default_factory=lambda: str(uuid4()))
metadata: Optional[SerializableDict] = None

def __repr__(self) -> str:
return self.__str__()
Expand All @@ -39,12 +41,15 @@ def __str__(self) -> str:
f"Example ID = {self.id}\n"
f"Input = {self.input}\n"
f'Expected output = "{self.expected_output}"\n'
f"Metadata = {self.metadata}\n"
)

def _rich_render(self) -> Tree:
example_tree = Tree(f"Example: {self.id}")
example_tree.add("Input").add(str(self.input))
example_tree.add("Expected Output").add(str(self.expected_output))
if self.metadata:
example_tree.add("Metadata").add(str(self.metadata))
return example_tree


Expand Down
6 changes: 5 additions & 1 deletion tests/evaluation/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ def file_run_repository(tmp_path: Path) -> FileRunRepository:

@fixture
def dummy_string_example() -> Example[DummyStringInput, DummyStringOutput]:
return Example(input=DummyStringInput(), expected_output=DummyStringOutput())
return Example(
input=DummyStringInput(),
expected_output=DummyStringOutput(),
metadata={"some_key": "some_value"},
)


@fixture
Expand Down