Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions apps/application/views/application_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,8 +644,6 @@ class SpeechToText(APIView):
dynamic_tag=keywords.get(
'application_id'))],
compare=CompareConstants.AND))
@log(menu='Application', operate="speech to text",
get_operation_object=lambda r, k: get_application_operation_object(k.get('application_id')))
def post(self, request: Request, application_id: str):
return result.success(
ApplicationSerializer.Operate(data={'application_id': application_id, 'user_id': request.user.id})
Expand All @@ -668,8 +666,6 @@ class TextToSpeech(APIView):
dynamic_tag=keywords.get(
'application_id'))],
compare=CompareConstants.AND))
@log(menu='Application', operate="text to speech",
get_operation_object=lambda r, k: get_application_operation_object(k.get('application_id')))
def post(self, request: Request, application_id: str):
byte_data = ApplicationSerializer.Operate(
data={'application_id': application_id, 'user_id': request.user.id}).text_to_speech(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Here are some concerns and suggestions for review:

  1. Redundancy: The same @log decorator is applied multiple times with similar parameters on both classes (SpeechToText and TextToSpeech). This redundancy can be removed, which makes the code cleaner.

  2. Functionality Duplication: Both functions in the post methods seem to have very similar logic. Extracting this common functionality into a separate method would make things more maintainable and reduce duplication.

  3. Code Style: Ensure consistent spacing, alignment, and use of comments where necessary. Proper organization of the class hierarchy and function definitions will also improve readability.

  4. Security: If there's sensitive information about the application ID being logged, consider implementing additional security measures such as anonymization or whitelisting specific IDs.

Here’s an optimized version of the code based on these suggestions:

from django.utils.decorators import method_decorator
from logging_decorators import log

class SpeechToText(APIView):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.dynamic_tag_key = "application_id"

    @method_decorator(log(menu='Application', operate="speech to text"))
    def post(self, request: Request, application_id: str):
        return apply_operation(request.user.id)

def text_to_speech(application_id, user_id):
    # Placeholder for actual implementation
    pass

def apply_operation(user_id):
    keywords = {}
    dynamic_tag = keywords.pop(self.dynamic_tag_key) if self.dynamic_tag_key in keywords else None

    operation_object = get_application_operation_object(dynamic_tag=dynamic_tag)
    return result.success(ApplicationSerializer.Operate(data={'application_id': application_id, 'user_id': user_id}))

# Replace get_application_operation_object with appropriate logic
def get_application_operation_object(dynamic_tag=None):
    # Placeholder for actual implementation
    pass

Key Changes:

  • Removed redundant @log decorators.
  • Introduced a helper method apply_operation that encapsulates duplicate logic.
  • Created two separate functions: text_to_speech for handling text-to-speech operations, and get_application_operation_object.
  • Used @method_decorator to apply the logging middleware globally.

These changes should lead to cleaner, more organized, and potentially less error-prone code.

Expand Down
2 changes: 2 additions & 0 deletions apps/application/views/chat_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class Export(APIView):
[lambda r, keywords: Permission(group=Group.APPLICATION, operate=Operate.USE,
dynamic_tag=keywords.get('application_id'))])
)
@log(menu='Conversation Log', operate="Export conversation",
get_operation_object=lambda r, k: get_application_operation_object(k.get('application_id')))
def post(self, request: Request, application_id: str):
return ChatSerializers.Query(
data={**query_params_to_single_dict(request.query_params), 'application_id': application_id,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Your code looks mostly well-structured, but there's one change needed to fix a syntax error:

@@ -62,7 +64 @@ class Export(APIView):

To correct the syntax error and ensure proper function definitions within your APIView, update line 62 from -62,7 to +62. This should resolve the issue with the indentation. Here is the corrected line:

@post(...)
def post(self, request, application_id): # Note the removal of commas here due to incorrect indenting
    ... rest of the code ...

Additionally, consider checking if get_log_menu_name is defined properly as it appears in "Export conversation" within the annotation.

If you need further optimization suggestions or additional improvements, please let me know! Otherwise, this should address any immediate issues found in your code.

Expand Down
17 changes: 13 additions & 4 deletions apps/locales/en_US/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ msgstr ""

#: apps/xpack/serializers/channel/chat_manage.py:298
msgid "Thinking, please wait a moment!"
msgstr ""
msgstr "Thinking, please wait a moment......"

#: apps/xpack/serializers/channel/ding_talk.py:19
#: apps/xpack/serializers/channel/wechat.py:89
Expand Down Expand Up @@ -1210,7 +1210,7 @@ msgstr "Details"
#: apps/xpack/views/application_setting_views.py:23
#| msgid "Modification time"
msgid "Modify Application Settings"
msgstr ""
msgstr "Modify Application Display Settings"

#: apps/xpack/views/application_setting_views.py:24
#: apps/xpack/views/application_setting_views.py:40
Expand Down Expand Up @@ -4478,7 +4478,7 @@ msgstr ""
#: community/apps/dataset/views/dataset.py:184
#: community/apps/dataset/views/dataset.py:185
msgid "Export knowledge base containing images"
msgstr ""
msgstr "Export ZIP Knowledge Base"

#: community/apps/dataset/views/dataset.py:199
msgid "Delete knowledge base"
Expand Down Expand Up @@ -7448,7 +7448,7 @@ msgid "Operate Time"
msgstr "Operate time"

msgid "System Settings/API Key"
msgstr "System Settings/API Key"
msgstr "System API Key"

msgid "Appearance Settings"
msgstr "Appearance Settings"
Expand All @@ -7463,4 +7463,13 @@ msgid "Paragraph"
msgstr ""

msgid "Batch generate related"
msgstr "Paragraph generate related problems"

msgid "Application access"
msgstr ""

msgid "Add internal function"
msgstr ""

msgid "Batch generate related documents"
msgstr "Batch generate related problems"
23 changes: 16 additions & 7 deletions apps/locales/zh_CN/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ msgstr "AI 回复: "

#: apps/xpack/serializers/channel/chat_manage.py:298
msgid "Thinking, please wait a moment!"
msgstr "正在思考中,请稍后"
msgstr "正在思考中,请稍后......"

#: apps/xpack/serializers/channel/ding_talk.py:19
#: apps/xpack/serializers/channel/wechat.py:89
Expand Down Expand Up @@ -1229,7 +1229,7 @@ msgstr "详情"
#: apps/xpack/views/application_setting_views.py:23
#| msgid "Pro/Modify Application Settings"
msgid "Modify Application Settings"
msgstr "修改应用设置"
msgstr "修改应用显示设置"

#: apps/xpack/views/application_setting_views.py:24
#: apps/xpack/views/application_setting_views.py:40
Expand Down Expand Up @@ -4515,7 +4515,7 @@ msgstr "导出知识库"
#: community/apps/dataset/views/dataset.py:184
#: community/apps/dataset/views/dataset.py:185
msgid "Export knowledge base containing images"
msgstr "导出包含图片的知识库"
msgstr "导出ZIP知识库"

#: community/apps/dataset/views/dataset.py:199
msgid "Delete knowledge base"
Expand Down Expand Up @@ -4606,12 +4606,12 @@ msgstr "批量取消任务"
#: community/apps/dataset/views/document.py:279
#: community/apps/dataset/views/document.py:280
msgid "Refresh document vector library"
msgstr "刷新文档向量库"
msgstr "文档向量化"

#: community/apps/dataset/views/document.py:300
#: community/apps/dataset/views/document.py:301
msgid "Batch refresh document vector library"
msgstr "批量刷新文档向量库"
msgstr "批量文档向量化"

#: community/apps/dataset/views/document.py:319
#: community/apps/dataset/views/document.py:320
Expand Down Expand Up @@ -7611,7 +7611,7 @@ msgid "Operate Time"
msgstr "操作时间"

msgid "System Settings/API Key"
msgstr "系统设置/API Key"
msgstr "系统 API Key"

msgid "Appearance Settings"
msgstr "外观设置"
Expand All @@ -7626,4 +7626,13 @@ msgid "Paragraph"
msgstr "段落"

msgid "Batch generate related"
msgstr "批量生成相关问题"
msgstr "分段生成问题"

msgid "Application access"
msgstr "应用接入"

msgid "Add internal function"
msgstr "添加内部函数"

msgid "Batch generate related documents"
msgstr "批量生成问题"
23 changes: 16 additions & 7 deletions apps/locales/zh_Hant/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ msgstr "AI 回覆: "

#: apps/xpack/serializers/channel/chat_manage.py:298
msgid "Thinking, please wait a moment!"
msgstr "正在思考,請稍等"
msgstr "正在思考中,請稍等......"

#: apps/xpack/serializers/channel/ding_talk.py:19
#: apps/xpack/serializers/channel/wechat.py:89
Expand Down Expand Up @@ -1231,7 +1231,7 @@ msgstr "詳情"
#: apps/xpack/views/application_setting_views.py:23
#| msgid "Pro/Modify Application Settings"
msgid "Modify Application Settings"
msgstr "修改應用設置"
msgstr "修改應用显示設置"

#: apps/xpack/views/application_setting_views.py:24
#: apps/xpack/views/application_setting_views.py:40
Expand Down Expand Up @@ -4524,7 +4524,7 @@ msgstr "導出知識庫"
#: community/apps/dataset/views/dataset.py:184
#: community/apps/dataset/views/dataset.py:185
msgid "Export knowledge base containing images"
msgstr "導出包含圖片的知識庫"
msgstr "導出ZIP知識庫"

#: community/apps/dataset/views/dataset.py:199
msgid "Delete knowledge base"
Expand Down Expand Up @@ -4615,12 +4615,12 @@ msgstr "批量取消任務"
#: community/apps/dataset/views/document.py:279
#: community/apps/dataset/views/document.py:280
msgid "Refresh document vector library"
msgstr "刷新文檔向量庫"
msgstr "文檔向量化"

#: community/apps/dataset/views/document.py:300
#: community/apps/dataset/views/document.py:301
msgid "Batch refresh document vector library"
msgstr "批量刷新文檔向量庫"
msgstr "批量文檔向量化"

#: community/apps/dataset/views/document.py:319
#: community/apps/dataset/views/document.py:320
Expand Down Expand Up @@ -7621,7 +7621,7 @@ msgid "Operate Time"
msgstr "操作時間"

msgid "System Settings/API Key"
msgstr "系統設置/API Key"
msgstr "系統 API Key"

msgid "Appearance Settings"
msgstr "外觀設置"
Expand All @@ -7636,4 +7636,13 @@ msgid "Paragraph"
msgstr "段落"

msgid "Batch generate related"
msgstr "批量生成相關问题"
msgstr "分段生成问题"

msgid "Application access"
msgstr "應用接入"

msgid "Add internal function"
msgstr "添加內部函數"

msgid "Batch generate related documents"
msgstr "批量生成问题"
11 changes: 10 additions & 1 deletion ui/src/views/operate-log/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,16 @@
</div>
</template>
</el-table-column>
<el-table-column prop="operate" :label="$t('views.operateLog.table.operate.detail')" />
<el-table-column prop="operate" :label="$t('views.operateLog.table.operate.detail')">
<template #default="{ row }">
{{
row.operate +
(row.operation_object && row.operation_object.name
? `【${row.operation_object.name}】`
: '')
}}
</template>
</el-table-column>
<el-table-column
width="120"
prop="user.username"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The modified line seems to correct a minor issue in how the operation details are displayed. The template expression now includes the operation object's name if it exists, separated by "【」" for clarity.

Optimization Suggestions:

  1. Improve Readability: Consider wrapping long expressions across multiple lines for better readability.
  2. Type Checking: Ensure that row.operation_object?.name is not undefined before accessing it to avoid runtime errors.
  3. Avoid Redundancy: If row.operate and row.operation_object?.name always come together, you can simplify the logic.
  4. Internationalization (i18n): Ensure consistent use of $t for internationalized labels.

Here’s an improved version:

<template>
  <!-- ... -->
  <el-table-column
    prop="operate"
    :label="$t('views.operateLog.table.operate.detail')"
  >
    <template #default="{ row }">
      {{ row.operate }}
      {{
        row.operation_object && row.operation_object.name
          ? ` 【${row.operation_object.name}】`
          : ''
      }}
    </template>
  </el-table-column>
<!-- ... -->
</template>

<script setup lang="ts">
// No additional changes required unless further modifications are needed beyond this point
</script>

This should handle the operation object display correctly while making the code more readable and maintaining good practices.

Expand Down