Skip to content

Commit

Permalink
Add as_dict utility method to Score (#653)
Browse files Browse the repository at this point in the history
* Add as_dict utility method to Score

* Remove newline

* Update CHANGELOG.md

---------

Co-authored-by: jjallaire <[email protected]>
  • Loading branch information
rusheb and jjallaire authored Oct 6, 2024
1 parent 7046263 commit 3f3af80
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- Add `as_dict()` utility method to `Score`

## v0.3.40 (6 October 2024)

- Add `interactive` option to `web_browser()` for disabling interactive tools (clicking, typing, and submitting forms).
Expand Down
7 changes: 7 additions & 0 deletions src/inspect_ai/scorer/_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ def as_bool(self) -> bool:
"""Read the score as a boolean."""
return bool(self._as_scalar())

def as_dict(self) -> dict[str, str | int | float | bool | None]:
"""Read the score as a dictionary."""
if isinstance(self.value, dict):
return self.value
else:
raise ValueError("This score is not a dictionary")

def _as_scalar(self) -> str | int | float | bool:
if isinstance(self.value, str | int | float | bool):
return self.value
Expand Down

0 comments on commit 3f3af80

Please sign in to comment.