Skip to content

Commit

Permalink
More test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mabashian committed Feb 11, 2025
1 parent 5ac8709 commit 99638da
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
15 changes: 5 additions & 10 deletions ansible_ai_connect/ai/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,22 +654,17 @@ class ExplanationRoleRequestSerializer(Metadata):
label="Files",
help_text="A list of role files to be explained.",
)
role_name = serializers.CharField(
roleName = serializers.CharField(
required=True,
label="Role name",
help_text="The name of the role.",
)
model_id = serializers.CharField(required=False, allow_blank=True, default="")
focus_on_file = serializers.CharField(required=False, allow_blank=True, default="")
model = serializers.CharField(required=False, allow_blank=True, default="")
focusOnFile = serializers.CharField(required=False, allow_blank=True, default="")

def validate(self, attrs):
attrs = super().validate(attrs)

if "model_id" in attrs and not attrs["model_id"].strip():
del attrs["model_id"]
if "focus_on_file" in attrs and not attrs["focus_on_file"].strip():
del attrs["focus_on_file"]
return attrs
data = super().validate(attrs)
return data


class ContentMatchRequestSerializer(Metadata):
Expand Down
13 changes: 11 additions & 2 deletions ansible_ai_connect/ai/api/tests/test_role_explanation_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,21 @@ class TestRoleExplanationView(
APIVersionTestCaseBase, WisdomAppsBackendMocking, WisdomServiceAPITestCaseBase
):
def test_ok(self):
payload = {}
payload = {
"files": [
{
"path": "dummy_path",
"content": "dummy_content",
"file_type": "dummy_file_type",
}
],
"roleName": "dummy_role",
}
self.client.force_authenticate(user=self.user)
r = self.client.post(self.api_version_reverse("explanations/role"), payload, format="json")
self.assertEqual(r.status_code, HTTPStatus.OK)
self.assertIsNotNone(r.data)
self.assertEqual(r.data, {})
self.assertEqual(r.data["format"], "markdown")

def test_unauthorized(self):
payload = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from ansible_ai_connect.ai.api.versions.v1.test_base import API_VERSION


class TestRoleGenerationViewVersion1(TestRoleExplanationView):
class TestRoleExplanationViewVersion1(TestRoleExplanationView):
api_version = API_VERSION

def test_explanation_role_version_url(self):
Expand Down
8 changes: 4 additions & 4 deletions ansible_ai_connect/ai/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,15 +861,16 @@ class ExplanationRole(AACSAPIView):
summary="Inline code suggestions",
)
def post(self, request) -> Response:
self.event.explanationId = self.validated_data["explanationId"]
llm: ModelPipelineRoleExplanation = apps.get_app_config("ai").get_model_pipeline(
ModelPipelineRoleExplanation
)
explanation = llm.invoke(
RoleExplanationParameters.init(
request=request,
content=self.validated_data["content"],
explanation_id=self.validated_data["explanationId"],
files=self.validated_data["files"],
role_name=self.validated_data["roleName"],
model_id=self.validated_data["model"],
focus_on_file=self.validated_data["focusOnFile"],
)
)

Expand All @@ -882,7 +883,6 @@ def post(self, request) -> Response:
answer = {
"content": anonymized_explanation,
"format": "markdown",
"explanationId": self.validated_data["explanationId"],
}

return Response(
Expand Down

0 comments on commit 99638da

Please sign in to comment.