-
Notifications
You must be signed in to change notification settings - Fork 17
feat: add basic evaluation example using FakeAdapter #35
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
Merged
aviralgarg05
merged 5 commits into
aviralgarg05:main
from
dharapandya85:add-basic-evaluation-example
Jan 6, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4934a98
fix(example): restore basic evaluation example
dharapandya85 3a427d0
fix(example): align basic evaluation example with current AgentUnit API
dharapandya85 158dfdf
fix(example): align basic example with Runner and BaseAdapter APIs
dharapandya85 9e67660
fix(example): align basic evaluation with current APIs
dharapandya85 1d719e9
fix tracelog import and pass failed tests
dharapandya85 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| from agentunit.adapters.base import AdapterOutcome, BaseAdapter | ||
| from agentunit.core.runner import Runner | ||
| from agentunit.core.scenario import Scenario | ||
| from agentunit.core.trace import TraceLog | ||
| from agentunit.datasets.base import DatasetCase, DatasetSource | ||
|
|
||
|
|
||
| class FakeAdapter(BaseAdapter): | ||
| """ | ||
| A minimal adapter implementation used for testing and examples. | ||
|
|
||
| FakeAdapter simulates an adapter without performing real computation, it returns predefined response. | ||
| This becomes useful in representing integration of adapters with the AgentUnit. | ||
| """ | ||
|
|
||
| def __init__(self, response: str): | ||
| """ | ||
| Initialize adapter with static response. | ||
|
|
||
| Args: | ||
| response (str): The output string returns on execution. | ||
| """ | ||
| self.response = response | ||
|
|
||
| def prepare(self): | ||
| """ | ||
| Prepare adapter before execution. | ||
|
|
||
| FakeAdapter do nor require setup. | ||
| """ | ||
|
|
||
| def execute(self, case, trace_log: TraceLog) -> AdapterOutcome: | ||
| """ | ||
| Execute the adapter for a given evaluation case. | ||
|
|
||
| Args: | ||
| case(object): Input case of evaluation. | ||
| trace_log (TraceLog): Trace log for recording execution details. | ||
| """ | ||
| return AdapterOutcome(success=True, output=self.response, error=None) | ||
|
|
||
| def cleanup(self): | ||
| """ | ||
| Cleanup adapter resources. | ||
|
|
||
| No cleanup required for FakeAdapter. | ||
| """ | ||
|
|
||
|
|
||
| def main() -> None: | ||
| # define simple dataset | ||
| cases = [ | ||
| DatasetCase( | ||
| id="case_1", | ||
| input="hello", | ||
| expected_output="hello", | ||
| ) | ||
| ] | ||
|
|
||
| # create a scenario using the fake adapter | ||
| scenario = Scenario( | ||
| name="Basic Evaluation Example", | ||
| adapter=FakeAdapter(response="hello"), | ||
| dataset=DatasetSource.from_list(cases), | ||
| ) | ||
|
|
||
| # run evaluation | ||
| runner = Runner([scenario]) | ||
| result = runner.run() | ||
|
|
||
| scenario_result = result.scenarios[0] | ||
| # print summary | ||
| print("=== Evaluation Summary ===") | ||
| print(f"Scenario: {scenario.name}") | ||
| print(f"Success rate: {scenario_result.success_rate:.0%}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix DatasetCase field names to match the API.
The
DatasetCaseconstructor arguments don't match the actual field names defined in the class. From the relevant code snippets,DatasetCasehas:id: str(required)query: str(required, notinput)expected_output: str | None(optional, notexpected)This will cause a
TypeErrorat runtime, violating the acceptance criteria that the script must run without errors.🔎 Proposed fix for DatasetCase construction
cases = [ DatasetCase( - input="hello", - expected="hello", + id="case_1", + query="hello", + expected_output="hello", ) ]🤖 Prompt for AI Agents