-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AIC-py][eval] small refactor to ease defining metrics, add tests
- Add decorators for metric creation and reimplement some existing ones - Add a unit test Test plan: Existing and new unit tests.
- Loading branch information
1 parent
204ee2f
commit 4f024fa
Showing
4 changed files
with
199 additions
and
64 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,28 +1,44 @@ | ||
from typing import Any | ||
from abc import abstractmethod | ||
from typing import Any, Protocol | ||
|
||
from aiconfig.Config import AIConfigRuntime | ||
from aiconfig.model_parser import InferenceOptions | ||
|
||
|
||
class MockAIConfigRuntime(AIConfigRuntime): | ||
def __init__(self): | ||
class MockRunTextToText(Protocol): | ||
@abstractmethod | ||
async def __call__(self, prompt_name: str, params: dict[str, str]) -> str: | ||
pass | ||
|
||
async def run_and_get_output_text( | ||
self, | ||
prompt_name: str, | ||
params: dict[Any, Any] | None = None, | ||
options: InferenceOptions | None = None, | ||
**kwargs, # type: ignore | ||
) -> str: | ||
""" | ||
This overrides the real method for mocking, but the output doesn't matter very much. | ||
We're currently not really testing properties of the output. | ||
We just have to return a string so the tests work. | ||
Real method: https://github.com/lastmile-ai/aiconfig/blob/a4376d1f951e19776633d397a3cda7fa85506eef/python/src/aiconfig/Config.py#L277 | ||
""" | ||
params_ = params or {} | ||
assert params_.keys() == {"the_query"}, 'For eval, AIConfig params must have just the key "the_query".' | ||
the_query = params_["the_query"] | ||
return f"output_for_{prompt_name}_the_query_{the_query}" | ||
|
||
def make_mock_aiconfig_runtime(mock_run_text_to_text: MockRunTextToText | None = None) -> AIConfigRuntime: | ||
async def _default_mock_run_text_to_text(prompt_name: str, params: dict[str, str]) -> str: | ||
return f"output_for_{prompt_name}_the_query_{params['the_query']}" | ||
|
||
mock_run_text_to_text_impl = _default_mock_run_text_to_text if mock_run_text_to_text is None else mock_run_text_to_text | ||
|
||
class _MockAIConfigRuntime(AIConfigRuntime): | ||
def __init__(self): | ||
pass | ||
|
||
async def run_and_get_output_text( | ||
self, | ||
prompt_name: str, | ||
params: dict[Any, Any] | None = None, | ||
options: InferenceOptions | None = None, | ||
**kwargs, # type: ignore | ||
) -> str: | ||
""" | ||
This overrides the real method for mocking, but the output doesn't matter very much. | ||
We're currently not really testing properties of the output. | ||
We just have to return a string so the tests work. | ||
Real method: https://github.com/lastmile-ai/aiconfig/blob/a4376d1f951e19776633d397a3cda7fa85506eef/python/src/aiconfig/Config.py#L277 | ||
""" | ||
params_ = params or {} | ||
return await mock_run_text_to_text_impl(prompt_name, params_) | ||
|
||
return _MockAIConfigRuntime() | ||
|
||
|
||
MockAIConfigRuntime = lambda: make_mock_aiconfig_runtime() |
This file contains 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