Skip to content

Commit

Permalink
AAP-30619: migrate PlaybookGeneration to the new Schema1 object (#1485)
Browse files Browse the repository at this point in the history
Use an object defined in ansible_ai_connect/ai/api/telemetry/schema1.py to prepare the Schema1 payload.
  • Loading branch information
goneri authored Jan 9, 2025
1 parent d7c5ab0 commit 617c179
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 186 deletions.
11 changes: 11 additions & 0 deletions ansible_ai_connect/ai/api/telemetry/schema1.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,17 @@ class ExplainPlaybookEvent(Schema1Event):
explanationId: str = field(validator=validators.instance_of(str), converter=str, default="")


@define
class GenerationPlaybookEvent(Schema1Event):
event_name: str = "codegenPlaybook"
playbook_length: int = field(validator=validators.instance_of(int), default=0)
generationId: str = field(validator=validators.instance_of(str), converter=str, default="")
wizardId: str = field(validator=validators.instance_of(str), converter=str, default="")
create_outline: bool = field(
validator=validators.instance_of(bool), converter=bool, default=False
)


@define
class ChatBotResponseDocsReferences:
docs_url: str = field(validator=validators.instance_of(str), converter=str, default="")
Expand Down
16 changes: 15 additions & 1 deletion ansible_ai_connect/ai/api/telemetry/test_schema1.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
from ansible_ai_connect.test_utils import WisdomServiceAPITestCaseBaseOIDC
from ansible_ai_connect.users.models import Plan

from .schema1 import ExplainPlaybookEvent, OneClickTrialStartedEvent, Schema1Event
from .schema1 import (
ExplainPlaybookEvent,
GenerationPlaybookEvent,
OneClickTrialStartedEvent,
Schema1Event,
)


@override_settings(AUTHZ_BACKEND_TYPE="dummy")
Expand Down Expand Up @@ -107,3 +112,12 @@ class TestExplainPlaybookEvent(WisdomServiceAPITestCaseBaseOIDC):
def test_base(self):
event1 = ExplainPlaybookEvent()
self.assertEqual(event1.event_name, "explainPlaybook")


@override_settings(AUTHZ_BACKEND_TYPE="dummy")
@override_settings(WCA_SECRET_DUMMY_SECRETS="1981:valid")
class TestGenerationPlaybookEvent(WisdomServiceAPITestCaseBaseOIDC):
def test_base(self):
event1 = GenerationPlaybookEvent()
self.assertEqual(event1.event_name, "codegenPlaybook")
self.assertFalse(event1.create_outline)
22 changes: 11 additions & 11 deletions ansible_ai_connect/ai/api/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3604,7 +3604,7 @@ def test_bad_wca_request(self):
model_client,
HTTPStatus.NO_CONTENT,
WcaBadRequestException,
"bad request for playbook generation",
"WCA returned a bad request response",
)

def test_missing_api_key(self):
Expand All @@ -3616,7 +3616,7 @@ def test_missing_api_key(self):
model_client,
HTTPStatus.FORBIDDEN,
WcaKeyNotFoundException,
"A WCA Api Key was expected but not found for playbook generation",
"A WCA Api Key was expected but not found",
)

def test_missing_model_id(self):
Expand All @@ -3628,7 +3628,7 @@ def test_missing_model_id(self):
model_client,
HTTPStatus.FORBIDDEN,
WcaModelIdNotFoundException,
"A WCA Model ID was expected but not found for playbook generation",
"A WCA Model ID was expected but not found",
)

def test_missing_default_model_id(self):
Expand All @@ -3640,7 +3640,7 @@ def test_missing_default_model_id(self):
model_client,
HTTPStatus.FORBIDDEN,
WcaNoDefaultModelIdException,
"A default WCA Model ID was expected but not found for playbook generation",
"No default WCA Model ID was found",
)

def test_request_id_correlation_failure(self):
Expand All @@ -3656,7 +3656,7 @@ def test_request_id_correlation_failure(self):
model_client,
HTTPStatus.INTERNAL_SERVER_ERROR,
WcaRequestIdCorrelationFailureException,
"WCA Request/Response GenerationId correlation failed",
"WCA Request/Response Request Id correlation failed",
)

def test_invalid_model_id(self):
Expand All @@ -3669,7 +3669,7 @@ def test_invalid_model_id(self):
model_client,
HTTPStatus.FORBIDDEN,
WcaInvalidModelIdException,
"WCA Model ID is invalid for playbook generation",
"WCA Model ID is invalid",
)

def test_empty_response(self):
Expand All @@ -3680,7 +3680,7 @@ def test_empty_response(self):
model_client,
HTTPStatus.NO_CONTENT,
WcaEmptyResponseException,
"WCA returned an empty response for playbook generation",
"WCA returned an empty response",
)

def test_cloudflare_rejection(self):
Expand All @@ -3689,7 +3689,7 @@ def test_cloudflare_rejection(self):
model_client,
HTTPStatus.BAD_REQUEST,
WcaCloudflareRejectionException,
"Cloudflare rejected the request for playbook generation",
"Cloudflare rejected the request",
)

def test_hap_filter(self):
Expand All @@ -3704,7 +3704,7 @@ def test_hap_filter(self):
model_client,
HTTPStatus.BAD_REQUEST,
WcaHAPFilterRejectionException,
"WCA Hate, Abuse, and Profanity filter rejected the request for playbook generation",
"WCA Hate, Abuse, and Profanity filter rejected the request",
)

def test_user_trial_expired(self):
Expand All @@ -3716,7 +3716,7 @@ def test_user_trial_expired(self):
model_client,
HTTPStatus.FORBIDDEN,
WcaUserTrialExpiredException,
"User trial expired, when requesting playbook generation",
"User trial expired",
)

def test_wca_instance_deleted(self):
Expand All @@ -3733,7 +3733,7 @@ def test_wca_instance_deleted(self):
model_client,
HTTPStatus.IM_A_TEAPOT,
WcaInstanceDeletedException,
"WCA Instance has been deleted when requesting playbook generation",
"The WCA instance associated with the Model ID has been deleted",
)

def test_wca_request_with_model_id_given(self):
Expand Down
Loading

0 comments on commit 617c179

Please sign in to comment.