-
Notifications
You must be signed in to change notification settings - Fork 2.6k
refactor: Add applicationId in generate prompt #4028
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
refactor: Add applicationId in generate prompt #4028
Conversation
|
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. DetailsInstructions 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. |
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
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.
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:
- Comments: Ensure all
@extend_schemaannotations have comments explaining their purpose (e.g., what they generate). - Consistent Indentation: The last line of the
postmethod inPromptGenerateViewshould 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 |
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.
The code you provided is a part of an API documentation generated by Swagger/OpenAPI. It includes several minor improvements and corrections:
-
Whitespace Consistency: The spaces around
requiredwere incorrect; they should be aligned with the parameter values. -
Type Hinting: The usage of
type=instead oftypes=in theOpenApiParameterdefinition was incorrect. This should not cause any functional issues but can lead to confusion if used incorrectly elsewhere. -
Documentation Improvements: The comments and descriptions within the code are clear, which is good practice for maintaining readability.
-
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()), | ||
|
|
||
| ] |
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.
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.
refactor: Add applicationId in generate prompt