Skip to content

Commit

Permalink
feat: PHS-392 added metadata to Example (#902)
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixFehse authored Jun 11, 2024
1 parent 9a9afcb commit 0433d88
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
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

0 comments on commit 0433d88

Please sign in to comment.