mirror of
https://github.com/langgenius/dify.git
synced 2026-04-21 06:46:30 +08:00
refactor(services): replace Union with | syntax in service layer (batch 2) (#34906)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
5d4d60bb95
commit
488fcd4f83
@ -1,6 +1,6 @@
|
|||||||
import uuid
|
import uuid
|
||||||
from collections.abc import Generator, Mapping
|
from collections.abc import Generator, Mapping
|
||||||
from typing import Any, Union, cast
|
from typing import Any, cast
|
||||||
|
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
@ -207,7 +207,7 @@ class PluginAppBackwardsInvocation(BaseBackwardsInvocation):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _get_user(cls, user_id: str) -> Union[EndUser, Account]:
|
def _get_user(cls, user_id: str) -> EndUser | Account:
|
||||||
"""
|
"""
|
||||||
get the user by user id
|
get the user by user id
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -6,7 +6,6 @@ import os
|
|||||||
import time
|
import time
|
||||||
from collections.abc import Generator
|
from collections.abc import Generator
|
||||||
from mimetypes import guess_extension, guess_type
|
from mimetypes import guess_extension, guess_type
|
||||||
from typing import Union
|
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
@ -158,7 +157,7 @@ class ToolFileManager:
|
|||||||
|
|
||||||
return tool_file
|
return tool_file
|
||||||
|
|
||||||
def get_file_binary(self, id: str) -> Union[tuple[bytes, str], None]:
|
def get_file_binary(self, id: str) -> tuple[bytes, str] | None:
|
||||||
"""
|
"""
|
||||||
get file binary
|
get file binary
|
||||||
|
|
||||||
@ -176,7 +175,7 @@ class ToolFileManager:
|
|||||||
|
|
||||||
return blob, tool_file.mimetype
|
return blob, tool_file.mimetype
|
||||||
|
|
||||||
def get_file_binary_by_message_file_id(self, id: str) -> Union[tuple[bytes, str], None]:
|
def get_file_binary_by_message_file_id(self, id: str) -> tuple[bytes, str] | None:
|
||||||
"""
|
"""
|
||||||
get file binary
|
get file binary
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ with support for different subscription tiers, rate limiting, and execution trac
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
from datetime import UTC, datetime
|
from datetime import UTC, datetime
|
||||||
from typing import Any, Union
|
from typing import Any
|
||||||
|
|
||||||
from celery.result import AsyncResult
|
from celery.result import AsyncResult
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
@ -50,7 +50,7 @@ class AsyncWorkflowService:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def trigger_workflow_async(
|
def trigger_workflow_async(
|
||||||
cls, session: Session, user: Union[Account, EndUser], trigger_data: TriggerData
|
cls, session: Session, user: Account | EndUser, trigger_data: TriggerData
|
||||||
) -> AsyncTriggerResponse:
|
) -> AsyncTriggerResponse:
|
||||||
"""
|
"""
|
||||||
Universal entry point for async workflow execution - THIS METHOD WILL NOT BLOCK
|
Universal entry point for async workflow execution - THIS METHOD WILL NOT BLOCK
|
||||||
@ -177,7 +177,7 @@ class AsyncWorkflowService:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def reinvoke_trigger(
|
def reinvoke_trigger(
|
||||||
cls, session: Session, user: Union[Account, EndUser], workflow_trigger_log_id: str
|
cls, session: Session, user: Account | EndUser, workflow_trigger_log_id: str
|
||||||
) -> AsyncTriggerResponse:
|
) -> AsyncTriggerResponse:
|
||||||
"""
|
"""
|
||||||
Re-invoke a previously failed or rate-limited trigger - THIS METHOD WILL NOT BLOCK
|
Re-invoke a previously failed or rate-limited trigger - THIS METHOD WILL NOT BLOCK
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from typing import Any, Union, cast
|
from typing import Any, cast
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
@ -195,9 +195,7 @@ class ExternalDatasetService:
|
|||||||
raise ValueError(f"{parameter.get('name')} is required")
|
raise ValueError(f"{parameter.get('name')} is required")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def process_external_api(
|
def process_external_api(settings: ExternalKnowledgeApiSetting, files: dict[str, Any] | None) -> httpx.Response:
|
||||||
settings: ExternalKnowledgeApiSetting, files: Union[None, dict[str, Any]]
|
|
||||||
) -> httpx.Response:
|
|
||||||
"""
|
"""
|
||||||
do http request depending on api bundle
|
do http request depending on api bundle
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, TypedDict, Union
|
from typing import Any, TypedDict
|
||||||
|
|
||||||
from graphon.model_runtime.entities.model_entities import ModelType
|
from graphon.model_runtime.entities.model_entities import ModelType
|
||||||
from graphon.model_runtime.entities.provider_entities import (
|
from graphon.model_runtime.entities.provider_entities import (
|
||||||
@ -626,7 +626,7 @@ class ModelLoadBalancingService:
|
|||||||
|
|
||||||
def _get_credential_schema(
|
def _get_credential_schema(
|
||||||
self, provider_configuration: ProviderConfiguration
|
self, provider_configuration: ProviderConfiguration
|
||||||
) -> Union[ModelCredentialSchema, ProviderCredentialSchema]:
|
) -> ModelCredentialSchema | ProviderCredentialSchema:
|
||||||
"""Get form schemas."""
|
"""Get form schemas."""
|
||||||
if provider_configuration.provider.model_credential_schema:
|
if provider_configuration.provider.model_credential_schema:
|
||||||
return provider_configuration.provider.model_credential_schema
|
return provider_configuration.provider.model_credential_schema
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import threading
|
|||||||
import time
|
import time
|
||||||
from collections.abc import Callable, Generator, Mapping, Sequence
|
from collections.abc import Callable, Generator, Mapping, Sequence
|
||||||
from datetime import UTC, datetime
|
from datetime import UTC, datetime
|
||||||
from typing import Any, Union, cast
|
from typing import Any, cast
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from flask_login import current_user
|
from flask_login import current_user
|
||||||
@ -1387,7 +1387,7 @@ class RagPipelineService:
|
|||||||
"uninstalled_recommended_plugins": uninstalled_plugin_list,
|
"uninstalled_recommended_plugins": uninstalled_plugin_list,
|
||||||
}
|
}
|
||||||
|
|
||||||
def retry_error_document(self, dataset: Dataset, document: Document, user: Union[Account, EndUser]):
|
def retry_error_document(self, dataset: Dataset, document: Document, user: Account | EndUser):
|
||||||
"""
|
"""
|
||||||
Retry error document
|
Retry error document
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
from collections.abc import Mapping
|
from collections.abc import Mapping
|
||||||
from typing import Any, Union
|
from typing import Any
|
||||||
|
|
||||||
from pydantic import TypeAdapter, ValidationError
|
from pydantic import TypeAdapter, ValidationError
|
||||||
from yarl import URL
|
from yarl import URL
|
||||||
@ -69,7 +69,7 @@ class ToolTransformService:
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def repack_provider(tenant_id: str, provider: Union[dict, ToolProviderApiEntity, PluginDatasourceProviderEntity]):
|
def repack_provider(tenant_id: str, provider: dict | ToolProviderApiEntity | PluginDatasourceProviderEntity):
|
||||||
"""
|
"""
|
||||||
repack provider
|
repack provider
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user