-
Notifications
You must be signed in to change notification settings - Fork 6
Add delete_detector method to Groundlight SDK #370
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
Changes from all commits
b89949b
a6382e0
71095ec
d8af357
91822ee
24680c1
5199c2c
7a68913
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| from groundlight.internalapi import ApiException, InternalApiError, NotFoundError | ||
| from groundlight.optional_imports import * | ||
| from groundlight.status_codes import is_user_error | ||
| from groundlight_openapi_client.exceptions import NotFoundException | ||
| from ksuid import KsuidMs | ||
| from model import ( | ||
| BinaryClassificationResult, | ||
|
|
@@ -848,3 +849,42 @@ def test_multiclass_detector(gl: Groundlight): | |
| mc_iq = gl.submit_image_query(created_detector, "test/assets/dog.jpeg") | ||
| assert mc_iq.result.label is not None | ||
| assert mc_iq.result.label in class_names | ||
|
|
||
|
|
||
| def test_delete_detector(gl: Groundlight): | ||
| """ | ||
| Test deleting a detector by both ID and object, and verify proper error handling. | ||
| """ | ||
| # Create a detector to delete | ||
| name = f"Test delete detector {datetime.utcnow()}" | ||
| query = "Is there a dog to delete?" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this name is so sad
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bad claude
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was going to change it originally, but then I thought about the silly test strings I've used and figured I'd let Claude have its fun
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going to assume that Claude was being funny here, and not just confused. |
||
| pipeline_config = "never-review" | ||
| detector = gl.create_detector(name=name, query=query, pipeline_config=pipeline_config) | ||
|
|
||
| # Delete using detector object | ||
| gl.delete_detector(detector) | ||
|
|
||
| # Verify the detector is actually deleted | ||
| with pytest.raises(NotFoundError): | ||
| gl.get_detector(detector.id) | ||
|
|
||
| # Create another detector to test deletion by ID string and that an attached image query is deleted | ||
| name2 = f"Test delete detector 2 {datetime.utcnow()}" | ||
| detector2 = gl.create_detector(name=name2, query=query, pipeline_config=pipeline_config) | ||
| gl.submit_image_query(detector2, "test/assets/dog.jpeg") | ||
|
|
||
| # Delete using detector ID string | ||
| gl.delete_detector(detector2.id) | ||
|
|
||
| # Verify the second detector is also deleted | ||
| with pytest.raises(NotFoundError): | ||
| gl.get_detector(detector2.id) | ||
|
|
||
| # Verify the image query is also deleted | ||
| with pytest.raises(NotFoundException): | ||
| gl.get_image_query(detector2.id) | ||
|
|
||
| # Test deleting a non-existent detector raises NotFoundError | ||
| fake_detector_id = "det_fake123456789" | ||
| with pytest.raises(NotFoundError): | ||
| gl.delete_detector(fake_detector_id) # type: ignore | ||
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.
I have no idea if this line is correct. I assume you've already verified that it is?
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.
It is correct. It's a pretty strict pattern match from the create_detector method