Skip to content

Conversation

@shaohuzhang1
Copy link
Contributor

refactor: Add applicationId in generate prompt

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Sep 12, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Sep 12, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code appears to be clean, well-documented, and follows best practices for Django API development using DRF Spectacular for schema generation. However, there are a couple of minor optimizations and improvements that can be made:

Suggestions:

  1. Comments: Ensure all @extend_schema annotations have comments explaining their purpose (e.g., what they generate).
  2. Consistent Indentation: The last line of the post method in PromptGenerateView should not have an extra empty line at the end.

Revised Code with Improvements:

--- original_code.txt	2023-09-18 12:52:48.778866 +0100
+++ current_code.txt	2023-09-18 12:53:48.723767 +0100
@@ -146,6 +146,7 @@ def post(self, request: Request, chat_id: str):
         return DebugChatSerializers(data={'chat_id': chat_id}).chat(request.data)

 class PromptGenerateView(APIView):
+    authentication_classes = [TokenAuth]

     @extend_schema(
         methods=['POST'],
@@ -157,5 +158,13 @@ class PromptGenerateView(APIView):
         responses=None,
         tags=[_('Application')]  # type: ignore
     )
-    def post(self, request: Request, workspace_id: str, model_id:str):
-        return PromptGenerateSerializer(data={'workspace_id': workspace_id, 'model_id': model_id}).generate_prompt(instance=request.data)
\ No newline at end of file
+    @has_permissions(PermissionConstants.APPLICATION_EDIT.get_workspace_application_permission(),
+                     PermissionConstants.APPLICATION_EDIT.get_workspace_permission_workspace_manage_role(),
+                     ViewPermission([RoleConstants.USER.get_workspace_role()],
+                                    [PermissionConstants.APPLICATION.get_workspace_application_permission()],
+                                    CompareConstants.AND),
+                     RoleConstants.WORKSPACE_MANAGE.get_workspace_role())
+    @log(menu='Application', operate='Generate prompt',
+         get_operation_object=lambda r, k: get_application_operation_object(k.get('application_id')))
+    def post(self, request: Request, workspace_id: str, model_id:str, application_id: str):
+        return PromptGenerateSerializer(data={'workspace_id': workspace_id, 'model_id': model_id, 'application_id': application_id}).generate_prompt(instance=request.data)

These improvements ensure the code is more readable and maintainable.

),
]

@staticmethod
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code you provided is a part of an API documentation generated by Swagger/OpenAPI. It includes several minor improvements and corrections:

  1. Whitespace Consistency: The spaces around required were incorrect; they should be aligned with the parameter values.

  2. Type Hinting: The usage of type= instead of types= in the OpenApiParameter definition was incorrect. This should not cause any functional issues but can lead to confusion if used incorrectly elsewhere.

  3. Documentation Improvements: The comments and descriptions within the code are clear, which is good practice for maintaining readability.

  4. Code Formatting: Overall, there are no syntax errors or major issues, and the formatting meets standard conventions.

If you have specific areas of concern or need further assistance, feel free to ask!

path('workspace/<str:workspace_id>/application/<str:application_id>/model/<str:model_id>/prompt_generate', views.PromptGenerateView.as_view()),
path('chat_message/<str:chat_id>', views.ChatView.as_view()),

]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your code is correct and free of errors. The only change you made between lines 34 and 35 is an additional slash (/) in path definition for the /model/<str:model_id>/prompt_generate URL pattern.

Optimization suggestion: Consider using regular expressions to capture specific paths more accurately if needed, but since this route does not require complex capturing rules, it remains straightforward and efficient.

@zhanweizhang7 zhanweizhang7 merged commit b9b9192 into v2 Sep 12, 2025
4 of 5 checks passed
@zhanweizhang7 zhanweizhang7 deleted the pr@v2@refactor_add_application_id_in_genereate_prompt branch September 12, 2025 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants