-
Notifications
You must be signed in to change notification settings - Fork 2
feat: rpt client updated to 1.6 #174
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
Open
yamaceay
wants to merge
8
commits into
main
Choose a base branch
from
upgrade-rpt-clients
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+359
−50
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e075eae
rpt client updated to 1.6
yamaceay 143a9a3
prediction_payload tests updated
yamaceay c162a26
mock tests added + integration tests extended
yamaceay 5e60f6c
update to rpt 1.6 client for tests
yamaceay a75d563
fix: rename rpt model
yamaceay 5d68b51
Merge branch 'main' into upgrade-rpt-clients
yamaceay a096f14
update confidence interval + mock tests + happy path testing
yamaceay 35b9c6e
add missing sap models to the list
yamaceay 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
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
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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import unittest | ||
|
|
||
| from integration_tests.constants import SAP_RPT_1_SMALL_TEST_MODEL | ||
| from integration_tests.constants import SAP_RPT_1_6_SMALL_TEST_MODEL | ||
|
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. Let's not only test against 1.6. |
||
| from integration_tests.setup_aicore import TestCaseStandardSetupMixin | ||
| from gen_ai_hub.proxy.native.sap.client import RPTClient | ||
| from gen_ai_hub.proxy.native.sap.models import RPTRequest, RPTResponse, PredictionConfig, TargetColumn | ||
|
|
@@ -138,15 +138,15 @@ def setUp(self) -> None: | |
| self.client = RPTClient(proxy_client=self.proxy_client) | ||
|
|
||
| def test_client_find_url_by_model_name(self): | ||
| url = self.client._get_url(model_name=SAP_RPT_1_SMALL_TEST_MODEL) | ||
| url = self.client._get_url(model_name=SAP_RPT_1_6_SMALL_TEST_MODEL) | ||
| self.assertIsNotNone(url) | ||
|
|
||
| def test_client_find_url_by_model_name_and_version(self): | ||
| url = self.client._get_url(model_name=SAP_RPT_1_SMALL_TEST_MODEL, model_version="latest") | ||
| url = self.client._get_url(model_name=SAP_RPT_1_6_SMALL_TEST_MODEL, model_version="latest") | ||
| self.assertIsNotNone(url) | ||
|
|
||
| def test_client_find_url_by_config_name(self): | ||
| url = self.client._get_url(config_name="sap-rpt-1-small-latest") | ||
| url = self.client._get_url(config_name="sap-rpt-1.6-latest") | ||
| self.assertIsNotNone(url) | ||
|
|
||
| def test_client_find_url_with_invalid_model_name(self): | ||
|
|
@@ -155,7 +155,7 @@ def test_client_find_url_with_invalid_model_name(self): | |
|
|
||
| def test_predict_by_row(self): | ||
| body = RPTRequest(**request_by_row_dict) | ||
| response = self.client.predict(body=body, model_name=SAP_RPT_1_SMALL_TEST_MODEL) | ||
| response = self.client.predict(body=body, model_name=SAP_RPT_1_6_SMALL_TEST_MODEL) | ||
| self.assertIsInstance(response, RPTResponse) | ||
| self.assertEqual(response.status.code, 0) | ||
| self.assertEqual(response.predictions[0]["ID"], "35") | ||
|
|
@@ -165,7 +165,7 @@ def test_predict_by_row(self): | |
|
|
||
| def test_predict_by_columns(self): | ||
| body = RPTRequest(**request_by_columns_dict) | ||
| response = self.client.predict(body=body, model_name=SAP_RPT_1_SMALL_TEST_MODEL) | ||
| response = self.client.predict(body=body, model_name=SAP_RPT_1_6_SMALL_TEST_MODEL) | ||
| self.assertIsInstance(response, RPTResponse) | ||
| self.assertEqual(response.status.code, 0) | ||
| self.assertEqual(response.metadata.num_columns, 5) | ||
|
|
@@ -175,7 +175,7 @@ def test_predict_by_columns(self): | |
|
|
||
| def test_predict_with_api_url(self): | ||
| body = RPTRequest(**request_by_columns_dict) | ||
| deployment_url = self.client._get_url(model_name=SAP_RPT_1_SMALL_TEST_MODEL) | ||
| deployment_url = self.client._get_url(model_name=SAP_RPT_1_6_SMALL_TEST_MODEL) | ||
| response = self.client.predict(body=body, deployment_url=deployment_url) | ||
| self.assertIsInstance(response, RPTResponse) | ||
| self.assertEqual(response.status.code, 0) | ||
|
|
@@ -187,11 +187,11 @@ def test_regression_prediction(self): | |
| body = RPTRequest( | ||
| prediction_config=PredictionConfig( | ||
| target_columns=[ | ||
| TargetColumn(name="DISCOUNT_RATE", task_type="regression") | ||
| TargetColumn(name="DISCOUNT_RATE", task_type="regression", prediction_placeholder="[PREDICT]") | ||
| ]), | ||
| rows=rows_regression | ||
| ) | ||
| response = self.client.predict(body=body, model_name=SAP_RPT_1_SMALL_TEST_MODEL) | ||
| response = self.client.predict(body=body, model_name=SAP_RPT_1_6_SMALL_TEST_MODEL) | ||
| self.assertIsInstance(response, RPTResponse) | ||
| self.assertEqual(response.status.code, 0) | ||
| self.assertEqual(response.metadata.num_predictions, 2) | ||
|
|
@@ -201,13 +201,81 @@ def test_timeout_error(self): | |
| body = RPTRequest( | ||
| prediction_config=PredictionConfig( | ||
| target_columns=[ | ||
| TargetColumn(name="DISCOUNT_RATE", task_type="regression") | ||
| TargetColumn(name="DISCOUNT_RATE", task_type="regression", prediction_placeholder="[PREDICT]") | ||
| ]), | ||
| rows=rows_regression | ||
| ) | ||
|
|
||
| with self.assertRaises(Exception): | ||
| self.client.predict(body=body, model_name=SAP_RPT_1_SMALL_TEST_MODEL, timeout=0.001) | ||
| self.client.predict(body=body, model_name=SAP_RPT_1_6_SMALL_TEST_MODEL, timeout=0.001) | ||
|
|
||
|
|
||
|
|
||
| def test_predict_classification_with_top_k(self): | ||
| body = RPTRequest(**{ | ||
| **request_by_columns_dict, | ||
| 'prediction_config': { | ||
| 'target_columns': [ | ||
| { | ||
| 'name': 'COSTCENTER', | ||
| 'prediction_placeholder': '[PREDICT]', | ||
| 'task_type': 'classification', | ||
| 'top_k': 2 | ||
| } | ||
| ] | ||
| } | ||
| }) | ||
| response = self.client.predict(body=body, model_name=SAP_RPT_1_6_SMALL_TEST_MODEL) | ||
| self.assertIsInstance(response, RPTResponse) | ||
| self.assertEqual(response.status.code, 0) | ||
| costcenter_predictions = response.predictions[0]['COSTCENTER'] | ||
| self.assertGreaterEqual(len(costcenter_predictions), 1) | ||
|
|
||
| def test_predict_response_includes_context_mode(self): | ||
| body = RPTRequest(**request_by_columns_dict) | ||
| response = self.client.predict(body=body, model_name=SAP_RPT_1_6_SMALL_TEST_MODEL) | ||
| self.assertIsInstance(response, RPTResponse) | ||
| self.assertIn(response.metadata.context_mode, ['default', 'deep']) | ||
|
|
||
| def test_regression_prediction_includes_confidence_interval(self): | ||
| body = RPTRequest( | ||
| prediction_config=PredictionConfig( | ||
| target_columns=[ | ||
| TargetColumn(name='DISCOUNT_RATE', task_type='regression', prediction_placeholder='[PREDICT]') | ||
| ]), | ||
| rows=rows_regression | ||
| ) | ||
| response = self.client.predict(body=body, model_name=SAP_RPT_1_6_SMALL_TEST_MODEL) | ||
| self.assertIsInstance(response, RPTResponse) | ||
| self.assertEqual(response.status.code, 0) | ||
| discount_predictions = response.predictions[0]['DISCOUNT_RATE'] | ||
| self.assertIsNotNone(discount_predictions[0].confidence_interval) | ||
| self.assertEqual(len(discount_predictions[0].confidence_interval), 2) | ||
| self.assertIsNone(discount_predictions[0].confidence) | ||
|
|
||
| def test_predict_with_explanations(self): | ||
| body = RPTRequest(**{ | ||
| **request_by_columns_dict, | ||
| 'prediction_config': { | ||
| 'target_columns': [ | ||
| { | ||
| 'name': 'COSTCENTER', | ||
| 'prediction_placeholder': '[PREDICT]', | ||
| 'task_type': 'classification' | ||
| } | ||
| ], | ||
| 'explanations': { | ||
| 'top_column_scores': 3, | ||
| 'top_relevant_context_rows': 2 | ||
| } | ||
| } | ||
| }) | ||
| response = self.client.predict(body=body, model_name=SAP_RPT_1_6_SMALL_TEST_MODEL) | ||
| self.assertIsInstance(response, RPTResponse) | ||
| self.assertEqual(response.status.code, 0) | ||
| self.assertIsNotNone(response.explanations) | ||
| self.assertIsNotNone(response.explanations.top_column_scores) | ||
| self.assertIsNotNone(response.explanations.top_relevant_context_rows) | ||
|
|
||
|
|
||
| class AsyncRPTClientTests(TestCaseStandardSetupMixin, unittest.IsolatedAsyncioTestCase): | ||
|
|
@@ -217,7 +285,7 @@ def setUp(self) -> None: | |
|
|
||
| async def test_apredict_by_row(self): | ||
| body = RPTRequest(**request_by_row_dict) | ||
| response = await self.client.apredict(body=body, model_name=SAP_RPT_1_SMALL_TEST_MODEL) | ||
| response = await self.client.apredict(body=body, model_name=SAP_RPT_1_6_SMALL_TEST_MODEL) | ||
| self.assertIsInstance(response, RPTResponse) | ||
| self.assertEqual(response.status.code, 0) | ||
| self.assertEqual(response.predictions[0]["ID"], "35") | ||
|
|
@@ -227,10 +295,33 @@ async def test_apredict_by_row(self): | |
|
|
||
| async def test_apredict_by_columns(self): | ||
| body = RPTRequest(**request_by_columns_dict) | ||
| response = await self.client.apredict(body=body, model_name=SAP_RPT_1_SMALL_TEST_MODEL) | ||
| response = await self.client.apredict(body=body, model_name=SAP_RPT_1_6_SMALL_TEST_MODEL) | ||
| self.assertIsInstance(response, RPTResponse) | ||
| self.assertEqual(response.status.code, 0) | ||
| self.assertEqual(response.metadata.num_columns, 5) | ||
| self.assertEqual(response.metadata.num_predictions, 1) | ||
| self.assertIn("COSTCENTER", response.predictions[0].model_dump()) | ||
| self.assertNotIn("ID", response.predictions[0].model_dump()) | ||
|
|
||
| async def test_apredict_response_includes_context_mode(self): | ||
| body = RPTRequest(**request_by_columns_dict) | ||
| response = await self.client.apredict(body=body, model_name=SAP_RPT_1_6_SMALL_TEST_MODEL) | ||
| self.assertIsInstance(response, RPTResponse) | ||
| self.assertIn(response.metadata.context_mode, ['default', 'deep']) | ||
|
|
||
| async def test_apredict_regression_includes_confidence_interval(self): | ||
| body = RPTRequest( | ||
| prediction_config=PredictionConfig( | ||
| target_columns=[ | ||
| TargetColumn(name='DISCOUNT_RATE', task_type='regression', prediction_placeholder='[PREDICT]') | ||
| ]), | ||
| rows=rows_regression | ||
| ) | ||
| response = await self.client.apredict(body=body, model_name=SAP_RPT_1_6_SMALL_TEST_MODEL) | ||
| self.assertIsInstance(response, RPTResponse) | ||
| self.assertEqual(response.status.code, 0) | ||
| discount_predictions = response.predictions[0]['DISCOUNT_RATE'] | ||
| self.assertIsNotNone(discount_predictions[0].confidence_interval) | ||
| self.assertEqual(len(discount_predictions[0].confidence_interval), 2) | ||
| self.assertIsNone(discount_predictions[0].confidence) | ||
|
|
||
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
Oops, something went wrong.
Oops, something went wrong.
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.
This is a mandatory field, not optional.
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.
According to this spec, yes, it is required. But still, it needs to be a nullable number | string union. Is it wrong to set optional here?