mirror of
http://112.124.100.131/huang.ze/ebiz-dify-ai.git
synced 2025-12-09 10:56:52 +08:00
enhancement: introduce Ruff for Python linter for reordering and removing unused imports with automated pre-commit and sytle check (#2366)
This commit is contained in:
@@ -8,23 +8,33 @@ from datetime import datetime, timedelta
|
||||
from hashlib import sha256
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
from flask import current_app
|
||||
from sqlalchemy import func
|
||||
from werkzeug.exceptions import Forbidden
|
||||
|
||||
from constants.languages import language_timezone_mapping, languages
|
||||
from events.tenant_event import tenant_was_created
|
||||
from extensions.ext_redis import redis_client
|
||||
from flask import current_app
|
||||
from libs.helper import get_remote_ip
|
||||
from libs.passport import PassportService
|
||||
from libs.password import compare_password, hash_password
|
||||
from libs.rsa import generate_key_pair
|
||||
from models.account import *
|
||||
from services.errors.account import (AccountAlreadyInTenantError, AccountLoginError, AccountNotLinkTenantError,
|
||||
AccountRegisterError, CannotOperateSelfError, CurrentPasswordIncorrectError,
|
||||
InvalidActionError, LinkAccountIntegrateError, MemberNotInTenantError,
|
||||
NoPermissionError, RoleAlreadyAssignedError, TenantNotFound)
|
||||
from sqlalchemy import func
|
||||
from services.errors.account import (
|
||||
AccountAlreadyInTenantError,
|
||||
AccountLoginError,
|
||||
AccountNotLinkTenantError,
|
||||
AccountRegisterError,
|
||||
CannotOperateSelfError,
|
||||
CurrentPasswordIncorrectError,
|
||||
InvalidActionError,
|
||||
LinkAccountIntegrateError,
|
||||
MemberNotInTenantError,
|
||||
NoPermissionError,
|
||||
RoleAlreadyAssignedError,
|
||||
TenantNotFound,
|
||||
)
|
||||
from tasks.mail_invite_member_task import send_invite_member_mail_task
|
||||
from werkzeug.exceptions import Forbidden
|
||||
from sqlalchemy import exc
|
||||
|
||||
|
||||
def _create_tenant_for_account(account) -> Tenant:
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
|
||||
import copy
|
||||
|
||||
from core.prompt.advanced_prompt_templates import (BAICHUAN_CHAT_APP_CHAT_PROMPT_CONFIG,
|
||||
BAICHUAN_CHAT_APP_COMPLETION_PROMPT_CONFIG,
|
||||
BAICHUAN_COMPLETION_APP_CHAT_PROMPT_CONFIG,
|
||||
BAICHUAN_COMPLETION_APP_COMPLETION_PROMPT_CONFIG, BAICHUAN_CONTEXT,
|
||||
CHAT_APP_CHAT_PROMPT_CONFIG, CHAT_APP_COMPLETION_PROMPT_CONFIG,
|
||||
COMPLETION_APP_CHAT_PROMPT_CONFIG,
|
||||
COMPLETION_APP_COMPLETION_PROMPT_CONFIG, CONTEXT)
|
||||
from core.prompt.advanced_prompt_templates import (
|
||||
BAICHUAN_CHAT_APP_CHAT_PROMPT_CONFIG,
|
||||
BAICHUAN_CHAT_APP_COMPLETION_PROMPT_CONFIG,
|
||||
BAICHUAN_COMPLETION_APP_CHAT_PROMPT_CONFIG,
|
||||
BAICHUAN_COMPLETION_APP_COMPLETION_PROMPT_CONFIG,
|
||||
BAICHUAN_CONTEXT,
|
||||
CHAT_APP_CHAT_PROMPT_CONFIG,
|
||||
CHAT_APP_COMPLETION_PROMPT_CONFIG,
|
||||
COMPLETION_APP_CHAT_PROMPT_CONFIG,
|
||||
COMPLETION_APP_COMPLETION_PROMPT_CONFIG,
|
||||
CONTEXT,
|
||||
)
|
||||
from core.prompt.prompt_transform import AppMode
|
||||
|
||||
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
import datetime
|
||||
import json
|
||||
import uuid
|
||||
|
||||
import pandas as pd
|
||||
from flask_login import current_user
|
||||
from sqlalchemy import or_
|
||||
from werkzeug.datastructures import FileStorage
|
||||
from werkzeug.exceptions import NotFound
|
||||
|
||||
from extensions.ext_database import db
|
||||
from extensions.ext_redis import redis_client
|
||||
from flask_login import current_user
|
||||
from models.model import App, AppAnnotationHitHistory, AppAnnotationSetting, Message, MessageAnnotation
|
||||
from sqlalchemy import or_
|
||||
from tasks.annotation.add_annotation_to_index_task import add_annotation_to_index_task
|
||||
from tasks.annotation.batch_import_annotations_task import batch_import_annotations_task
|
||||
from tasks.annotation.delete_annotation_index_task import delete_annotation_index_task
|
||||
from tasks.annotation.disable_annotation_reply_task import disable_annotation_reply_task
|
||||
from tasks.annotation.enable_annotation_reply_task import enable_annotation_reply_task
|
||||
from tasks.annotation.update_annotation_to_index_task import update_annotation_to_index_task
|
||||
from werkzeug.datastructures import FileStorage
|
||||
from werkzeug.exceptions import NotFound
|
||||
|
||||
|
||||
class AppAnnotationService:
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
import io
|
||||
from typing import Optional
|
||||
|
||||
from werkzeug.datastructures import FileStorage
|
||||
|
||||
from core.model_manager import ModelManager
|
||||
from core.model_runtime.entities.model_entities import ModelType
|
||||
from services.errors.audio import (AudioTooLargeServiceError, NoAudioUploadedServiceError,
|
||||
ProviderNotSupportSpeechToTextServiceError,
|
||||
ProviderNotSupportTextToSpeechServiceError, UnsupportedAudioTypeServiceError)
|
||||
from werkzeug.datastructures import FileStorage
|
||||
from services.errors.audio import (
|
||||
AudioTooLargeServiceError,
|
||||
NoAudioUploadedServiceError,
|
||||
ProviderNotSupportSpeechToTextServiceError,
|
||||
ProviderNotSupportTextToSpeechServiceError,
|
||||
UnsupportedAudioTypeServiceError,
|
||||
)
|
||||
|
||||
FILE_SIZE = 15
|
||||
FILE_SIZE_LIMIT = FILE_SIZE * 1024 * 1024
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
from extensions.ext_database import db
|
||||
from models.account import TenantAccountJoin
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import json
|
||||
from typing import Any, Generator, Union
|
||||
|
||||
from sqlalchemy import and_
|
||||
|
||||
from core.application_manager import ApplicationManager
|
||||
from core.entities.application_entities import InvokeFrom
|
||||
from core.file.message_file_parser import MessageFileParser
|
||||
@@ -11,7 +13,6 @@ from services.errors.app import MoreLikeThisDisabledError
|
||||
from services.errors.app_model_config import AppModelConfigBrokenError
|
||||
from services.errors.conversation import ConversationCompletedError, ConversationNotExistsError
|
||||
from services.errors.message import MessageNotExistsError
|
||||
from sqlalchemy import and_
|
||||
|
||||
|
||||
class CompletionService:
|
||||
|
||||
@@ -6,6 +6,10 @@ import time
|
||||
import uuid
|
||||
from typing import List, Optional, cast
|
||||
|
||||
from flask import current_app
|
||||
from flask_login import current_user
|
||||
from sqlalchemy import func
|
||||
|
||||
from core.errors.error import LLMBadRequestError, ProviderTokenNotInitError
|
||||
from core.index.index import IndexBuilder
|
||||
from core.model_manager import ModelManager
|
||||
@@ -15,12 +19,17 @@ from events.dataset_event import dataset_was_deleted
|
||||
from events.document_event import document_was_deleted
|
||||
from extensions.ext_database import db
|
||||
from extensions.ext_redis import redis_client
|
||||
from flask import current_app
|
||||
from flask_login import current_user
|
||||
from libs import helper
|
||||
from models.account import Account
|
||||
from models.dataset import (AppDatasetJoin, Dataset, DatasetCollectionBinding, DatasetProcessRule, DatasetQuery,
|
||||
Document, DocumentSegment)
|
||||
from models.dataset import (
|
||||
AppDatasetJoin,
|
||||
Dataset,
|
||||
DatasetCollectionBinding,
|
||||
DatasetProcessRule,
|
||||
DatasetQuery,
|
||||
Document,
|
||||
DocumentSegment,
|
||||
)
|
||||
from models.model import UploadFile
|
||||
from models.source import DataSourceBinding
|
||||
from services.errors.account import NoPermissionError
|
||||
@@ -28,7 +37,6 @@ from services.errors.dataset import DatasetNameDuplicateError
|
||||
from services.errors.document import DocumentIndexingError
|
||||
from services.errors.file import FileNotExistsError
|
||||
from services.vector_service import VectorService
|
||||
from sqlalchemy import func
|
||||
from tasks.clean_notion_document_task import clean_notion_document_task
|
||||
from tasks.deal_dataset_vector_index_task import deal_dataset_vector_index_task
|
||||
from tasks.delete_segment_from_index_task import delete_segment_from_index_task
|
||||
|
||||
@@ -1,16 +1,21 @@
|
||||
from enum import Enum
|
||||
from typing import Optional
|
||||
|
||||
from flask import current_app
|
||||
from pydantic import BaseModel
|
||||
|
||||
from core.entities.model_entities import ModelStatus, ModelWithProviderEntity
|
||||
from core.entities.provider_entities import QuotaConfiguration
|
||||
from core.model_runtime.entities.common_entities import I18nObject
|
||||
from core.model_runtime.entities.model_entities import ModelType, ProviderModel
|
||||
from core.model_runtime.entities.provider_entities import (ConfigurateMethod, ModelCredentialSchema,
|
||||
ProviderCredentialSchema, ProviderHelpEntity,
|
||||
SimpleProviderEntity)
|
||||
from flask import current_app
|
||||
from core.model_runtime.entities.provider_entities import (
|
||||
ConfigurateMethod,
|
||||
ModelCredentialSchema,
|
||||
ProviderCredentialSchema,
|
||||
ProviderHelpEntity,
|
||||
SimpleProviderEntity,
|
||||
)
|
||||
from models.provider import ProviderQuotaType, ProviderType
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class CustomConfigurationStatus(Enum):
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from flask import current_app
|
||||
from pydantic import BaseModel
|
||||
|
||||
from services.billing_service import BillingService
|
||||
|
||||
|
||||
|
||||
@@ -3,17 +3,18 @@ import hashlib
|
||||
import uuid
|
||||
from typing import Generator, Tuple, Union
|
||||
|
||||
from flask import current_app
|
||||
from flask_login import current_user
|
||||
from werkzeug.datastructures import FileStorage
|
||||
from werkzeug.exceptions import NotFound
|
||||
|
||||
from core.data_loader.file_extractor import FileExtractor
|
||||
from core.file.upload_file_parser import UploadFileParser
|
||||
from extensions.ext_database import db
|
||||
from extensions.ext_storage import storage
|
||||
from flask import current_app
|
||||
from flask_login import current_user
|
||||
from models.account import Account
|
||||
from models.model import EndUser, UploadFile
|
||||
from services.errors.file import FileTooLargeError, UnsupportedFileTypeError
|
||||
from werkzeug.datastructures import FileStorage
|
||||
from werkzeug.exceptions import NotFound
|
||||
|
||||
IMAGE_EXTENSIONS = ['jpg', 'jpeg', 'png', 'webp', 'gif', 'svg']
|
||||
IMAGE_EXTENSIONS.extend([ext.upper() for ext in IMAGE_EXTENSIONS])
|
||||
|
||||
@@ -4,18 +4,19 @@ import time
|
||||
from typing import List
|
||||
|
||||
import numpy as np
|
||||
from flask import current_app
|
||||
from langchain.embeddings.base import Embeddings
|
||||
from langchain.schema import Document
|
||||
from sklearn.manifold import TSNE
|
||||
|
||||
from core.embedding.cached_embedding import CacheEmbedding
|
||||
from core.model_manager import ModelManager
|
||||
from core.model_runtime.entities.model_entities import ModelType
|
||||
from core.rerank.rerank import RerankRunner
|
||||
from extensions.ext_database import db
|
||||
from flask import current_app
|
||||
from langchain.embeddings.base import Embeddings
|
||||
from langchain.schema import Document
|
||||
from models.account import Account
|
||||
from models.dataset import Dataset, DatasetQuery, DocumentSegment
|
||||
from services.retrieval_service import RetrievalService
|
||||
from sklearn.manifold import TSNE
|
||||
|
||||
default_retrieval_model = {
|
||||
'search_method': 'semantic_search',
|
||||
|
||||
@@ -12,8 +12,12 @@ from models.model import App, AppModelConfig, EndUser, Message, MessageFeedback
|
||||
from services.conversation_service import ConversationService
|
||||
from services.errors.app_model_config import AppModelConfigBrokenError
|
||||
from services.errors.conversation import ConversationCompletedError, ConversationNotExistsError
|
||||
from services.errors.message import (FirstMessageNotExistsError, LastMessageNotExistsError, MessageNotExistsError,
|
||||
SuggestedQuestionsAfterAnswerDisabledError)
|
||||
from services.errors.message import (
|
||||
FirstMessageNotExistsError,
|
||||
LastMessageNotExistsError,
|
||||
MessageNotExistsError,
|
||||
SuggestedQuestionsAfterAnswerDisabledError,
|
||||
)
|
||||
|
||||
|
||||
class MessageService:
|
||||
|
||||
@@ -4,18 +4,25 @@ import os
|
||||
from typing import Optional, Tuple, cast
|
||||
|
||||
import requests
|
||||
from flask import current_app
|
||||
|
||||
from core.entities.model_entities import ModelStatus
|
||||
from core.model_runtime.entities.model_entities import ModelType, ParameterRule
|
||||
from core.model_runtime.model_providers import model_provider_factory
|
||||
from core.model_runtime.model_providers.__base.large_language_model import LargeLanguageModel
|
||||
from core.provider_manager import ProviderManager
|
||||
from flask import current_app
|
||||
from models.provider import ProviderType
|
||||
from services.entities.model_provider_entities import (CustomConfigurationResponse, CustomConfigurationStatus,
|
||||
DefaultModelResponse, ModelResponse,
|
||||
ModelWithProviderEntityResponse, ProviderResponse,
|
||||
ProviderWithModelsResponse, SimpleProviderEntityResponse,
|
||||
SystemConfigurationResponse)
|
||||
from services.entities.model_provider_entities import (
|
||||
CustomConfigurationResponse,
|
||||
CustomConfigurationStatus,
|
||||
DefaultModelResponse,
|
||||
ModelResponse,
|
||||
ModelWithProviderEntityResponse,
|
||||
ProviderResponse,
|
||||
ProviderWithModelsResponse,
|
||||
SimpleProviderEntityResponse,
|
||||
SystemConfigurationResponse,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
from typing import Optional
|
||||
|
||||
from flask import Flask, current_app
|
||||
from langchain.embeddings.base import Embeddings
|
||||
|
||||
from core.index.vector_index.vector_index import VectorIndex
|
||||
from core.model_manager import ModelManager
|
||||
from core.model_runtime.entities.model_entities import ModelType
|
||||
from core.model_runtime.errors.invoke import InvokeAuthorizationError
|
||||
from core.rerank.rerank import RerankRunner
|
||||
from extensions.ext_database import db
|
||||
from flask import Flask, current_app
|
||||
from langchain.embeddings.base import Embeddings
|
||||
from models.dataset import Dataset
|
||||
|
||||
default_retrieval_model = {
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
import json
|
||||
from typing import List, Tuple
|
||||
from typing import List
|
||||
|
||||
from flask import current_app
|
||||
from httpx import get
|
||||
|
||||
from core.tools.entities.common_entities import I18nObject
|
||||
from core.tools.entities.tool_bundle import ApiBasedToolBundle
|
||||
from core.tools.entities.tool_entities import (ApiProviderAuthType, ApiProviderSchemaType, ToolCredentialsOption,
|
||||
ToolProviderCredentials)
|
||||
from core.tools.entities.tool_entities import (
|
||||
ApiProviderAuthType,
|
||||
ApiProviderSchemaType,
|
||||
ToolCredentialsOption,
|
||||
ToolProviderCredentials,
|
||||
)
|
||||
from core.tools.entities.user_entities import UserTool, UserToolProvider
|
||||
from core.tools.errors import ToolNotFoundError, ToolProviderCredentialValidationError, ToolProviderNotFoundError
|
||||
from core.tools.provider.api_tool_provider import ApiBasedToolProviderController
|
||||
@@ -14,8 +21,6 @@ from core.tools.utils.configuration import ToolConfiguration
|
||||
from core.tools.utils.encoder import serialize_base_model_array, serialize_base_model_dict
|
||||
from core.tools.utils.parser import ApiBasedToolSchemaParser
|
||||
from extensions.ext_database import db
|
||||
from flask import current_app
|
||||
from httpx import get
|
||||
from models.tools import ApiToolProvider, BuiltinToolProvider
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
|
||||
from typing import List, Optional
|
||||
|
||||
from core.index.index import IndexBuilder
|
||||
from langchain.schema import Document
|
||||
|
||||
from core.index.index import IndexBuilder
|
||||
from models.dataset import Dataset, DocumentSegment
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
from extensions.ext_database import db
|
||||
from flask import current_app
|
||||
from flask_login import current_user
|
||||
|
||||
from extensions.ext_database import db
|
||||
from models.account import Tenant, TenantAccountJoin, TenantAccountJoinRole
|
||||
from models.provider import Provider
|
||||
from services.account_service import TenantService
|
||||
from services.feature_service import FeatureService
|
||||
|
||||
|
||||
Reference in New Issue
Block a user