-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add datasets client #274
Add datasets client #274
Conversation
📝 Walkthrough📝 WalkthroughWalkthroughThe changes enhance the API client by improving dataset retrieval functionality and ensuring proper URI encoding for identifiers in API requests. A new method, Changes
Possibly related PRs
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (3)
autoblocks/api/models.py (1)
Please update all existing imports to use the new
Dataset
andDatasetItem
fromautoblocks/api/models.py
and remove the old references from_impl/api/models.py
. Additionally, verify the usage inragas_base.py
to ensure consistency.🔗 Analysis chain
Line range hint
1-53
: Overall, the changes look good and align with the PR objective.The additions of
Dataset
andDatasetItem
to this file are straightforward and follow the existing patterns. However, it's important to ensure that these new models are properly integrated into the rest of the codebase.Let's verify if there are any existing references to these new models in other files:
This script will help identify if there are any existing references to
Dataset
orDatasetItem
in other Python files, which might need to be updated to use these new imports.
Let's update the shell script to use the correct file type identifier for Python files and re-run the search.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for potential usage of the new Dataset and DatasetItem models in other files. echo "Searching for potential usage of Dataset:" rg --type python -g '!autoblocks/api/models.py' 'Dataset' echo "Searching for potential usage of DatasetItem:" rg --type python -g '!autoblocks/api/models.py' 'DatasetItem'Length of output: 375
Script:
#!/bin/bash # Description: Check for potential usage of the new Dataset and DatasetItem models in other files. echo "Searching for potential usage of Dataset:" rg --type py -g '!autoblocks/api/models.py' 'Dataset' echo "Searching for potential usage of DatasetItem:" rg --type py -g '!autoblocks/api/models.py' 'DatasetItem'Length of output: 1358
autoblocks/_impl/api/models.py (2)
191-194
: LGTM! Consider using a more specific type fordata
.The
DatasetItem
class looks good and provides a flexible structure for dataset items. However, consider if a more specific type thanDict[str, Any]
could be used for thedata
field to improve type safety.If the structure of the data is known, you could define a custom type or use
TypedDict
for better type hinting:from typing import TypedDict class DataItemContent(TypedDict): field1: str field2: int # Add other fields as needed @dataclass class DatasetItem: id: str data: DataItemContentThis approach would provide better type checking and code completion in IDEs.
197-202
: LGTM! Consider adding docstrings for clarity.The
Dataset
class is well-structured and provides a good foundation for managing datasets with versioning capabilities. The fields are appropriate and cover essential aspects of dataset management.To improve code clarity and maintainability, consider adding docstrings to the class and its fields. For example:
@dataclass class Dataset: """Represents a versioned dataset containing multiple items.""" name: str """The name of the dataset.""" schema_version: str """The version of the schema used for this dataset.""" revision_id: str """A unique identifier for this specific revision of the dataset.""" items: List[DatasetItem] """The list of items contained in this dataset."""This addition would provide more context for developers working with this class in the future.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
- autoblocks/_impl/api/client.py (6 hunks)
- autoblocks/_impl/api/models.py (1 hunks)
- autoblocks/api/models.py (2 hunks)
🔇 Additional comments (9)
autoblocks/api/models.py (2)
2-3
: LGTM: New imports added correctly.The new imports for
Dataset
andDatasetItem
have been added correctly, following the existing import style in the file. These additions align with the PR objective of adding a datasets client.
39-40
: LGTM:__all__
list updated correctly.The
__all__
list has been properly updated to include the newDataset
andDatasetItem
models. The additions maintain the alphabetical order, which is good for consistency and readability.autoblocks/_impl/api/models.py (1)
191-202
: Summary: Dataset models implemented correctlyThe implementation of
DatasetItem
andDataset
classes aligns well with the PR objective of adding a datasets client. These new models provide a solid foundation for managing datasets within the system.A few minor suggestions were made to enhance type safety and documentation, but overall, the changes look good and are ready for integration.
autoblocks/_impl/api/client.py (6)
14-15
: LGTM!The imports for
Dataset
andDatasetItem
models are necessary for the newget_dataset
method.
36-36
: LGTM!The import for
encode_uri_component
is necessary for properly encoding URI components in the API requests.
91-91
: LGTM!The
view_id
is now properly encoded using theencode_uri_component
function before being used in the API endpoint URL. This ensures that any special characters in theview_id
are correctly handled.
143-143
: LGTM!The
job_id
is now properly encoded using theencode_uri_component
function before being used in the API endpoint URL. This ensures that any special characters in thejob_id
are correctly handled.
154-156
: LGTM!Both
job_id
andtest_case_id
are now properly encoded using theencode_uri_component
function before being used in the API endpoint URL. This ensures that any special characters in these IDs are correctly handled.
210-226
: LGTM!The new
get_dataset
method is implemented correctly:
- It takes the necessary parameters:
name
,schema_version
, and an optionalrevision_id
.- It properly encodes the
name
,schema_version
, andrevision_id
(if provided) using theencode_uri_component
function before using them in the API endpoint URL.- It constructs the appropriate API endpoint URL based on whether
revision_id
is provided or not.- It raises an exception if the API request fails.
- It processes the API response and returns a
Dataset
object with the correct attributes:name
,schema_version
,revision_id
, and a list ofDatasetItem
objects.
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
autoblocks/_impl/testing/models.py (1)
125-129
: LGTM with a minor suggestion for improvement.The new
serialize_dataset_item_id
method is a good addition that aligns with the PR objective of adding datasets functionality. It provides a clear extension point for subclasses to implement custom serialization of dataset item IDs.Consider enhancing the docstring to provide more context about the purpose and usage of this method. For example:
def serialize_dataset_item_id(self) -> Optional[str]: """ Override this method to set the dataset item ID for this test case. This method is used to provide a unique identifier for the test case when it's added to a dataset. If not overridden, no dataset item ID will be set (returns None). Returns: Optional[str]: The dataset item ID for this test case, or None if not applicable. """ return NoneThis expanded docstring provides more information about when and why a subclass might want to override this method.
autoblocks/_impl/testing/api.py (1)
225-225
: LGTM! Consider adding error handling forserialize_dataset_item_id()
.The addition of
dataset_item_id
to the test case result payload is implemented correctly and consistently for both CLI and public API calls. This change enhances the data being sent during the test case result submission by including the serialized dataset item ID.Consider adding error handling for the case where
serialize_dataset_item_id()
might return None or raise an exception. For example:try: dataset_item_id = test_case_ctx.test_case.serialize_dataset_item_id() except AttributeError: log.warning("TestCase does not have serialize_dataset_item_id method") dataset_item_id = None except Exception as e: log.error(f"Error serializing dataset item ID: {e}") dataset_item_id = NoneThis will make the code more robust and prevent potential crashes if the
serialize_dataset_item_id()
method is not implemented or raises an exception.Also applies to: 238-238, 257-257
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- autoblocks/_impl/testing/api.py (3 hunks)
- autoblocks/_impl/testing/models.py (1 hunks)
🔇 Additional comments (1)
autoblocks/_impl/testing/models.py (1)
125-129
: Verify usage of the new method in the codebase.The
serialize_dataset_item_id
method has been added successfully. To ensure its effectiveness, we should verify its usage across the codebase.Let's run a script to check for any references to this new method:
This script will help us identify where the new method is being called or overridden, ensuring it's properly integrated into the datasets functionality.
✅ Verification successful
Usage of
serialize_dataset_item_id
Verified Successfully.
- The method is defined in
autoblocks/_impl/testing/models.py
.- It is called in
autoblocks/_impl/testing/api.py
.All usages of the new method have been verified and properly integrated.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for references to serialize_dataset_item_id method # Search for direct calls to serialize_dataset_item_id echo "Searching for direct calls to serialize_dataset_item_id:" rg "serialize_dataset_item_id\(" --type py # Search for classes that might be overriding this method echo "\nSearching for potential overrides of serialize_dataset_item_id:" rg "class.*\(.*BaseTestCase.*\):" --type py -A 10 | rg "def serialize_dataset_item_id"Length of output: 596
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.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (1)
tests/autoblocks/test_run_manager.py (1)
147-147
: LGTM. Consider updating related documentation.The addition of
datasetItemId=None
to the test case result dictionary is a good change. It suggests that theRunManager.add_result
method now supports an optionaldatasetItemId
parameter.To ensure comprehensive documentation and testing:
- Update the docstring for the
RunManager.add_result
method to include information about the newdatasetItemId
parameter.- Consider adding a test case that explicitly sets a non-None value for
datasetItemId
to ensure the parameter is correctly passed through to the API.- If there's a user-facing API documentation, make sure it's updated to reflect this new optional parameter.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- tests/autoblocks/test_run_manager.py (2 hunks)
- tests/autoblocks/test_run_test_suite.py (52 hunks)
🔇 Additional comments (2)
tests/autoblocks/test_run_test_suite.py (2)
233-233
: Ensure consistent inclusion ofdatasetItemId
The addition of
datasetItemId=None
to the request body enhances clarity by explicitly stating the parameter. This practice ensures consistency across test cases.
3481-3541
: Effective addition oftest_serialize_dataset_item_id
test caseThe new test function
test_serialize_dataset_item_id
enhances test coverage by validating the serialization ofdatasetItemId
. It ensures that this functionality behaves as expected.
@@ -62,7 +62,7 @@ def serialize_for_human_review(self) -> List[HumanReviewField]: | |||
def test_does_not_allow_adding_result_before_starting(): | |||
test_run = RunManager[MyTestCase, MyOutput]("test-id", "Test run") | |||
|
|||
with pytest.raises(ValueError): | |||
with pytest.raises(Exception): |
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.
Consider using a more specific exception type.
The change from ValueError
to Exception
broadens the scope of exceptions that this test will catch. While this ensures the test passes if any exception is raised, it might make the test less specific and could potentially hide bugs if an unexpected exception type is thrown.
Consider the following options:
- If
RunManager.add_result
is expected to raise onlyValueError
, keep the originalValueError
in the test. - If
RunManager.add_result
can raise multiple specific exceptions, usepytest.raises((ValueError, OtherSpecificException))
to catch only the expected exceptions. - If the exact exception type is not crucial, but you want to ensure a specific error message, you can use:
with pytest.raises(Exception) as excinfo: # ... test code ... assert "Expected error message" in str(excinfo.value)
This approach maintains the broadened exception catching while still asserting on the specific error condition.
def serialize_dataset_item_id(self): | ||
return mock_dataset_item_id |
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 the scope issue of mock_dataset_item_id
In the serialize_dataset_item_id
method, mock_dataset_item_id
is used, but it is defined within the scope of the test_serialize_dataset_item_id
function. This will result in a NameError
when serialize_dataset_item_id
is called outside that function. To fix this, store mock_dataset_item_id
as an instance variable of MyCustomTestCase
.
Apply this diff to resolve the scope issue:
+ dataset_item_id: str
def hash(self):
return f"{self.x}-{self.y}"
def serialize_dataset_item_id(self):
- return mock_dataset_item_id
+ return self.dataset_item_id
Update the test case instantiation to pass dataset_item_id
:
MyCustomTestCase(x=1, y=2)
+MyCustomTestCase(x=1, y=2, dataset_item_id=mock_dataset_item_id)
Committable suggestion was skipped due to low confidence.
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (3)
tests/autoblocks/test_ragas_evaluators.py (1)
65-65
: LGTM! Consider adding a docstring update.The addition of
datasetItemId=None
to the request body is a good enhancement, allowing for future association of test results with specific dataset items.Consider updating the function's docstring to reflect this new parameter, explaining its purpose and optional nature. This would improve the function's documentation and make it easier for other developers to understand the change. For example:
def make_expected_requests(evaluator_id: str, httpx_mock: Any) -> None: """ Prepare expected requests for testing. Args: evaluator_id (str): The ID of the evaluator being tested. httpx_mock (Any): The HTTP mock object for request assertions. Note: The function now includes a `datasetItemId` parameter in the request body, which can be used to associate test results with specific dataset items. This parameter is optional and defaults to None. """ # ... rest of the functiontests/autoblocks/test_evaluators.py (2)
91-91
: LGTM. Consider updating documentation.The addition of the
datasetItemId
parameter is consistent and appears to be part of a larger feature implementation. This change maintains backwards compatibility by setting the default value toNone
.Consider updating the function's documentation to explain the purpose and usage of the new
datasetItemId
parameter.
Line range hint
91-1097
: Summary: Consistent implementation ofdatasetItemId
parameter across all test functionsThe changes in this file consistently add a
datasetItemId
parameter (defaulting toNone
) to various function calls across all test functions. This systematic update suggests the implementation of a new feature for dataset-specific testing or tracking while maintaining backwards compatibility.Consider the following recommendations:
- Update the documentation for these test functions to explain the purpose and usage of the new
datasetItemId
parameter.- If not already done, ensure that the corresponding production code properly handles this new parameter.
- Consider adding new test cases that explicitly use non-None
datasetItemId
values to verify the new functionality.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- tests/autoblocks/test_evaluators.py (17 hunks)
- tests/autoblocks/test_ragas_evaluators.py (1 hunks)
🔇 Additional comments (6)
tests/autoblocks/test_evaluators.py (6)
123-123
: LGTM. Consistent implementation.The addition of the
datasetItemId
parameter here maintains consistency within the test function, ensuring all test cases are treated similarly.
201-201
: LGTM. Consistent implementation across test functions.The addition of the
datasetItemId
parameter here extends the support to thetest_is_equals_evaluator
function, maintaining consistency across different test functions in the file.
233-233
: LGTM. Consistent implementation within the function.The addition of the
datasetItemId
parameter here maintains consistency within thetest_is_equals_evaluator
function, ensuring all test cases are treated similarly.
313-313
: LGTM. Consistent implementation across test functions.The addition of the
datasetItemId
parameter here extends the support to thetest_is_valid_json_evaluator
function, maintaining consistency across different test functions in the file.
345-345
: LGTM. Consistent implementation within the function.The addition of the
datasetItemId
parameter here maintains consistency within thetest_is_valid_json_evaluator
function, ensuring all test cases are treated similarly.
427-427
: LGTM. Consistent implementation across all test functions.The addition of the
datasetItemId
parameter to all remaining test functions maintains consistency throughout the file. This systematic change suggests a global update to support dataset-specific testing or tracking.To ensure the changes have been applied consistently, please run the following command:
This command will help confirm that the
datasetItemId
parameter has been added uniformly across all necessary function calls.Also applies to: 462-462, 547-547, 582-582, 668-668, 703-703, 791-791, 826-826, 922-922, 1005-1005, 1097-1097
✅ Verification successful
If the above script still encounters issues, please try the following alternative:
Verification Successful: All relevant function calls include
datasetItemId=None
.The shell script confirmed that the
datasetItemId=None
parameter has been consistently added across all targeted function calls intests/autoblocks/test_evaluators.py
.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that all relevant function calls include the datasetItemId parameter rg --type python 'testCaseBody.*datasetItemId=None' tests/autoblocks/test_evaluators.pyLength of output: 120
Script:
#!/bin/bash # Verify that all relevant function calls include the datasetItemId parameter rg --type py 'testCaseBody.*datasetItemId=None' tests/autoblocks/test_evaluators.pyLength of output: 85
Script:
#!/bin/bash # Alternative verification without specifying file type rg 'testCaseBody.*datasetItemId=None' tests/autoblocks/test_evaluators.pyLength of output: 75
Script:
#!/bin/bash # Verify that all relevant function calls include the datasetItemId parameter set to None rg 'datasetItemId\s*=\s*None' tests/autoblocks/test_evaluators.pyLength of output: 611
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (1)
tests/e2e/test_e2e.py (1)
508-508
: LGTM. Consider adding test cases for non-nulldatasetItemId
.The addition of the
datasetItemId
parameter is a good enhancement to support associating test results with specific dataset items. Setting it toNone
in this test case is appropriate for backward compatibility.Consider adding additional test cases that cover scenarios where
datasetItemId
is notNone
. This would ensure that the new functionality is properly tested. For example:expect_cli_post_request( httpx_mock, path="/results", body=dict( # ... other parameters ... datasetItemId="some-dataset-item-id", ), json=dict(id="mock-result-id-2"), ) # Then add a test case that uses a non-None datasetItemId
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (4)
tests/e2e/test_e2e.py (4)
508-508
: LGTM. Consider updating documentation.The addition of the
datasetItemId
parameter is a good enhancement, allowing for potential integration with dataset functionality.Consider updating the function's documentation to explain the purpose and usage of this new parameter.
717-725
: LGTM. Consider adding a negative test case.The test function comprehensively checks the properties of the retrieved dataset. It verifies the revision ID, name, schema version, number of items, and properties of the first item.
Consider adding a negative test case to verify the behavior when trying to retrieve a non-existent dataset. This would enhance the robustness of your test suite.
727-733
: LGTM. Consider adding an assertion for non-empty splits.The test function effectively verifies the retrieval of a dataset with a specific split. It correctly checks that no items are returned for the "test-split-2".
Consider adding another test case or assertion to verify that when using a split that does contain items (e.g., "test-split" from the previous test), the items are correctly returned. This would provide more comprehensive coverage of the split functionality.
745-750
: LGTM. Consider adding a test case with non-empty results.This test function effectively verifies the retrieval of a dataset using both a specific revision ID and split. It correctly checks that no items are returned for this combination.
Consider adding another test case that uses a combination of revision ID and split that does return items. This would provide more comprehensive coverage of the functionality when both parameters are used together.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- autoblocks/_impl/api/client.py (6 hunks)
- tests/e2e/test_e2e.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- autoblocks/_impl/api/client.py
🔇 Additional comments (1)
tests/e2e/test_e2e.py (1)
735-743
: LGTM. Comprehensive test for dataset retrieval by revision ID.This test function effectively verifies the retrieval of a dataset using a specific revision ID. It checks all relevant properties including the revision ID, name, schema version, number of items, and the properties of the first item.
Summary by CodeRabbit
New Features
Bug Fixes
Documentation