mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 02:18:08 +08:00
chore: apply ruff's pyupgrade linter rules to modernize Python code with targeted version (#2419)
This commit is contained in:
@ -1,4 +1,3 @@
|
||||
# -*- coding:utf-8 -*-
|
||||
import base64
|
||||
import json
|
||||
import logging
|
||||
@ -6,7 +5,7 @@ import secrets
|
||||
import uuid
|
||||
from datetime import datetime, timedelta
|
||||
from hashlib import sha256
|
||||
from typing import Any, Dict, Optional
|
||||
from typing import Any, Optional
|
||||
|
||||
from flask import current_app
|
||||
from sqlalchemy import func
|
||||
@ -510,7 +509,7 @@ class RegisterService:
|
||||
redis_client.delete(cls._get_invitation_token_key(token))
|
||||
|
||||
@classmethod
|
||||
def get_invitation_if_token_valid(cls, workspace_id: str, email: str, token: str) -> Optional[Dict[str, Any]]:
|
||||
def get_invitation_if_token_valid(cls, workspace_id: str, email: str, token: str) -> Optional[dict[str, Any]]:
|
||||
invitation_data = cls._get_invitation_by_token(token, workspace_id, email)
|
||||
if not invitation_data:
|
||||
return None
|
||||
@ -544,7 +543,7 @@ class RegisterService:
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def _get_invitation_by_token(cls, token: str, workspace_id: str, email: str) -> Optional[Dict[str, str]]:
|
||||
def _get_invitation_by_token(cls, token: str, workspace_id: str, email: str) -> Optional[dict[str, str]]:
|
||||
if workspace_id is not None and email is not None:
|
||||
email_hash = sha256(email.encode()).hexdigest()
|
||||
cache_key = f'member_invite_token:{workspace_id}, {email_hash}:{token}'
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import json
|
||||
from typing import Any, Generator, Union
|
||||
from collections.abc import Generator
|
||||
from typing import Any, Union
|
||||
|
||||
from sqlalchemy import and_
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ import logging
|
||||
import random
|
||||
import time
|
||||
import uuid
|
||||
from typing import List, Optional, cast
|
||||
from typing import Optional, cast
|
||||
|
||||
from flask import current_app
|
||||
from flask_login import current_user
|
||||
@ -366,7 +366,7 @@ class DocumentService:
|
||||
return document
|
||||
|
||||
@staticmethod
|
||||
def get_document_by_dataset_id(dataset_id: str) -> List[Document]:
|
||||
def get_document_by_dataset_id(dataset_id: str) -> list[Document]:
|
||||
documents = db.session.query(Document).filter(
|
||||
Document.dataset_id == dataset_id,
|
||||
Document.enabled == True
|
||||
@ -375,7 +375,7 @@ class DocumentService:
|
||||
return documents
|
||||
|
||||
@staticmethod
|
||||
def get_batch_documents(dataset_id: str, batch: str) -> List[Document]:
|
||||
def get_batch_documents(dataset_id: str, batch: str) -> list[Document]:
|
||||
documents = db.session.query(Document).filter(
|
||||
Document.batch == batch,
|
||||
Document.dataset_id == dataset_id,
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import datetime
|
||||
import hashlib
|
||||
import uuid
|
||||
from typing import Generator, Tuple, Union
|
||||
from collections.abc import Generator
|
||||
from typing import Union
|
||||
|
||||
from flask import current_app
|
||||
from flask_login import current_user
|
||||
@ -141,7 +142,7 @@ class FileService:
|
||||
return text
|
||||
|
||||
@staticmethod
|
||||
def get_image_preview(file_id: str, timestamp: str, nonce: str, sign: str) -> Tuple[Generator, str]:
|
||||
def get_image_preview(file_id: str, timestamp: str, nonce: str, sign: str) -> tuple[Generator, str]:
|
||||
result = UploadFileParser.verify_image_file_signature(file_id, timestamp, nonce, sign)
|
||||
if not result:
|
||||
raise NotFound("File not found or signature is invalid")
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import logging
|
||||
import threading
|
||||
import time
|
||||
from typing import List
|
||||
|
||||
import numpy as np
|
||||
from flask import current_app
|
||||
@ -131,7 +130,7 @@ class HitTestingService:
|
||||
return cls.compact_retrieve_response(dataset, embeddings, query, all_documents)
|
||||
|
||||
@classmethod
|
||||
def compact_retrieve_response(cls, dataset: Dataset, embeddings: Embeddings, query: str, documents: List[Document]):
|
||||
def compact_retrieve_response(cls, dataset: Dataset, embeddings: Embeddings, query: str, documents: list[Document]):
|
||||
text_embeddings = [
|
||||
embeddings.embed_query(query)
|
||||
]
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import json
|
||||
from typing import List, Optional, Union
|
||||
from typing import Optional, Union
|
||||
|
||||
from core.generator.llm_generator import LLMGenerator
|
||||
from core.memory.token_buffer_memory import TokenBufferMemory
|
||||
@ -177,7 +177,7 @@ class MessageService:
|
||||
|
||||
@classmethod
|
||||
def get_suggested_questions_after_answer(cls, app_model: App, user: Optional[Union[Account, EndUser]],
|
||||
message_id: str, check_enabled: bool = True) -> List[Message]:
|
||||
message_id: str, check_enabled: bool = True) -> list[Message]:
|
||||
if not user:
|
||||
raise ValueError('user cannot be None')
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import logging
|
||||
import mimetypes
|
||||
import os
|
||||
from typing import Optional, Tuple, cast
|
||||
from typing import Optional, cast
|
||||
|
||||
import requests
|
||||
from flask import current_app
|
||||
@ -418,7 +418,7 @@ class ModelProviderService:
|
||||
model=model
|
||||
)
|
||||
|
||||
def get_model_provider_icon(self, provider: str, icon_type: str, lang: str) -> Tuple[Optional[bytes], Optional[str]]:
|
||||
def get_model_provider_icon(self, provider: str, icon_type: str, lang: str) -> tuple[Optional[bytes], Optional[str]]:
|
||||
"""
|
||||
get model provider icon.
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import json
|
||||
from typing import List
|
||||
|
||||
from flask import current_app
|
||||
from httpx import get
|
||||
@ -103,7 +102,7 @@ class ToolManageService:
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def parser_api_schema(schema: str) -> List[ApiBasedToolBundle]:
|
||||
def parser_api_schema(schema: str) -> list[ApiBasedToolBundle]:
|
||||
"""
|
||||
parse api schema to tool bundle
|
||||
"""
|
||||
@ -173,7 +172,7 @@ class ToolManageService:
|
||||
raise ValueError(f'invalid schema: {str(e)}')
|
||||
|
||||
@staticmethod
|
||||
def convert_schema_to_tool_bundles(schema: str, extra_info: dict = None) -> List[ApiBasedToolBundle]:
|
||||
def convert_schema_to_tool_bundles(schema: str, extra_info: dict = None) -> list[ApiBasedToolBundle]:
|
||||
"""
|
||||
convert schema to tool bundles
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
|
||||
from typing import List, Optional
|
||||
from typing import Optional
|
||||
|
||||
from langchain.schema import Document
|
||||
|
||||
@ -10,7 +10,7 @@ from models.dataset import Dataset, DocumentSegment
|
||||
class VectorService:
|
||||
|
||||
@classmethod
|
||||
def create_segment_vector(cls, keywords: Optional[List[str]], segment: DocumentSegment, dataset: Dataset):
|
||||
def create_segment_vector(cls, keywords: Optional[list[str]], segment: DocumentSegment, dataset: Dataset):
|
||||
document = Document(
|
||||
page_content=segment.content,
|
||||
metadata={
|
||||
@ -61,7 +61,7 @@ class VectorService:
|
||||
keyword_index.multi_create_segment_keywords(pre_segment_data_list)
|
||||
|
||||
@classmethod
|
||||
def update_segment_vector(cls, keywords: Optional[List[str]], segment: DocumentSegment, dataset: Dataset):
|
||||
def update_segment_vector(cls, keywords: Optional[list[str]], segment: DocumentSegment, dataset: Dataset):
|
||||
# update segment index task
|
||||
vector_index = IndexBuilder.get_index(dataset, 'high_quality')
|
||||
kw_index = IndexBuilder.get_index(dataset, 'economy')
|
||||
|
||||
Reference in New Issue
Block a user