-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| @desc: | ||
| """ | ||
| import uuid_utils.compat as uuid | ||
| from django.db.models import QuerySet | ||
|
|
||
| from django.utils.translation import gettext_lazy as _ | ||
| from drf_spectacular.utils import extend_schema | ||
|
|
@@ -15,17 +16,25 @@ | |
|
|
||
| from application.api.application_chat import ApplicationChatQueryAPI, ApplicationChatQueryPageAPI, \ | ||
| ApplicationChatExportAPI | ||
| from application.models import ChatUserType | ||
| from application.models import ChatUserType, Application | ||
| from application.serializers.application_chat import ApplicationChatQuerySerializers | ||
| from chat.api.chat_api import ChatAPI, PromptGenerateAPI | ||
| from chat.api.chat_authentication_api import ChatOpenAPI | ||
| from chat.serializers.chat import OpenChatSerializers, ChatSerializers, DebugChatSerializers, PromptGenerateSerializer | ||
| from common.auth import TokenAuth | ||
| from common.auth.authentication import has_permissions | ||
| from common.constants.permission_constants import PermissionConstants, RoleConstants, ViewPermission, CompareConstants | ||
| from common.log.log import log | ||
| from common.result import result | ||
| from common.utils.common import query_params_to_single_dict | ||
|
|
||
| def get_application_operation_object(application_id): | ||
| application_model = QuerySet(model=Application).filter(id=application_id).first() | ||
| if application_model is not None: | ||
| return { | ||
| 'name': application_model.name | ||
| } | ||
| return {} | ||
|
|
||
| class ApplicationChat(APIView): | ||
| authentication_classes = [TokenAuth] | ||
|
|
@@ -146,6 +155,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 +167,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) | ||
| @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) | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,15 @@ def get_parameters(): | |
| description="模型id", | ||
| type=OpenApiTypes.STR, | ||
| location='path', | ||
| required=True,) | ||
| required=True, | ||
| ), | ||
| OpenApiParameter( | ||
| name="application_id", | ||
| description="应用id", | ||
| type=OpenApiTypes.STR, | ||
| location='path', | ||
| required=True, | ||
| ), | ||
| ] | ||
|
|
||
| @staticmethod | ||
|
Contributor
Author
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. The code you provided is a part of an API documentation generated by Swagger/OpenAPI. It includes several minor improvements and corrections:
If you have specific areas of concern or need further assistance, feel free to ask! |
||
|
|
||
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 (
/) inpathdefinition for the/model/<str:model_id>/prompt_generateURL 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.