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

🍌 Update eval to print failure reason #3

Merged
merged 1 commit into from
Nov 13, 2023
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
7 changes: 5 additions & 2 deletions bananalyzer/data/schemas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from abc import ABC, abstractmethod
from typing import Any, Dict, List, Literal, Optional, Union

import pytest
from pydantic import BaseModel, Field, model_validator

from bananalyzer.data.fetch_schemas import fetch_schemas
Expand Down Expand Up @@ -37,8 +38,10 @@ def eval_action(self, _: str) -> bool:
# We don't care about action level evaluations
return True

def eval_results(self, result: Dict[str, Any]) -> bool:
return result == self.expected
def eval_results(self, result: Dict[str, Any]) -> None:
if result != self.expected:
diff_msg = f"Expected: {self.expected}\nActual: {result}"
pytest.fail(f"JSONEval mismatch:\n{diff_msg}")


class ActionEval(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion bananalyzer/runner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async def test_{example.id.replace("-", "_")}() -> None:
# The agent is imported into the global context prior to this call
result = await agent.run(context, example)
for curr_eval in example.evals:
assert curr_eval.eval_results(result)
curr_eval.eval_results(result)
""",
example=example,
)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "bananalyzer"
version = "0.2.1"
version = "0.2.2"
description = "Open source AI Agent evaluation framework for web tasks 🐒🍌"
authors = ["asim-shrestha <[email protected]>"]
readme = "README.md"
Expand Down
8 changes: 5 additions & 3 deletions tests/data/test_example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any, Dict, Optional

import pytest
from _pytest.outcomes import Failed
from pydantic import ValidationError

from bananalyzer.data.fetch_schemas import fetch_schemas
Expand All @@ -12,9 +13,10 @@ def test_json_eval() -> None:

eval = JSONEval(expected=json)

assert eval.eval_results(json)
assert eval.eval_results({"two": "two", "one": "one"})
assert not eval.eval_results({"test": "test"})
eval.eval_results(json)
eval.eval_results({"two": "two", "one": "one"})
with pytest.raises(Failed):
eval.eval_results({"test": "test"})


def create_default_example(
Expand Down