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

chore: remove feedback feature #17

Merged
merged 1 commit into from
Jan 12, 2024
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
58 changes: 0 additions & 58 deletions src/ansys/simai/core/api/prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,9 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import io
import logging
from pathlib import Path
from typing import BinaryIO, Callable, Optional, Union

from requests_toolbelt import MultipartEncoder, MultipartEncoderMonitor

from ansys.simai.core.api.mixin import ApiClientMixin
from ansys.simai.core.utils.files import file_path_to_obj_file

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -72,55 +66,3 @@ def run_prediction(self, geometry_id: str, **kwargs): # noqa: D417
are considered equal. The default is ``10**-6``.
"""
return self._post(f"geometries/{geometry_id}/predictions", json=kwargs)

def send_prediction_feedback(
self,
prediction_id: str,
rating: int,
comment: str,
solution: Optional[Union[BinaryIO, str, Path]] = None,
monitor_callback: Optional[Callable[[int], None]] = None,
):
"""Send feedback on your prediction so improvements can be made.

Args:
prediction_id: ID of the target prediction.
rating: Rating from 0 to 4.
comment: Additional comment.
solution: Client solution to the prediction.
monitor_callback: Function or method to pass the
:py:class:`~requests_toolbelt.multipart.encoder.MultipartEncoderMonitor` to.
"""
if solution is None:
with_solution = False
close_file = False
else:
if isinstance(solution, (Path, str)):
solution_file = file_path_to_obj_file(solution, "rb")
close_file = True
elif isinstance(solution, (io.RawIOBase, io.BufferedIOBase)):
solution_file = solution
close_file = False
else:
raise ValueError(
"Could not handle the provided solution." " Use a path or binary file."
)
with_solution = True
upload_form = {"rating": str(rating), "comment": comment}
if with_solution:
upload_form["solution"] = (
"solution",
solution_file,
"application/octet-stream",
)
multipart = MultipartEncoder(upload_form)
if monitor_callback is not None:
multipart = MultipartEncoderMonitor(multipart, monitor_callback)

self._post(
f"predictions/{prediction_id}/feedback",
data=multipart,
headers={"Content-Type": multipart.content_type},
)
if close_file is True:
solution_file.close()
33 changes: 0 additions & 33 deletions src/ansys/simai/core/data/predictions.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,6 @@ def delete(self) -> None:
self._client._api.delete_prediction(self.id)
self._unregister()

def feedback(self, **kwargs): # noqa: D417
"""Provide feedback on a prediction so improvements might be made.

This method enables you to give a rating (from 0 to 4) and a comment on a
prediction.
Moreover, you can upload your computed solution.
Your feedback is used to try to make predictions more accurate.

Keyword Args:
rating (int): Rating from 0 to 4.
comment (str): Additional comment.
solution (Optional[File]): Your solution to the prediction.
"""
self._client._api.send_prediction_feedback(self.id, **kwargs)

def _wait_all(self):
"""Wait until both this prediction and any postprocessing launched on it
have finished processing.
Expand Down Expand Up @@ -277,21 +262,3 @@ def run( # noqa: D417
for location, warning_message in prediction.fields.get("warnings", {}).items():
logger.warning(f"{location}: {warning_message}")
return prediction

def feedback(self, prediction: Identifiable[Prediction], **kwargs) -> None: # noqa: D417
"""Provide feedback on a prediction so improvements might be made.

This method enables you to give a rating (from 0 to 4) and a comment on a
prediction.
Moreover, you can upload your computed solution.
Your feedback is used to try to make predictions more accurate.

Args:
prediction: ID or :class:`model <Prediction>` of the prediction.

Keyword Args:
rating (int): Rating from 0 to 4.
comment (str): Additional comment.
solution (typing.Optional[File]): Your solution to the prediction.
"""
self._client._api.send_prediction_feedback(get_id_from_identifiable(prediction), **kwargs)
Loading