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
3 changes: 2 additions & 1 deletion apps/common/event/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
@desc:
"""
from django.core.cache import cache
from django.db.models import QuerySet
from django.utils.translation import gettext as _

from .listener_manage import *

from ..constants.cache_version import Cache_Version
from ..db.sql_execute import update_execute
from ..utils.lock import RedisLock
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code looks mostly correct, but here are a few minor improvements and suggestions:

  1. Import Order: The imports should be organized consistently:

    from django.core.cache import cache
    from django.db.models import QuerySet
    from django.utils.translation import gettext as _
    from .listener_manage import *
    
  2. Whitespace Consistency:
    Ensure consistent indentation and spacing around parentheses:

    from django.utils.translation import gettext as _
    
    def some_function():
        do_something()
    
  3. Variable Naming Conventions: Use meaningful variable names if they represent specific values or objects.

  4. Comments:
    Add comments explaining purpose of Cache_Version, update_execute, and the usage of _ for translation functions. For example:

    # Import necessary modules for managing listeners
    from .listener_manage import *
    
    # Import constants related to cache versions
    from ..constants.cache_version import Cache_Version
    
    # Import utility function for executing SQL updates
    from ..db.sql_execute import update_execute
    
    # Import a lock manager using Redis
    from ..utils.lock import RedisLock
  5. Code Formatting: Although Python standardizes on PEP 8 formatting, you might want to ensure alignment within lines, especially in list comprehensions or multi-line strings:

    items = [
        value1,
        value2,
        value3,
    ]
  6. Optional Imports: If importing all methods from a module is not necessary, consider specifying only what's used, e.g., from django.db.models.query import QuerySet.

Here’s your modified version with these points in mind:

from django.core.cache import cache
from django.db.models import QuerySet
from django.utils.translation import gettext as _

# Import necessary management functions from listener_manage
from .listener_manage import *

# Constants related to cache versions
from ..constants.cache_version import Cache_Version

# Utility function for executing SQL updates
from ..db.sql_execute import update_execute

# Lock management class using Redis
from ..utils.lock import RedisLock

If you have any more specific areas where you need help or additional modifications please let me know!

Expand Down
2 changes: 1 addition & 1 deletion apps/knowledge/serializers/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from xlwt import Utils

from common.db.search import native_search, get_dynamics_model, native_page_search
from common.event import ListenerManagement
from common.event.listener_manage import ListenerManagement
from common.event.common import work_thread_pool
from common.exception.app_exception import AppApiException
from common.field.common import UploadedFileField
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've provided has a few issues. The first one is that the ListenerManagement import line seems to have an extra e, making it ListnerManage. This should be corrected to ListenerManagement.

Here's the revised version with the issue addressed:

@@ -25,7 +25,7 @@
 from xlwt import Utils
 
 from common.db.search import native_search, get_dynamics_model, native_page_search
-from common.event import ListenerManagement
+from common.event.listener_management import ListenerManagement
 from common.event.common import work_thread_pool
 from common.exception.app_exception import AppApiException
 from common.field.common import UploadedFileField

This change ensures that the correct import statement uses the full name of the class while removing any extraneous characters.

However, there might still be other potential issues or optimizations depending on the broader context and additional features not included in this snippet. Let me know if you need further clarification or assistance!

Expand Down
2 changes: 1 addition & 1 deletion apps/knowledge/serializers/knowledge.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from common.database_model_manage.database_model_manage import DatabaseModelManage
from common.db.search import native_search, get_dynamics_model, native_page_search
from common.db.sql_execute import select_list
from common.event import ListenerManagement
from common.event.listener_manage import ListenerManagement
from common.exception.app_exception import AppApiException
from common.utils.common import post, get_file_content, parse_image
from common.utils.fork import Fork, ChildLink
Expand Down
2 changes: 1 addition & 1 deletion apps/knowledge/serializers/paragraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from rest_framework import serializers

from common.db.search import page_search
from common.event import ListenerManagement
from common.event.listener_manage import ListenerManagement
from common.exception.app_exception import AppApiException
from common.utils.common import post
from knowledge.models import Paragraph, Problem, Document, ProblemParagraphMapping, SourceType, TaskType, State, \
Expand Down
2 changes: 1 addition & 1 deletion apps/knowledge/task/embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.utils.translation import gettext_lazy as _

from common.config.embedding_config import ModelManage
from common.event import ListenerManagement, UpdateProblemArgs, UpdateEmbeddingKnowledgeIdArgs, \
from common.event.listener_manage import ListenerManagement, UpdateProblemArgs, UpdateEmbeddingKnowledgeIdArgs, \
UpdateEmbeddingDocumentIdArgs
from common.utils.logger import maxkb_logger
from knowledge.models import Document, TaskType, State
Expand Down
3 changes: 1 addition & 2 deletions apps/knowledge/task/generate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import traceback

from celery_once import QueueOnce
Expand All @@ -8,7 +7,7 @@
from langchain_core.messages import HumanMessage

from common.config.embedding_config import ModelManage
from common.event import ListenerManagement
from common.event.listener_manage import ListenerManagement
from common.utils.logger import maxkb_logger
from common.utils.page_utils import page, page_desc
from knowledge.models import Paragraph, Document, Status, TaskType, State
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is one potential issue with this code modification. The line from_common.event might need to be changed to from common.event.listener_manage if the intended import path is different. Otherwise, everything else looks fine in terms of syntax, logic, and file structure. You can confirm by running the code snippet locally or using an IDE that supports Python. If you have more questions on the code or its behavior, feel free to ask!

Expand Down
Loading