diff --git a/api/app.py b/api/app.py index 124306b010..bd782a4380 100644 --- a/api/app.py +++ b/api/app.py @@ -17,10 +17,13 @@ import warnings from flask import Flask, Response, request from flask_cors import CORS - from werkzeug.exceptions import Unauthorized + from commands import register_commands from config import CloudEditionConfig, Config + +# DO NOT REMOVE BELOW +from events import event_handlers from extensions import ( ext_celery, ext_code_based_extension, @@ -37,11 +40,8 @@ from extensions import ( from extensions.ext_database import db from extensions.ext_login import login_manager from libs.passport import PassportService -from services.account_service import AccountService - -# DO NOT REMOVE BELOW -from events import event_handlers from models import account, dataset, model, source, task, tool, tools, web +from services.account_service import AccountService # DO NOT REMOVE ABOVE @@ -151,9 +151,9 @@ def unauthorized_handler(): def register_blueprints(app): from controllers.console import bp as console_app_bp from controllers.files import bp as files_bp + from controllers.inner_api import bp as inner_api_bp from controllers.service_api import bp as service_api_bp from controllers.web import bp as web_bp - from controllers.inner_api import bp as inner_api_bp CORS(service_api_bp, allow_headers=['Content-Type', 'Authorization', 'X-App-Code'], diff --git a/api/controllers/__init__.py b/api/controllers/__init__.py index 2c0485b18d..b28b04f643 100644 --- a/api/controllers/__init__.py +++ b/api/controllers/__init__.py @@ -1,4 +1,3 @@ -# -*- coding:utf-8 -*- diff --git a/api/controllers/console/__init__.py b/api/controllers/console/__init__.py index 2895dbe73e..39c96d9673 100644 --- a/api/controllers/console/__init__.py +++ b/api/controllers/console/__init__.py @@ -1,24 +1,57 @@ from flask import Blueprint + from libs.external_api import ExternalApi bp = Blueprint('console', __name__, url_prefix='/console/api') api = ExternalApi(bp) # Import other controllers -from . import admin, apikey, extension, feature, setup, version, ping +from . import admin, apikey, extension, feature, ping, setup, version + # Import app controllers -from .app import (advanced_prompt_template, annotation, app, audio, completion, conversation, generator, message, - model_config, site, statistic, workflow, workflow_run, workflow_app_log, workflow_statistic, agent) +from .app import ( + advanced_prompt_template, + agent, + annotation, + app, + audio, + completion, + conversation, + generator, + message, + model_config, + site, + statistic, + workflow, + workflow_app_log, + workflow_run, + workflow_statistic, +) + # Import auth controllers from .auth import activate, data_source_oauth, login, oauth + # Import billing controllers from .billing import billing + # Import datasets controllers from .datasets import data_source, datasets, datasets_document, datasets_segments, file, hit_testing -# Import explore controllers -from .explore import (audio, completion, conversation, installed_app, message, parameter, recommended_app, - saved_message, workflow) -# Import workspace controllers -from .workspace import account, members, model_providers, models, tool_providers, workspace + # Import enterprise controllers from .enterprise import enterprise_sso + +# Import explore controllers +from .explore import ( + audio, + completion, + conversation, + installed_app, + message, + parameter, + recommended_app, + saved_message, + workflow, +) + +# Import workspace controllers +from .workspace import account, members, model_providers, models, tool_providers, workspace diff --git a/api/controllers/console/app/app.py b/api/controllers/console/app/app.py index 9c362a9ed0..c694cc7fc3 100644 --- a/api/controllers/console/app/app.py +++ b/api/controllers/console/app/app.py @@ -2,13 +2,15 @@ import json from flask_login import current_user from flask_restful import Resource, inputs, marshal_with, reqparse -from werkzeug.exceptions import Forbidden, BadRequest +from werkzeug.exceptions import BadRequest, Forbidden from controllers.console import api from controllers.console.app.wraps import get_app_model from controllers.console.setup import setup_required from controllers.console.wraps import account_initialization_required, cloud_edition_billing_resource_check from core.agent.entities import AgentToolEntity +from core.tools.tool_manager import ToolManager +from core.tools.utils.configuration import ToolParameterConfigurationManager from extensions.ext_database import db from fields.app_fields import ( app_detail_fields, @@ -16,11 +18,8 @@ from fields.app_fields import ( app_pagination_fields, ) from libs.login import login_required +from models.model import App, AppMode, AppModelConfig from services.app_service import AppService -from models.model import App, AppModelConfig, AppMode -from core.tools.utils.configuration import ToolParameterConfigurationManager -from core.tools.tool_manager import ToolManager - ALLOW_CREATE_APP_MODES = ['chat', 'agent-chat', 'advanced-chat', 'workflow', 'completion'] diff --git a/api/controllers/files/__init__.py b/api/controllers/files/__init__.py index c7bc7d26d2..8d38ab9866 100644 --- a/api/controllers/files/__init__.py +++ b/api/controllers/files/__init__.py @@ -1,5 +1,5 @@ -# -*- coding:utf-8 -*- from flask import Blueprint + from libs.external_api import ExternalApi bp = Blueprint('files', __name__) diff --git a/api/controllers/inner_api/__init__.py b/api/controllers/inner_api/__init__.py index 067c28c3fa..ad49a649ca 100644 --- a/api/controllers/inner_api/__init__.py +++ b/api/controllers/inner_api/__init__.py @@ -1,4 +1,5 @@ from flask import Blueprint + from libs.external_api import ExternalApi bp = Blueprint('inner_api', __name__, url_prefix='/inner/api') diff --git a/api/controllers/service_api/__init__.py b/api/controllers/service_api/__init__.py index 9e6bb3a698..082660a891 100644 --- a/api/controllers/service_api/__init__.py +++ b/api/controllers/service_api/__init__.py @@ -1,5 +1,5 @@ -# -*- coding:utf-8 -*- from flask import Blueprint + from libs.external_api import ExternalApi bp = Blueprint('service_api', __name__, url_prefix='/v1') diff --git a/api/controllers/web/__init__.py b/api/controllers/web/__init__.py index c68d23f878..b6d46d4081 100644 --- a/api/controllers/web/__init__.py +++ b/api/controllers/web/__init__.py @@ -1,5 +1,5 @@ -# -*- coding:utf-8 -*- from flask import Blueprint + from libs.external_api import ExternalApi bp = Blueprint('web', __name__, url_prefix='/api') diff --git a/api/controllers/web/app.py b/api/controllers/web/app.py index 8524bd45b0..2586f2e6ec 100644 --- a/api/controllers/web/app.py +++ b/api/controllers/web/app.py @@ -7,7 +7,7 @@ from controllers.web import api from controllers.web.error import AppUnavailableError from controllers.web.wraps import WebApiResource from extensions.ext_database import db -from models.model import App, AppModelConfig, AppMode +from models.model import App, AppMode, AppModelConfig from models.tools import ApiToolProvider from services.app_service import AppService diff --git a/api/core/model_runtime/model_providers/zhipuai/zhipuai_sdk/__init__.py b/api/core/model_runtime/model_providers/zhipuai/zhipuai_sdk/__init__.py index 8a687ef47a..4dcd03f551 100644 --- a/api/core/model_runtime/model_providers/zhipuai/zhipuai_sdk/__init__.py +++ b/api/core/model_runtime/model_providers/zhipuai/zhipuai_sdk/__init__.py @@ -1,6 +1,15 @@ from .__version__ import __version__ from ._client import ZhipuAI -from .core._errors import (APIAuthenticationError, APIInternalError, APIReachLimitError, APIRequestFailedError, - APIResponseError, APIResponseValidationError, APIServerFlowExceedError, APIStatusError, - APITimeoutError, ZhipuAIError) +from .core._errors import ( + APIAuthenticationError, + APIInternalError, + APIReachLimitError, + APIRequestFailedError, + APIResponseError, + APIResponseValidationError, + APIServerFlowExceedError, + APIStatusError, + APITimeoutError, + ZhipuAIError, +) diff --git a/api/events/event_handlers/__init__.py b/api/events/event_handlers/__init__.py index 9a7c0deb20..cb640fa222 100644 --- a/api/events/event_handlers/__init__.py +++ b/api/events/event_handlers/__init__.py @@ -6,5 +6,5 @@ from .create_site_record_when_app_created import handle from .deduct_quota_when_messaeg_created import handle from .delete_installed_app_when_app_deleted import handle from .update_app_dataset_join_when_app_model_config_updated import handle -from .update_provider_last_used_at_when_messaeg_created import handle from .update_app_dataset_join_when_app_published_workflow_updated import handle +from .update_provider_last_used_at_when_messaeg_created import handle diff --git a/api/libs/__init__.py b/api/libs/__init__.py index 380474e035..e69de29bb2 100644 --- a/api/libs/__init__.py +++ b/api/libs/__init__.py @@ -1 +0,0 @@ -# -*- coding:utf-8 -*- diff --git a/api/pyproject.toml b/api/pyproject.toml index 801a39cff9..0002c61436 100644 --- a/api/pyproject.toml +++ b/api/pyproject.toml @@ -3,9 +3,6 @@ requires-python = ">=3.10" [tool.ruff] exclude = [ - "app.py", - "__init__.py", - "tests/", ] line-length = 120 @@ -26,6 +23,20 @@ ignore = [ "UP032", # f-string ] +[tool.ruff.lint.per-file-ignores] +"app.py" = [ + "F401", # unused-import + "F811", # redefined-while-unused +] +"__init__.py" = [ + "F401", # unused-import + "F811", # redefined-while-unused +] +"tests/*" = [ + "F401", # unused-import + "F811", # redefined-while-unused +] + [tool.pytest_env] OPENAI_API_KEY = "sk-IamNotARealKeyJustForMockTestKawaiiiiiiiiii" diff --git a/api/services/__init__.py b/api/services/__init__.py index 36a7704385..20e68ab6d9 100644 --- a/api/services/__init__.py +++ b/api/services/__init__.py @@ -1,2 +1 @@ -# -*- coding:utf-8 -*- import services.errors diff --git a/api/services/errors/__init__.py b/api/services/errors/__init__.py index 5804f599fe..493919d373 100644 --- a/api/services/errors/__init__.py +++ b/api/services/errors/__init__.py @@ -1,4 +1,3 @@ -# -*- coding:utf-8 -*- __all__ = [ 'base', 'conversation', 'message', 'index', 'app_model_config', 'account', 'document', 'dataset', 'app', 'completion', 'audio', 'file' diff --git a/api/tests/integration_tests/model_runtime/__mock/anthropic.py b/api/tests/integration_tests/model_runtime/__mock/anthropic.py index 2247d33e24..037501c410 100644 --- a/api/tests/integration_tests/model_runtime/__mock/anthropic.py +++ b/api/tests/integration_tests/model_runtime/__mock/anthropic.py @@ -1,22 +1,32 @@ import os +from collections.abc import Iterable from time import sleep -from typing import Any, Literal, Union, Iterable - -from anthropic.resources import Messages -from anthropic.types.message_delta_event import Delta +from typing import Any, Literal, Union import anthropic import pytest from _pytest.monkeypatch import MonkeyPatch from anthropic import Anthropic, Stream -from anthropic.types import MessageParam, Message, MessageStreamEvent, \ - ContentBlock, MessageStartEvent, Usage, TextDelta, MessageDeltaEvent, MessageStopEvent, ContentBlockDeltaEvent, \ - MessageDeltaUsage +from anthropic.resources import Messages +from anthropic.types import ( + ContentBlock, + ContentBlockDeltaEvent, + Message, + MessageDeltaEvent, + MessageDeltaUsage, + MessageParam, + MessageStartEvent, + MessageStopEvent, + MessageStreamEvent, + TextDelta, + Usage, +) +from anthropic.types.message_delta_event import Delta MOCK = os.getenv('MOCK_SWITCH', 'false') == 'true' -class MockAnthropicClass(object): +class MockAnthropicClass: @staticmethod def mocked_anthropic_chat_create_sync(model: str) -> Message: return Message( diff --git a/api/tests/integration_tests/model_runtime/__mock/google.py b/api/tests/integration_tests/model_runtime/__mock/google.py index cc4d8c6fbd..d838e9890f 100644 --- a/api/tests/integration_tests/model_runtime/__mock/google.py +++ b/api/tests/integration_tests/model_runtime/__mock/google.py @@ -1,4 +1,4 @@ -from typing import Generator, List +from collections.abc import Generator import google.generativeai.types.content_types as content_types import google.generativeai.types.generation_types as generation_config_types @@ -6,15 +6,15 @@ import google.generativeai.types.safety_types as safety_types import pytest from _pytest.monkeypatch import MonkeyPatch from google.ai import generativelanguage as glm +from google.ai.generativelanguage_v1beta.types import content as gag_content from google.generativeai import GenerativeModel from google.generativeai.client import _ClientManager, configure from google.generativeai.types import GenerateContentResponse from google.generativeai.types.generation_types import BaseGenerateContentResponse -from google.ai.generativelanguage_v1beta.types import content as gag_content current_api_key = '' -class MockGoogleResponseClass(object): +class MockGoogleResponseClass: _done = False def __iter__(self): @@ -41,7 +41,7 @@ class MockGoogleResponseClass(object): chunks=[] ) -class MockGoogleResponseCandidateClass(object): +class MockGoogleResponseCandidateClass: finish_reason = 'stop' @property @@ -52,7 +52,7 @@ class MockGoogleResponseCandidateClass(object): ] ) -class MockGoogleClass(object): +class MockGoogleClass: @staticmethod def generate_content_sync() -> GenerateContentResponse: return GenerateContentResponse( @@ -91,7 +91,7 @@ class MockGoogleClass(object): return 'it\'s google!' @property - def generative_response_candidates(self) -> List[MockGoogleResponseCandidateClass]: + def generative_response_candidates(self) -> list[MockGoogleResponseCandidateClass]: return [MockGoogleResponseCandidateClass()] def make_client(self: _ClientManager, name: str): diff --git a/api/tests/integration_tests/model_runtime/__mock/huggingface.py b/api/tests/integration_tests/model_runtime/__mock/huggingface.py index e1e87748cd..a75b058d92 100644 --- a/api/tests/integration_tests/model_runtime/__mock/huggingface.py +++ b/api/tests/integration_tests/model_runtime/__mock/huggingface.py @@ -1,9 +1,9 @@ import os -from typing import Any, Dict, List import pytest from _pytest.monkeypatch import MonkeyPatch from huggingface_hub import InferenceClient + from tests.integration_tests.model_runtime.__mock.huggingface_chat import MockHuggingfaceChatClass MOCK = os.getenv('MOCK_SWITCH', 'false').lower() == 'true' diff --git a/api/tests/integration_tests/model_runtime/__mock/huggingface_chat.py b/api/tests/integration_tests/model_runtime/__mock/huggingface_chat.py index 56b7ee4bfe..1607624c3c 100644 --- a/api/tests/integration_tests/model_runtime/__mock/huggingface_chat.py +++ b/api/tests/integration_tests/model_runtime/__mock/huggingface_chat.py @@ -1,14 +1,20 @@ import re -from typing import Any, Generator, List, Literal, Optional, Union +from collections.abc import Generator +from typing import Any, Literal, Optional, Union from _pytest.monkeypatch import MonkeyPatch from huggingface_hub import InferenceClient -from huggingface_hub.inference._text_generation import (Details, StreamDetails, TextGenerationResponse, - TextGenerationStreamResponse, Token) +from huggingface_hub.inference._text_generation import ( + Details, + StreamDetails, + TextGenerationResponse, + TextGenerationStreamResponse, + Token, +) from huggingface_hub.utils import BadRequestError -class MockHuggingfaceChatClass(object): +class MockHuggingfaceChatClass: @staticmethod def generate_create_sync(model: str) -> TextGenerationResponse: response = TextGenerationResponse( diff --git a/api/tests/integration_tests/model_runtime/__mock/openai.py b/api/tests/integration_tests/model_runtime/__mock/openai.py index 92fe30f4c9..0d3f0fbbea 100644 --- a/api/tests/integration_tests/model_runtime/__mock/openai.py +++ b/api/tests/integration_tests/model_runtime/__mock/openai.py @@ -1,7 +1,9 @@ import os -from typing import Callable, List, Literal +from collections.abc import Callable +from typing import Literal import pytest + # import monkeypatch from _pytest.monkeypatch import MonkeyPatch from openai.resources.audio.transcriptions import Transcriptions @@ -10,6 +12,7 @@ from openai.resources.completions import Completions from openai.resources.embeddings import Embeddings from openai.resources.models import Models from openai.resources.moderations import Moderations + from tests.integration_tests.model_runtime.__mock.openai_chat import MockChatClass from tests.integration_tests.model_runtime.__mock.openai_completion import MockCompletionsClass from tests.integration_tests.model_runtime.__mock.openai_embeddings import MockEmbeddingsClass @@ -18,7 +21,7 @@ from tests.integration_tests.model_runtime.__mock.openai_remote import MockModel from tests.integration_tests.model_runtime.__mock.openai_speech2text import MockSpeech2TextClass -def mock_openai(monkeypatch: MonkeyPatch, methods: List[Literal["completion", "chat", "remote", "moderation", "speech2text", "text_embedding"]]) -> Callable[[], None]: +def mock_openai(monkeypatch: MonkeyPatch, methods: list[Literal["completion", "chat", "remote", "moderation", "speech2text", "text_embedding"]]) -> Callable[[], None]: """ mock openai module diff --git a/api/tests/integration_tests/model_runtime/__mock/openai_chat.py b/api/tests/integration_tests/model_runtime/__mock/openai_chat.py index dbc061b952..35a93b2489 100644 --- a/api/tests/integration_tests/model_runtime/__mock/openai_chat.py +++ b/api/tests/integration_tests/model_runtime/__mock/openai_chat.py @@ -1,31 +1,44 @@ import re +from collections.abc import Generator from json import dumps, loads from time import sleep, time + # import monkeypatch -from typing import Any, Generator, List, Literal, Optional, Union +from typing import Any, Literal, Optional, Union import openai.types.chat.completion_create_params as completion_create_params -from core.model_runtime.errors.invoke import InvokeAuthorizationError from openai import AzureOpenAI, OpenAI from openai._types import NOT_GIVEN, NotGiven from openai.resources.chat.completions import Completions from openai.types import Completion as CompletionMessage -from openai.types.chat import (ChatCompletion, ChatCompletionChunk, ChatCompletionMessageParam, - ChatCompletionMessageToolCall, ChatCompletionToolChoiceOptionParam, - ChatCompletionToolParam) +from openai.types.chat import ( + ChatCompletion, + ChatCompletionChunk, + ChatCompletionMessageParam, + ChatCompletionMessageToolCall, + ChatCompletionToolChoiceOptionParam, + ChatCompletionToolParam, +) from openai.types.chat.chat_completion import ChatCompletion as _ChatCompletion from openai.types.chat.chat_completion import Choice as _ChatCompletionChoice -from openai.types.chat.chat_completion_chunk import (Choice, ChoiceDelta, ChoiceDeltaFunctionCall, ChoiceDeltaToolCall, - ChoiceDeltaToolCallFunction) +from openai.types.chat.chat_completion_chunk import ( + Choice, + ChoiceDelta, + ChoiceDeltaFunctionCall, + ChoiceDeltaToolCall, + ChoiceDeltaToolCallFunction, +) from openai.types.chat.chat_completion_message import ChatCompletionMessage, FunctionCall from openai.types.chat.chat_completion_message_tool_call import Function from openai.types.completion_usage import CompletionUsage +from core.model_runtime.errors.invoke import InvokeAuthorizationError -class MockChatClass(object): + +class MockChatClass: @staticmethod def generate_function_call( - functions: List[completion_create_params.Function] | NotGiven = NOT_GIVEN, + functions: list[completion_create_params.Function] | NotGiven = NOT_GIVEN, ) -> Optional[FunctionCall]: if not functions or len(functions) == 0: return None @@ -61,8 +74,8 @@ class MockChatClass(object): @staticmethod def generate_tool_calls( - tools: List[ChatCompletionToolParam] | NotGiven = NOT_GIVEN, - ) -> Optional[List[ChatCompletionMessageToolCall]]: + tools: list[ChatCompletionToolParam] | NotGiven = NOT_GIVEN, + ) -> Optional[list[ChatCompletionMessageToolCall]]: list_tool_calls = [] if not tools or len(tools) == 0: return None @@ -91,8 +104,8 @@ class MockChatClass(object): @staticmethod def mocked_openai_chat_create_sync( model: str, - functions: List[completion_create_params.Function] | NotGiven = NOT_GIVEN, - tools: List[ChatCompletionToolParam] | NotGiven = NOT_GIVEN, + functions: list[completion_create_params.Function] | NotGiven = NOT_GIVEN, + tools: list[ChatCompletionToolParam] | NotGiven = NOT_GIVEN, ) -> CompletionMessage: tool_calls = [] function_call = MockChatClass.generate_function_call(functions=functions) @@ -128,8 +141,8 @@ class MockChatClass(object): @staticmethod def mocked_openai_chat_create_stream( model: str, - functions: List[completion_create_params.Function] | NotGiven = NOT_GIVEN, - tools: List[ChatCompletionToolParam] | NotGiven = NOT_GIVEN, + functions: list[completion_create_params.Function] | NotGiven = NOT_GIVEN, + tools: list[ChatCompletionToolParam] | NotGiven = NOT_GIVEN, ) -> Generator[ChatCompletionChunk, None, None]: tool_calls = [] function_call = MockChatClass.generate_function_call(functions=functions) @@ -197,17 +210,17 @@ class MockChatClass(object): ) def chat_create(self: Completions, *, - messages: List[ChatCompletionMessageParam], + messages: list[ChatCompletionMessageParam], model: Union[str,Literal[ "gpt-4-1106-preview", "gpt-4-vision-preview", "gpt-4", "gpt-4-0314", "gpt-4-0613", "gpt-4-32k", "gpt-4-32k-0314", "gpt-4-32k-0613", "gpt-3.5-turbo-1106", "gpt-3.5-turbo", "gpt-3.5-turbo-16k", "gpt-3.5-turbo-0301", "gpt-3.5-turbo-0613", "gpt-3.5-turbo-16k-0613"], ], - functions: List[completion_create_params.Function] | NotGiven = NOT_GIVEN, + functions: list[completion_create_params.Function] | NotGiven = NOT_GIVEN, response_format: completion_create_params.ResponseFormat | NotGiven = NOT_GIVEN, stream: Optional[Literal[False]] | NotGiven = NOT_GIVEN, - tools: List[ChatCompletionToolParam] | NotGiven = NOT_GIVEN, + tools: list[ChatCompletionToolParam] | NotGiven = NOT_GIVEN, **kwargs: Any, ): openai_models = [ diff --git a/api/tests/integration_tests/model_runtime/__mock/openai_completion.py b/api/tests/integration_tests/model_runtime/__mock/openai_completion.py index 4a33a508a1..ec0f306aa3 100644 --- a/api/tests/integration_tests/model_runtime/__mock/openai_completion.py +++ b/api/tests/integration_tests/model_runtime/__mock/openai_completion.py @@ -1,9 +1,10 @@ import re +from collections.abc import Generator from time import sleep, time -# import monkeypatch -from typing import Any, Generator, List, Literal, Optional, Union -from core.model_runtime.errors.invoke import InvokeAuthorizationError +# import monkeypatch +from typing import Any, Literal, Optional, Union + from openai import AzureOpenAI, BadRequestError, OpenAI from openai._types import NOT_GIVEN, NotGiven from openai.resources.completions import Completions @@ -11,8 +12,10 @@ from openai.types import Completion as CompletionMessage from openai.types.completion import CompletionChoice from openai.types.completion_usage import CompletionUsage +from core.model_runtime.errors.invoke import InvokeAuthorizationError -class MockCompletionsClass(object): + +class MockCompletionsClass: @staticmethod def mocked_openai_completion_create_sync( model: str @@ -90,7 +93,7 @@ class MockCompletionsClass(object): "code-davinci-002", "text-curie-001", "text-babbage-001", "text-ada-001"], ], - prompt: Union[str, List[str], List[int], List[List[int]], None], + prompt: Union[str, list[str], list[int], list[list[int]], None], stream: Optional[Literal[False]] | NotGiven = NOT_GIVEN, **kwargs: Any ): diff --git a/api/tests/integration_tests/model_runtime/__mock/openai_embeddings.py b/api/tests/integration_tests/model_runtime/__mock/openai_embeddings.py index 9c3d293281..eccdbd3479 100644 --- a/api/tests/integration_tests/model_runtime/__mock/openai_embeddings.py +++ b/api/tests/integration_tests/model_runtime/__mock/openai_embeddings.py @@ -1,18 +1,19 @@ import re -from typing import Any, List, Literal, Union +from typing import Any, Literal, Union -from core.model_runtime.errors.invoke import InvokeAuthorizationError from openai import OpenAI from openai._types import NOT_GIVEN, NotGiven from openai.resources.embeddings import Embeddings from openai.types.create_embedding_response import CreateEmbeddingResponse, Usage from openai.types.embedding import Embedding +from core.model_runtime.errors.invoke import InvokeAuthorizationError -class MockEmbeddingsClass(object): + +class MockEmbeddingsClass: def create_embeddings( self: Embeddings, *, - input: Union[str, List[str], List[int], List[List[int]]], + input: Union[str, list[str], list[int], list[list[int]]], model: Union[str, Literal["text-embedding-ada-002"]], encoding_format: Literal["float", "base64"] | NotGiven = NOT_GIVEN, **kwargs: Any diff --git a/api/tests/integration_tests/model_runtime/__mock/openai_moderation.py b/api/tests/integration_tests/model_runtime/__mock/openai_moderation.py index 634fa77096..9466f4bfb8 100644 --- a/api/tests/integration_tests/model_runtime/__mock/openai_moderation.py +++ b/api/tests/integration_tests/model_runtime/__mock/openai_moderation.py @@ -1,16 +1,17 @@ import re -from typing import Any, List, Literal, Union +from typing import Any, Literal, Union -from core.model_runtime.errors.invoke import InvokeAuthorizationError from openai._types import NOT_GIVEN, NotGiven from openai.resources.moderations import Moderations from openai.types import ModerationCreateResponse from openai.types.moderation import Categories, CategoryScores, Moderation +from core.model_runtime.errors.invoke import InvokeAuthorizationError -class MockModerationClass(object): + +class MockModerationClass: def moderation_create(self: Moderations,*, - input: Union[str, List[str]], + input: Union[str, list[str]], model: Union[str, Literal["text-moderation-latest", "text-moderation-stable"]] | NotGiven = NOT_GIVEN, **kwargs: Any ) -> ModerationCreateResponse: diff --git a/api/tests/integration_tests/model_runtime/__mock/openai_remote.py b/api/tests/integration_tests/model_runtime/__mock/openai_remote.py index 3d665ad5c3..0124ac045b 100644 --- a/api/tests/integration_tests/model_runtime/__mock/openai_remote.py +++ b/api/tests/integration_tests/model_runtime/__mock/openai_remote.py @@ -1,18 +1,17 @@ from time import time -from typing import List from openai.resources.models import Models from openai.types.model import Model -class MockModelClass(object): +class MockModelClass: """ mock class for openai.models.Models """ def list( self, **kwargs, - ) -> List[Model]: + ) -> list[Model]: return [ Model( id='ft:gpt-3.5-turbo-0613:personal::8GYJLPDQ', diff --git a/api/tests/integration_tests/model_runtime/__mock/openai_speech2text.py b/api/tests/integration_tests/model_runtime/__mock/openai_speech2text.py index 8032747bd1..755fec4c1f 100644 --- a/api/tests/integration_tests/model_runtime/__mock/openai_speech2text.py +++ b/api/tests/integration_tests/model_runtime/__mock/openai_speech2text.py @@ -1,13 +1,14 @@ import re -from typing import Any, List, Literal, Union +from typing import Any, Literal, Union -from core.model_runtime.errors.invoke import InvokeAuthorizationError from openai._types import NOT_GIVEN, FileTypes, NotGiven from openai.resources.audio.transcriptions import Transcriptions from openai.types.audio.transcription import Transcription +from core.model_runtime.errors.invoke import InvokeAuthorizationError -class MockSpeech2TextClass(object): + +class MockSpeech2TextClass: def speech2text_create(self: Transcriptions, *, file: FileTypes, diff --git a/api/tests/integration_tests/model_runtime/__mock/xinference.py b/api/tests/integration_tests/model_runtime/__mock/xinference.py index bba5704d2e..ddb18fe919 100644 --- a/api/tests/integration_tests/model_runtime/__mock/xinference.py +++ b/api/tests/integration_tests/model_runtime/__mock/xinference.py @@ -1,19 +1,24 @@ import os import re -from typing import List, Union +from typing import Union import pytest from _pytest.monkeypatch import MonkeyPatch from requests import Response from requests.exceptions import ConnectionError from requests.sessions import Session -from xinference_client.client.restful.restful_client import (Client, RESTfulChatglmCppChatModelHandle, - RESTfulChatModelHandle, RESTfulEmbeddingModelHandle, - RESTfulGenerateModelHandle, RESTfulRerankModelHandle) +from xinference_client.client.restful.restful_client import ( + Client, + RESTfulChatglmCppChatModelHandle, + RESTfulChatModelHandle, + RESTfulEmbeddingModelHandle, + RESTfulGenerateModelHandle, + RESTfulRerankModelHandle, +) from xinference_client.types import Embedding, EmbeddingData, EmbeddingUsage -class MockXinferenceClass(object): +class MockXinferenceClass: def get_chat_model(self: Client, model_uid: str) -> Union[RESTfulChatglmCppChatModelHandle, RESTfulGenerateModelHandle, RESTfulChatModelHandle]: if not re.match(r'https?:\/\/[^\s\/$.?#].[^\s]*$', self.base_url): raise RuntimeError('404 Not Found') @@ -101,7 +106,7 @@ class MockXinferenceClass(object): def _check_cluster_authenticated(self): self._cluster_authed = True - def rerank(self: RESTfulRerankModelHandle, documents: List[str], query: str, top_n: int) -> dict: + def rerank(self: RESTfulRerankModelHandle, documents: list[str], query: str, top_n: int) -> dict: # check if self._model_uid is a valid uuid if not re.match(r'[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}', self._model_uid) and \ self._model_uid != 'rerank': @@ -126,7 +131,7 @@ class MockXinferenceClass(object): def create_embedding( self: RESTfulGenerateModelHandle, - input: Union[str, List[str]], + input: Union[str, list[str]], **kwargs ) -> dict: # check if self._model_uid is a valid uuid diff --git a/api/tests/integration_tests/model_runtime/anthropic/test_llm.py b/api/tests/integration_tests/model_runtime/anthropic/test_llm.py index b3f6414800..0d54d97daa 100644 --- a/api/tests/integration_tests/model_runtime/anthropic/test_llm.py +++ b/api/tests/integration_tests/model_runtime/anthropic/test_llm.py @@ -1,7 +1,8 @@ import os -from typing import Generator +from collections.abc import Generator import pytest + from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta from core.model_runtime.entities.message_entities import AssistantPromptMessage, SystemPromptMessage, UserPromptMessage from core.model_runtime.errors.validate import CredentialsValidateFailedError diff --git a/api/tests/integration_tests/model_runtime/anthropic/test_provider.py b/api/tests/integration_tests/model_runtime/anthropic/test_provider.py index 3ab624d351..7eaa40dfdd 100644 --- a/api/tests/integration_tests/model_runtime/anthropic/test_provider.py +++ b/api/tests/integration_tests/model_runtime/anthropic/test_provider.py @@ -1,6 +1,7 @@ import os import pytest + from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.anthropic.anthropic import AnthropicProvider from tests.integration_tests.model_runtime.__mock.anthropic import setup_anthropic_mock diff --git a/api/tests/integration_tests/model_runtime/azure_openai/test_llm.py b/api/tests/integration_tests/model_runtime/azure_openai/test_llm.py index bf9d9ea06b..e17d0acf99 100644 --- a/api/tests/integration_tests/model_runtime/azure_openai/test_llm.py +++ b/api/tests/integration_tests/model_runtime/azure_openai/test_llm.py @@ -1,11 +1,17 @@ import os -from typing import Generator +from collections.abc import Generator import pytest + from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta -from core.model_runtime.entities.message_entities import (AssistantPromptMessage, ImagePromptMessageContent, - PromptMessageTool, SystemPromptMessage, - TextPromptMessageContent, UserPromptMessage) +from core.model_runtime.entities.message_entities import ( + AssistantPromptMessage, + ImagePromptMessageContent, + PromptMessageTool, + SystemPromptMessage, + TextPromptMessageContent, + UserPromptMessage, +) from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.azure_openai.llm.llm import AzureOpenAILargeLanguageModel from tests.integration_tests.model_runtime.__mock.openai import setup_openai_mock diff --git a/api/tests/integration_tests/model_runtime/azure_openai/test_text_embedding.py b/api/tests/integration_tests/model_runtime/azure_openai/test_text_embedding.py index 7dca6fedda..8b838eb8fc 100644 --- a/api/tests/integration_tests/model_runtime/azure_openai/test_text_embedding.py +++ b/api/tests/integration_tests/model_runtime/azure_openai/test_text_embedding.py @@ -1,6 +1,7 @@ import os import pytest + from core.model_runtime.entities.text_embedding_entities import TextEmbeddingResult from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.azure_openai.text_embedding.text_embedding import AzureOpenAITextEmbeddingModel diff --git a/api/tests/integration_tests/model_runtime/baichuan/test_llm.py b/api/tests/integration_tests/model_runtime/baichuan/test_llm.py index d4b1523f01..1cae9a6dd0 100644 --- a/api/tests/integration_tests/model_runtime/baichuan/test_llm.py +++ b/api/tests/integration_tests/model_runtime/baichuan/test_llm.py @@ -1,8 +1,9 @@ import os +from collections.abc import Generator from time import sleep -from typing import Generator import pytest + from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta from core.model_runtime.entities.message_entities import AssistantPromptMessage, SystemPromptMessage, UserPromptMessage from core.model_runtime.entities.model_entities import AIModelEntity diff --git a/api/tests/integration_tests/model_runtime/baichuan/test_provider.py b/api/tests/integration_tests/model_runtime/baichuan/test_provider.py index fc85a506ac..87b3d9a609 100644 --- a/api/tests/integration_tests/model_runtime/baichuan/test_provider.py +++ b/api/tests/integration_tests/model_runtime/baichuan/test_provider.py @@ -1,6 +1,7 @@ import os import pytest + from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.baichuan.baichuan import BaichuanProvider diff --git a/api/tests/integration_tests/model_runtime/baichuan/test_text_embedding.py b/api/tests/integration_tests/model_runtime/baichuan/test_text_embedding.py index 932e48d808..1210ebc53d 100644 --- a/api/tests/integration_tests/model_runtime/baichuan/test_text_embedding.py +++ b/api/tests/integration_tests/model_runtime/baichuan/test_text_embedding.py @@ -1,6 +1,7 @@ import os import pytest + from core.model_runtime.entities.text_embedding_entities import TextEmbeddingResult from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.baichuan.text_embedding.text_embedding import BaichuanTextEmbeddingModel diff --git a/api/tests/integration_tests/model_runtime/bedrock/test_llm.py b/api/tests/integration_tests/model_runtime/bedrock/test_llm.py index 750c049614..20dc11151a 100644 --- a/api/tests/integration_tests/model_runtime/bedrock/test_llm.py +++ b/api/tests/integration_tests/model_runtime/bedrock/test_llm.py @@ -1,7 +1,8 @@ import os -from typing import Generator +from collections.abc import Generator import pytest + from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta from core.model_runtime.entities.message_entities import AssistantPromptMessage, SystemPromptMessage, UserPromptMessage from core.model_runtime.errors.validate import CredentialsValidateFailedError diff --git a/api/tests/integration_tests/model_runtime/bedrock/test_provider.py b/api/tests/integration_tests/model_runtime/bedrock/test_provider.py index 6819f8c9a1..e53d4c1db2 100644 --- a/api/tests/integration_tests/model_runtime/bedrock/test_provider.py +++ b/api/tests/integration_tests/model_runtime/bedrock/test_provider.py @@ -1,6 +1,7 @@ import os import pytest + from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.bedrock.bedrock import BedrockProvider diff --git a/api/tests/integration_tests/model_runtime/chatglm/test_llm.py b/api/tests/integration_tests/model_runtime/chatglm/test_llm.py index d009dbefca..e32f01a315 100644 --- a/api/tests/integration_tests/model_runtime/chatglm/test_llm.py +++ b/api/tests/integration_tests/model_runtime/chatglm/test_llm.py @@ -1,11 +1,16 @@ import os -from typing import Generator +from collections.abc import Generator import pytest + from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta -from core.model_runtime.entities.message_entities import (AssistantPromptMessage, PromptMessageTool, - SystemPromptMessage, TextPromptMessageContent, - UserPromptMessage) +from core.model_runtime.entities.message_entities import ( + AssistantPromptMessage, + PromptMessageTool, + SystemPromptMessage, + TextPromptMessageContent, + UserPromptMessage, +) from core.model_runtime.entities.model_entities import AIModelEntity from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.chatglm.llm.llm import ChatGLMLargeLanguageModel diff --git a/api/tests/integration_tests/model_runtime/chatglm/test_provider.py b/api/tests/integration_tests/model_runtime/chatglm/test_provider.py index 4baa25a38b..e9c5c4da75 100644 --- a/api/tests/integration_tests/model_runtime/chatglm/test_provider.py +++ b/api/tests/integration_tests/model_runtime/chatglm/test_provider.py @@ -1,6 +1,7 @@ import os import pytest + from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.chatglm.chatglm import ChatGLMProvider from tests.integration_tests.model_runtime.__mock.openai import setup_openai_mock diff --git a/api/tests/integration_tests/model_runtime/cohere/test_llm.py b/api/tests/integration_tests/model_runtime/cohere/test_llm.py index a3d054cacf..499e6289bc 100644 --- a/api/tests/integration_tests/model_runtime/cohere/test_llm.py +++ b/api/tests/integration_tests/model_runtime/cohere/test_llm.py @@ -1,7 +1,8 @@ import os -from typing import Generator +from collections.abc import Generator import pytest + from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta from core.model_runtime.entities.message_entities import AssistantPromptMessage, SystemPromptMessage, UserPromptMessage from core.model_runtime.errors.validate import CredentialsValidateFailedError diff --git a/api/tests/integration_tests/model_runtime/cohere/test_provider.py b/api/tests/integration_tests/model_runtime/cohere/test_provider.py index 176ba9bc07..a8f56b6194 100644 --- a/api/tests/integration_tests/model_runtime/cohere/test_provider.py +++ b/api/tests/integration_tests/model_runtime/cohere/test_provider.py @@ -1,6 +1,7 @@ import os import pytest + from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.cohere.cohere import CohereProvider diff --git a/api/tests/integration_tests/model_runtime/cohere/test_rerank.py b/api/tests/integration_tests/model_runtime/cohere/test_rerank.py index a022193f8d..415c5fbfda 100644 --- a/api/tests/integration_tests/model_runtime/cohere/test_rerank.py +++ b/api/tests/integration_tests/model_runtime/cohere/test_rerank.py @@ -1,6 +1,7 @@ import os import pytest + from core.model_runtime.entities.rerank_entities import RerankResult from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.cohere.rerank.rerank import CohereRerankModel diff --git a/api/tests/integration_tests/model_runtime/cohere/test_text_embedding.py b/api/tests/integration_tests/model_runtime/cohere/test_text_embedding.py index 9a15acc260..5017ba47e1 100644 --- a/api/tests/integration_tests/model_runtime/cohere/test_text_embedding.py +++ b/api/tests/integration_tests/model_runtime/cohere/test_text_embedding.py @@ -1,6 +1,7 @@ import os import pytest + from core.model_runtime.entities.text_embedding_entities import TextEmbeddingResult from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.cohere.text_embedding.text_embedding import CohereTextEmbeddingModel diff --git a/api/tests/integration_tests/model_runtime/google/test_llm.py b/api/tests/integration_tests/model_runtime/google/test_llm.py index 5383b2c05b..00d907d19e 100644 --- a/api/tests/integration_tests/model_runtime/google/test_llm.py +++ b/api/tests/integration_tests/model_runtime/google/test_llm.py @@ -1,11 +1,16 @@ import os -from typing import Generator +from collections.abc import Generator import pytest + from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta -from core.model_runtime.entities.message_entities import (AssistantPromptMessage, ImagePromptMessageContent, - SystemPromptMessage, TextPromptMessageContent, - UserPromptMessage) +from core.model_runtime.entities.message_entities import ( + AssistantPromptMessage, + ImagePromptMessageContent, + SystemPromptMessage, + TextPromptMessageContent, + UserPromptMessage, +) from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.google.llm.llm import GoogleLargeLanguageModel from tests.integration_tests.model_runtime.__mock.google import setup_google_mock diff --git a/api/tests/integration_tests/model_runtime/google/test_provider.py b/api/tests/integration_tests/model_runtime/google/test_provider.py index 5983ae8ba0..103107ed5a 100644 --- a/api/tests/integration_tests/model_runtime/google/test_provider.py +++ b/api/tests/integration_tests/model_runtime/google/test_provider.py @@ -1,6 +1,7 @@ import os import pytest + from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.google.google import GoogleProvider from tests.integration_tests.model_runtime.__mock.google import setup_google_mock diff --git a/api/tests/integration_tests/model_runtime/huggingface_hub/test_llm.py b/api/tests/integration_tests/model_runtime/huggingface_hub/test_llm.py index 08e56bc4fe..28cd0955b3 100644 --- a/api/tests/integration_tests/model_runtime/huggingface_hub/test_llm.py +++ b/api/tests/integration_tests/model_runtime/huggingface_hub/test_llm.py @@ -1,7 +1,8 @@ import os -from typing import Generator +from collections.abc import Generator import pytest + from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta from core.model_runtime.entities.message_entities import AssistantPromptMessage, UserPromptMessage from core.model_runtime.errors.validate import CredentialsValidateFailedError diff --git a/api/tests/integration_tests/model_runtime/huggingface_hub/test_text_embedding.py b/api/tests/integration_tests/model_runtime/huggingface_hub/test_text_embedding.py index 92ae289d0c..d03b3186cb 100644 --- a/api/tests/integration_tests/model_runtime/huggingface_hub/test_text_embedding.py +++ b/api/tests/integration_tests/model_runtime/huggingface_hub/test_text_embedding.py @@ -1,10 +1,12 @@ import os import pytest + from core.model_runtime.entities.text_embedding_entities import TextEmbeddingResult from core.model_runtime.errors.validate import CredentialsValidateFailedError -from core.model_runtime.model_providers.huggingface_hub.text_embedding.text_embedding import \ - HuggingfaceHubTextEmbeddingModel +from core.model_runtime.model_providers.huggingface_hub.text_embedding.text_embedding import ( + HuggingfaceHubTextEmbeddingModel, +) def test_hosted_inference_api_validate_credentials(): diff --git a/api/tests/integration_tests/model_runtime/jina/test_provider.py b/api/tests/integration_tests/model_runtime/jina/test_provider.py index 9568204b9d..2b43248388 100644 --- a/api/tests/integration_tests/model_runtime/jina/test_provider.py +++ b/api/tests/integration_tests/model_runtime/jina/test_provider.py @@ -1,6 +1,7 @@ import os import pytest + from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.jina.jina import JinaProvider diff --git a/api/tests/integration_tests/model_runtime/jina/test_text_embedding.py b/api/tests/integration_tests/model_runtime/jina/test_text_embedding.py index d39970a23c..ac17566174 100644 --- a/api/tests/integration_tests/model_runtime/jina/test_text_embedding.py +++ b/api/tests/integration_tests/model_runtime/jina/test_text_embedding.py @@ -1,6 +1,7 @@ import os import pytest + from core.model_runtime.entities.text_embedding_entities import TextEmbeddingResult from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.jina.text_embedding.text_embedding import JinaTextEmbeddingModel diff --git a/api/tests/integration_tests/model_runtime/localai/test_llm.py b/api/tests/integration_tests/model_runtime/localai/test_llm.py index f885a67893..208959815c 100644 --- a/api/tests/integration_tests/model_runtime/localai/test_llm.py +++ b/api/tests/integration_tests/model_runtime/localai/test_llm.py @@ -1,11 +1,16 @@ import os -from typing import Generator +from collections.abc import Generator import pytest + from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta -from core.model_runtime.entities.message_entities import (AssistantPromptMessage, PromptMessageTool, - SystemPromptMessage, TextPromptMessageContent, - UserPromptMessage) +from core.model_runtime.entities.message_entities import ( + AssistantPromptMessage, + PromptMessageTool, + SystemPromptMessage, + TextPromptMessageContent, + UserPromptMessage, +) from core.model_runtime.entities.model_entities import ParameterRule from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.localai.llm.llm import LocalAILarguageModel diff --git a/api/tests/integration_tests/model_runtime/minimax/test_embedding.py b/api/tests/integration_tests/model_runtime/minimax/test_embedding.py index 3a1e06ab22..6f4b8a163f 100644 --- a/api/tests/integration_tests/model_runtime/minimax/test_embedding.py +++ b/api/tests/integration_tests/model_runtime/minimax/test_embedding.py @@ -1,6 +1,7 @@ import os import pytest + from core.model_runtime.entities.text_embedding_entities import TextEmbeddingResult from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.minimax.text_embedding.text_embedding import MinimaxTextEmbeddingModel diff --git a/api/tests/integration_tests/model_runtime/minimax/test_llm.py b/api/tests/integration_tests/model_runtime/minimax/test_llm.py index 05f632a583..570e4901a9 100644 --- a/api/tests/integration_tests/model_runtime/minimax/test_llm.py +++ b/api/tests/integration_tests/model_runtime/minimax/test_llm.py @@ -1,8 +1,9 @@ import os +from collections.abc import Generator from time import sleep -from typing import Generator import pytest + from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta from core.model_runtime.entities.message_entities import AssistantPromptMessage, UserPromptMessage from core.model_runtime.entities.model_entities import AIModelEntity diff --git a/api/tests/integration_tests/model_runtime/minimax/test_provider.py b/api/tests/integration_tests/model_runtime/minimax/test_provider.py index 08872d704e..4c5462c6df 100644 --- a/api/tests/integration_tests/model_runtime/minimax/test_provider.py +++ b/api/tests/integration_tests/model_runtime/minimax/test_provider.py @@ -1,6 +1,7 @@ import os import pytest + from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.minimax.minimax import MinimaxProvider diff --git a/api/tests/integration_tests/model_runtime/ollama/test_llm.py b/api/tests/integration_tests/model_runtime/ollama/test_llm.py index 4265190f58..272e639a8a 100644 --- a/api/tests/integration_tests/model_runtime/ollama/test_llm.py +++ b/api/tests/integration_tests/model_runtime/ollama/test_llm.py @@ -1,11 +1,16 @@ import os -from typing import Generator +from collections.abc import Generator import pytest + from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta -from core.model_runtime.entities.message_entities import (AssistantPromptMessage, ImagePromptMessageContent, - SystemPromptMessage, TextPromptMessageContent, - UserPromptMessage) +from core.model_runtime.entities.message_entities import ( + AssistantPromptMessage, + ImagePromptMessageContent, + SystemPromptMessage, + TextPromptMessageContent, + UserPromptMessage, +) from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.ollama.llm.llm import OllamaLargeLanguageModel diff --git a/api/tests/integration_tests/model_runtime/ollama/test_text_embedding.py b/api/tests/integration_tests/model_runtime/ollama/test_text_embedding.py index e305226b85..c5f5918235 100644 --- a/api/tests/integration_tests/model_runtime/ollama/test_text_embedding.py +++ b/api/tests/integration_tests/model_runtime/ollama/test_text_embedding.py @@ -1,6 +1,7 @@ import os import pytest + from core.model_runtime.entities.text_embedding_entities import TextEmbeddingResult from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.ollama.text_embedding.text_embedding import OllamaEmbeddingModel diff --git a/api/tests/integration_tests/model_runtime/openai/test_llm.py b/api/tests/integration_tests/model_runtime/openai/test_llm.py index 55afd69167..0da4dbb49d 100644 --- a/api/tests/integration_tests/model_runtime/openai/test_llm.py +++ b/api/tests/integration_tests/model_runtime/openai/test_llm.py @@ -1,11 +1,17 @@ import os -from typing import Generator +from collections.abc import Generator import pytest + from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta -from core.model_runtime.entities.message_entities import (AssistantPromptMessage, ImagePromptMessageContent, - PromptMessageTool, SystemPromptMessage, - TextPromptMessageContent, UserPromptMessage) +from core.model_runtime.entities.message_entities import ( + AssistantPromptMessage, + ImagePromptMessageContent, + PromptMessageTool, + SystemPromptMessage, + TextPromptMessageContent, + UserPromptMessage, +) from core.model_runtime.entities.model_entities import AIModelEntity, ModelType from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.__base.large_language_model import LargeLanguageModel diff --git a/api/tests/integration_tests/model_runtime/openai/test_moderation.py b/api/tests/integration_tests/model_runtime/openai/test_moderation.py index 1154d76ad7..04f9b9f33b 100644 --- a/api/tests/integration_tests/model_runtime/openai/test_moderation.py +++ b/api/tests/integration_tests/model_runtime/openai/test_moderation.py @@ -1,6 +1,7 @@ import os import pytest + from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.openai.moderation.moderation import OpenAIModerationModel from tests.integration_tests.model_runtime.__mock.openai import setup_openai_mock diff --git a/api/tests/integration_tests/model_runtime/openai/test_provider.py b/api/tests/integration_tests/model_runtime/openai/test_provider.py index f4eaa61c04..5314bffbdf 100644 --- a/api/tests/integration_tests/model_runtime/openai/test_provider.py +++ b/api/tests/integration_tests/model_runtime/openai/test_provider.py @@ -1,6 +1,7 @@ import os import pytest + from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.openai.openai import OpenAIProvider from tests.integration_tests.model_runtime.__mock.openai import setup_openai_mock diff --git a/api/tests/integration_tests/model_runtime/openai/test_speech2text.py b/api/tests/integration_tests/model_runtime/openai/test_speech2text.py index 6d00ee2ea1..f1a5c4fd23 100644 --- a/api/tests/integration_tests/model_runtime/openai/test_speech2text.py +++ b/api/tests/integration_tests/model_runtime/openai/test_speech2text.py @@ -1,6 +1,7 @@ import os import pytest + from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.openai.speech2text.speech2text import OpenAISpeech2TextModel from tests.integration_tests.model_runtime.__mock.openai import setup_openai_mock diff --git a/api/tests/integration_tests/model_runtime/openai/test_text_embedding.py b/api/tests/integration_tests/model_runtime/openai/test_text_embedding.py index 927903a5a0..e2c4c74ee7 100644 --- a/api/tests/integration_tests/model_runtime/openai/test_text_embedding.py +++ b/api/tests/integration_tests/model_runtime/openai/test_text_embedding.py @@ -1,6 +1,7 @@ import os import pytest + from core.model_runtime.entities.text_embedding_entities import TextEmbeddingResult from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.openai.text_embedding.text_embedding import OpenAITextEmbeddingModel diff --git a/api/tests/integration_tests/model_runtime/openai_api_compatible/test_llm.py b/api/tests/integration_tests/model_runtime/openai_api_compatible/test_llm.py index c3cb5a481c..c833508569 100644 --- a/api/tests/integration_tests/model_runtime/openai_api_compatible/test_llm.py +++ b/api/tests/integration_tests/model_runtime/openai_api_compatible/test_llm.py @@ -1,10 +1,15 @@ import os -from typing import Generator +from collections.abc import Generator import pytest + from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta -from core.model_runtime.entities.message_entities import (AssistantPromptMessage, PromptMessageTool, - SystemPromptMessage, UserPromptMessage) +from core.model_runtime.entities.message_entities import ( + AssistantPromptMessage, + PromptMessageTool, + SystemPromptMessage, + UserPromptMessage, +) from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.openai_api_compatible.llm.llm import OAIAPICompatLargeLanguageModel diff --git a/api/tests/integration_tests/model_runtime/openai_api_compatible/test_text_embedding.py b/api/tests/integration_tests/model_runtime/openai_api_compatible/test_text_embedding.py index 80be869ec1..77d27ec161 100644 --- a/api/tests/integration_tests/model_runtime/openai_api_compatible/test_text_embedding.py +++ b/api/tests/integration_tests/model_runtime/openai_api_compatible/test_text_embedding.py @@ -1,10 +1,12 @@ import os import pytest + from core.model_runtime.entities.text_embedding_entities import TextEmbeddingResult from core.model_runtime.errors.validate import CredentialsValidateFailedError -from core.model_runtime.model_providers.openai_api_compatible.text_embedding.text_embedding import \ - OAICompatEmbeddingModel +from core.model_runtime.model_providers.openai_api_compatible.text_embedding.text_embedding import ( + OAICompatEmbeddingModel, +) """ Using OpenAI's API as testing endpoint diff --git a/api/tests/integration_tests/model_runtime/openllm/test_embedding.py b/api/tests/integration_tests/model_runtime/openllm/test_embedding.py index 8b6fc6738d..9eb05a111d 100644 --- a/api/tests/integration_tests/model_runtime/openllm/test_embedding.py +++ b/api/tests/integration_tests/model_runtime/openllm/test_embedding.py @@ -1,6 +1,7 @@ import os import pytest + from core.model_runtime.entities.text_embedding_entities import TextEmbeddingResult from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.openllm.text_embedding.text_embedding import OpenLLMTextEmbeddingModel diff --git a/api/tests/integration_tests/model_runtime/openllm/test_llm.py b/api/tests/integration_tests/model_runtime/openllm/test_llm.py index 42bd48cace..853a0fbe3c 100644 --- a/api/tests/integration_tests/model_runtime/openllm/test_llm.py +++ b/api/tests/integration_tests/model_runtime/openllm/test_llm.py @@ -1,7 +1,8 @@ import os -from typing import Generator +from collections.abc import Generator import pytest + from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta from core.model_runtime.entities.message_entities import AssistantPromptMessage, UserPromptMessage from core.model_runtime.errors.validate import CredentialsValidateFailedError diff --git a/api/tests/integration_tests/model_runtime/openrouter/test_llm.py b/api/tests/integration_tests/model_runtime/openrouter/test_llm.py index c0164e6418..8f1fb4c4ad 100644 --- a/api/tests/integration_tests/model_runtime/openrouter/test_llm.py +++ b/api/tests/integration_tests/model_runtime/openrouter/test_llm.py @@ -1,10 +1,15 @@ import os -from typing import Generator +from collections.abc import Generator import pytest + from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta -from core.model_runtime.entities.message_entities import (AssistantPromptMessage, PromptMessageTool, - SystemPromptMessage, UserPromptMessage) +from core.model_runtime.entities.message_entities import ( + AssistantPromptMessage, + PromptMessageTool, + SystemPromptMessage, + UserPromptMessage, +) from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.openrouter.llm.llm import OpenRouterLargeLanguageModel diff --git a/api/tests/integration_tests/model_runtime/replicate/test_llm.py b/api/tests/integration_tests/model_runtime/replicate/test_llm.py index f6768f20f8..e248f064c0 100644 --- a/api/tests/integration_tests/model_runtime/replicate/test_llm.py +++ b/api/tests/integration_tests/model_runtime/replicate/test_llm.py @@ -1,7 +1,8 @@ import os -from typing import Generator +from collections.abc import Generator import pytest + from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta from core.model_runtime.entities.message_entities import AssistantPromptMessage, SystemPromptMessage, UserPromptMessage from core.model_runtime.errors.validate import CredentialsValidateFailedError diff --git a/api/tests/integration_tests/model_runtime/replicate/test_text_embedding.py b/api/tests/integration_tests/model_runtime/replicate/test_text_embedding.py index 30144db74a..5708ec9e5a 100644 --- a/api/tests/integration_tests/model_runtime/replicate/test_text_embedding.py +++ b/api/tests/integration_tests/model_runtime/replicate/test_text_embedding.py @@ -1,6 +1,7 @@ import os import pytest + from core.model_runtime.entities.text_embedding_entities import TextEmbeddingResult from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.replicate.text_embedding.text_embedding import ReplicateEmbeddingModel diff --git a/api/tests/integration_tests/model_runtime/spark/test_llm.py b/api/tests/integration_tests/model_runtime/spark/test_llm.py index 78ad71b4cf..706316449d 100644 --- a/api/tests/integration_tests/model_runtime/spark/test_llm.py +++ b/api/tests/integration_tests/model_runtime/spark/test_llm.py @@ -1,7 +1,8 @@ import os -from typing import Generator +from collections.abc import Generator import pytest + from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta from core.model_runtime.entities.message_entities import AssistantPromptMessage, SystemPromptMessage, UserPromptMessage from core.model_runtime.errors.validate import CredentialsValidateFailedError diff --git a/api/tests/integration_tests/model_runtime/spark/test_provider.py b/api/tests/integration_tests/model_runtime/spark/test_provider.py index 8f65fa1af3..8e22815a86 100644 --- a/api/tests/integration_tests/model_runtime/spark/test_provider.py +++ b/api/tests/integration_tests/model_runtime/spark/test_provider.py @@ -1,6 +1,7 @@ import os import pytest + from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.spark.spark import SparkProvider diff --git a/api/tests/integration_tests/model_runtime/togetherai/test_llm.py b/api/tests/integration_tests/model_runtime/togetherai/test_llm.py index 2581bd46c1..698f534517 100644 --- a/api/tests/integration_tests/model_runtime/togetherai/test_llm.py +++ b/api/tests/integration_tests/model_runtime/togetherai/test_llm.py @@ -1,10 +1,15 @@ import os -from typing import Generator +from collections.abc import Generator import pytest + from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta -from core.model_runtime.entities.message_entities import (AssistantPromptMessage, PromptMessageTool, - SystemPromptMessage, UserPromptMessage) +from core.model_runtime.entities.message_entities import ( + AssistantPromptMessage, + PromptMessageTool, + SystemPromptMessage, + UserPromptMessage, +) from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.togetherai.llm.llm import TogetherAILargeLanguageModel diff --git a/api/tests/integration_tests/model_runtime/tongyi/test_llm.py b/api/tests/integration_tests/model_runtime/tongyi/test_llm.py index 217a17d801..81fb676018 100644 --- a/api/tests/integration_tests/model_runtime/tongyi/test_llm.py +++ b/api/tests/integration_tests/model_runtime/tongyi/test_llm.py @@ -1,7 +1,8 @@ import os -from typing import Generator +from collections.abc import Generator import pytest + from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta from core.model_runtime.entities.message_entities import AssistantPromptMessage, SystemPromptMessage, UserPromptMessage from core.model_runtime.errors.validate import CredentialsValidateFailedError diff --git a/api/tests/integration_tests/model_runtime/tongyi/test_provider.py b/api/tests/integration_tests/model_runtime/tongyi/test_provider.py index 4cfe5930f4..6145c1dc37 100644 --- a/api/tests/integration_tests/model_runtime/tongyi/test_provider.py +++ b/api/tests/integration_tests/model_runtime/tongyi/test_provider.py @@ -1,6 +1,7 @@ import os import pytest + from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.tongyi.tongyi import TongyiProvider diff --git a/api/tests/integration_tests/model_runtime/wenxin/test_llm.py b/api/tests/integration_tests/model_runtime/wenxin/test_llm.py index 23933b9700..164e8253d9 100644 --- a/api/tests/integration_tests/model_runtime/wenxin/test_llm.py +++ b/api/tests/integration_tests/model_runtime/wenxin/test_llm.py @@ -1,8 +1,9 @@ import os +from collections.abc import Generator from time import sleep -from typing import Generator import pytest + from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta from core.model_runtime.entities.message_entities import AssistantPromptMessage, SystemPromptMessage, UserPromptMessage from core.model_runtime.entities.model_entities import AIModelEntity diff --git a/api/tests/integration_tests/model_runtime/wenxin/test_provider.py b/api/tests/integration_tests/model_runtime/wenxin/test_provider.py index 683135b534..8922aa1868 100644 --- a/api/tests/integration_tests/model_runtime/wenxin/test_provider.py +++ b/api/tests/integration_tests/model_runtime/wenxin/test_provider.py @@ -1,6 +1,7 @@ import os import pytest + from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.wenxin.wenxin import WenxinProvider diff --git a/api/tests/integration_tests/model_runtime/xinference/test_embeddings.py b/api/tests/integration_tests/model_runtime/xinference/test_embeddings.py index c3f2f7083c..f0a5151f3d 100644 --- a/api/tests/integration_tests/model_runtime/xinference/test_embeddings.py +++ b/api/tests/integration_tests/model_runtime/xinference/test_embeddings.py @@ -1,6 +1,7 @@ import os import pytest + from core.model_runtime.entities.text_embedding_entities import TextEmbeddingResult from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.xinference.text_embedding.text_embedding import XinferenceTextEmbeddingModel diff --git a/api/tests/integration_tests/model_runtime/xinference/test_llm.py b/api/tests/integration_tests/model_runtime/xinference/test_llm.py index f31e6e48f5..47730406de 100644 --- a/api/tests/integration_tests/model_runtime/xinference/test_llm.py +++ b/api/tests/integration_tests/model_runtime/xinference/test_llm.py @@ -1,11 +1,16 @@ import os -from typing import Generator +from collections.abc import Generator import pytest + from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta -from core.model_runtime.entities.message_entities import (AssistantPromptMessage, PromptMessageTool, - SystemPromptMessage, TextPromptMessageContent, - UserPromptMessage) +from core.model_runtime.entities.message_entities import ( + AssistantPromptMessage, + PromptMessageTool, + SystemPromptMessage, + TextPromptMessageContent, + UserPromptMessage, +) from core.model_runtime.entities.model_entities import AIModelEntity from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.xinference.llm.llm import XinferenceAILargeLanguageModel diff --git a/api/tests/integration_tests/model_runtime/xinference/test_rerank.py b/api/tests/integration_tests/model_runtime/xinference/test_rerank.py index dd638317bd..9012c16a7e 100644 --- a/api/tests/integration_tests/model_runtime/xinference/test_rerank.py +++ b/api/tests/integration_tests/model_runtime/xinference/test_rerank.py @@ -1,6 +1,7 @@ import os import pytest + from core.model_runtime.entities.rerank_entities import RerankResult from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.xinference.rerank.rerank import XinferenceRerankModel diff --git a/api/tests/integration_tests/model_runtime/zhipuai/test_llm.py b/api/tests/integration_tests/model_runtime/zhipuai/test_llm.py index 5ca1ee44b8..393fe9fb2f 100644 --- a/api/tests/integration_tests/model_runtime/zhipuai/test_llm.py +++ b/api/tests/integration_tests/model_runtime/zhipuai/test_llm.py @@ -1,10 +1,15 @@ import os -from typing import Generator +from collections.abc import Generator import pytest + from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta -from core.model_runtime.entities.message_entities import (AssistantPromptMessage, PromptMessageTool, - SystemPromptMessage, UserPromptMessage) +from core.model_runtime.entities.message_entities import ( + AssistantPromptMessage, + PromptMessageTool, + SystemPromptMessage, + UserPromptMessage, +) from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.zhipuai.llm.llm import ZhipuAILargeLanguageModel diff --git a/api/tests/integration_tests/model_runtime/zhipuai/test_provider.py b/api/tests/integration_tests/model_runtime/zhipuai/test_provider.py index 6ec65df7e3..51b9cccf2e 100644 --- a/api/tests/integration_tests/model_runtime/zhipuai/test_provider.py +++ b/api/tests/integration_tests/model_runtime/zhipuai/test_provider.py @@ -1,6 +1,7 @@ import os import pytest + from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.zhipuai.zhipuai import ZhipuaiProvider diff --git a/api/tests/integration_tests/model_runtime/zhipuai/test_text_embedding.py b/api/tests/integration_tests/model_runtime/zhipuai/test_text_embedding.py index e8589350fd..7308c57296 100644 --- a/api/tests/integration_tests/model_runtime/zhipuai/test_text_embedding.py +++ b/api/tests/integration_tests/model_runtime/zhipuai/test_text_embedding.py @@ -1,6 +1,7 @@ import os import pytest + from core.model_runtime.entities.text_embedding_entities import TextEmbeddingResult from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.zhipuai.text_embedding.text_embedding import ZhipuAITextEmbeddingModel diff --git a/api/tests/integration_tests/tools/test_all_provider.py b/api/tests/integration_tests/tools/test_all_provider.py index 65645cb6c5..2811bc816d 100644 --- a/api/tests/integration_tests/tools/test_all_provider.py +++ b/api/tests/integration_tests/tools/test_all_provider.py @@ -1,4 +1,5 @@ import pytest + from core.tools.tool_manager import ToolManager provider_generator = ToolManager.list_builtin_providers() diff --git a/api/tests/integration_tests/utils/test_module_import_helper.py b/api/tests/integration_tests/utils/test_module_import_helper.py index e7da226434..39ac41b648 100644 --- a/api/tests/integration_tests/utils/test_module_import_helper.py +++ b/api/tests/integration_tests/utils/test_module_import_helper.py @@ -1,6 +1,6 @@ import os -from core.utils.module_import_helper import load_single_subclass_from_source, import_module_from_source +from core.utils.module_import_helper import import_module_from_source, load_single_subclass_from_source from tests.integration_tests.utils.parent_class import ParentClass diff --git a/api/tests/integration_tests/workflow/nodes/__mock/code_executor.py b/api/tests/integration_tests/workflow/nodes/__mock/code_executor.py index f83a41c955..38517cf448 100644 --- a/api/tests/integration_tests/workflow/nodes/__mock/code_executor.py +++ b/api/tests/integration_tests/workflow/nodes/__mock/code_executor.py @@ -1,8 +1,9 @@ import os -import pytest - from typing import Literal + +import pytest from _pytest.monkeypatch import MonkeyPatch + from core.helper.code_executor.code_executor import CodeExecutor MOCK = os.getenv('MOCK_SWITCH', 'false') == 'true' diff --git a/api/tests/integration_tests/workflow/nodes/__mock/http.py b/api/tests/integration_tests/workflow/nodes/__mock/http.py index 9cc43031f3..b74a49b640 100644 --- a/api/tests/integration_tests/workflow/nodes/__mock/http.py +++ b/api/tests/integration_tests/workflow/nodes/__mock/http.py @@ -1,14 +1,14 @@ import os +from json import dumps +from typing import Literal + +import httpx._api as httpx import pytest import requests.api as requests -import httpx._api as httpx -from requests import Response as RequestsResponse -from httpx import Request as HttpxRequest -from yarl import URL - -from typing import Literal from _pytest.monkeypatch import MonkeyPatch -from json import dumps +from httpx import Request as HttpxRequest +from requests import Response as RequestsResponse +from yarl import URL MOCK = os.getenv('MOCK_SWITCH', 'false') == 'true' diff --git a/api/tests/integration_tests/workflow/nodes/test_code.py b/api/tests/integration_tests/workflow/nodes/test_code.py index b211b8a701..9755cc3e2f 100644 --- a/api/tests/integration_tests/workflow/nodes/test_code.py +++ b/api/tests/integration_tests/workflow/nodes/test_code.py @@ -1,13 +1,13 @@ -import pytest -from core.app.entities.app_invoke_entities import InvokeFrom +from os import getenv +import pytest + +from core.app.entities.app_invoke_entities import InvokeFrom from core.workflow.entities.variable_pool import VariablePool from core.workflow.nodes.code.code_node import CodeNode from models.workflow import WorkflowNodeExecutionStatus from tests.integration_tests.workflow.nodes.__mock.code_executor import setup_code_executor_mock -from os import getenv - CODE_MAX_STRING_LENGTH = int(getenv('CODE_MAX_STRING_LENGTH', '10000')) @pytest.mark.parametrize('setup_code_executor_mock', [['none']], indirect=True) diff --git a/api/tests/integration_tests/workflow/nodes/test_http.py b/api/tests/integration_tests/workflow/nodes/test_http.py index a6c011944f..63b6b7d962 100644 --- a/api/tests/integration_tests/workflow/nodes/test_http.py +++ b/api/tests/integration_tests/workflow/nodes/test_http.py @@ -1,8 +1,8 @@ import pytest + from core.app.entities.app_invoke_entities import InvokeFrom from core.workflow.entities.variable_pool import VariablePool from core.workflow.nodes.http_request.http_request_node import HttpRequestNode - from tests.integration_tests.workflow.nodes.__mock.http import setup_http_mock BASIC_NODE_DATA = { diff --git a/api/tests/integration_tests/workflow/nodes/test_llm.py b/api/tests/integration_tests/workflow/nodes/test_llm.py index 73794336c2..c0c431912a 100644 --- a/api/tests/integration_tests/workflow/nodes/test_llm.py +++ b/api/tests/integration_tests/workflow/nodes/test_llm.py @@ -4,8 +4,8 @@ from unittest.mock import MagicMock import pytest from core.app.entities.app_invoke_entities import ModelConfigWithCredentialsEntity -from core.entities.provider_configuration import ProviderModelBundle, ProviderConfiguration -from core.entities.provider_entities import SystemConfiguration, CustomConfiguration, CustomProviderConfiguration +from core.entities.provider_configuration import ProviderConfiguration, ProviderModelBundle +from core.entities.provider_entities import CustomConfiguration, CustomProviderConfiguration, SystemConfiguration from core.model_manager import ModelInstance from core.model_runtime.entities.model_entities import ModelType from core.model_runtime.model_providers import ModelProviderFactory diff --git a/api/tests/integration_tests/workflow/nodes/test_template_transform.py b/api/tests/integration_tests/workflow/nodes/test_template_transform.py index 36cf0a070a..4a31334056 100644 --- a/api/tests/integration_tests/workflow/nodes/test_template_transform.py +++ b/api/tests/integration_tests/workflow/nodes/test_template_transform.py @@ -6,6 +6,7 @@ from core.workflow.nodes.template_transform.template_transform_node import Templ from models.workflow import WorkflowNodeExecutionStatus from tests.integration_tests.workflow.nodes.__mock.code_executor import setup_code_executor_mock + @pytest.mark.parametrize('setup_code_executor_mock', [['none']], indirect=True) def test_execute_code(setup_code_executor_mock): code = '''{{args2}}''' diff --git a/api/tests/integration_tests/workflow/nodes/test_tool.py b/api/tests/integration_tests/workflow/nodes/test_tool.py index e2bc68b767..4bbd4ccee7 100644 --- a/api/tests/integration_tests/workflow/nodes/test_tool.py +++ b/api/tests/integration_tests/workflow/nodes/test_tool.py @@ -1,9 +1,9 @@ from core.app.entities.app_invoke_entities import InvokeFrom - from core.workflow.entities.variable_pool import VariablePool from core.workflow.nodes.tool.tool_node import ToolNode from models.workflow import WorkflowNodeExecutionStatus + def test_tool_variable_invoke(): pool = VariablePool(system_variables={}, user_inputs={}) pool.append_variable(node_id='1', variable_key_list=['123', 'args1'], value='1+1') diff --git a/api/tests/unit_tests/core/prompt/test_advanced_prompt_transform.py b/api/tests/unit_tests/core/prompt/test_advanced_prompt_transform.py index 30208331ab..fd284488b5 100644 --- a/api/tests/unit_tests/core/prompt/test_advanced_prompt_transform.py +++ b/api/tests/unit_tests/core/prompt/test_advanced_prompt_transform.py @@ -2,12 +2,12 @@ from unittest.mock import MagicMock import pytest -from core.app.app_config.entities import ModelConfigEntity, FileExtraConfig -from core.file.file_obj import FileVar, FileType, FileTransferMethod +from core.app.app_config.entities import FileExtraConfig, ModelConfigEntity +from core.file.file_obj import FileTransferMethod, FileType, FileVar from core.memory.token_buffer_memory import TokenBufferMemory -from core.model_runtime.entities.message_entities import UserPromptMessage, AssistantPromptMessage, PromptMessageRole +from core.model_runtime.entities.message_entities import AssistantPromptMessage, PromptMessageRole, UserPromptMessage from core.prompt.advanced_prompt_transform import AdvancedPromptTransform -from core.prompt.entities.advanced_prompt_entities import CompletionModelPromptTemplate, MemoryConfig, ChatModelMessage +from core.prompt.entities.advanced_prompt_entities import ChatModelMessage, CompletionModelPromptTemplate, MemoryConfig from core.prompt.utils.prompt_template_parser import PromptTemplateParser from models.model import Conversation diff --git a/api/tests/unit_tests/core/prompt/test_prompt_transform.py b/api/tests/unit_tests/core/prompt/test_prompt_transform.py index 9796fc5558..40f5be8af9 100644 --- a/api/tests/unit_tests/core/prompt/test_prompt_transform.py +++ b/api/tests/unit_tests/core/prompt/test_prompt_transform.py @@ -3,7 +3,7 @@ from unittest.mock import MagicMock from core.app.app_config.entities import ModelConfigEntity from core.entities.provider_configuration import ProviderModelBundle from core.model_runtime.entities.message_entities import UserPromptMessage -from core.model_runtime.entities.model_entities import ModelPropertyKey, AIModelEntity, ParameterRule +from core.model_runtime.entities.model_entities import AIModelEntity, ModelPropertyKey, ParameterRule from core.model_runtime.model_providers.__base.large_language_model import LargeLanguageModel from core.prompt.prompt_transform import PromptTransform diff --git a/api/tests/unit_tests/core/prompt/test_simple_prompt_transform.py b/api/tests/unit_tests/core/prompt/test_simple_prompt_transform.py index be9fe8d004..ad72837ae2 100644 --- a/api/tests/unit_tests/core/prompt/test_simple_prompt_transform.py +++ b/api/tests/unit_tests/core/prompt/test_simple_prompt_transform.py @@ -2,7 +2,7 @@ from unittest.mock import MagicMock from core.app.entities.app_invoke_entities import ModelConfigWithCredentialsEntity from core.memory.token_buffer_memory import TokenBufferMemory -from core.model_runtime.entities.message_entities import UserPromptMessage, AssistantPromptMessage +from core.model_runtime.entities.message_entities import AssistantPromptMessage, UserPromptMessage from core.prompt.simple_prompt_transform import SimplePromptTransform from models.model import AppMode, Conversation diff --git a/api/tests/unit_tests/services/workflow/test_workflow_converter.py b/api/tests/unit_tests/services/workflow/test_workflow_converter.py index 30c9976750..140c84bf47 100644 --- a/api/tests/unit_tests/services/workflow/test_workflow_converter.py +++ b/api/tests/unit_tests/services/workflow/test_workflow_converter.py @@ -4,9 +4,17 @@ from unittest.mock import MagicMock import pytest -from core.app.app_config.entities import VariableEntity, ExternalDataVariableEntity, DatasetEntity, \ - DatasetRetrieveConfigEntity, ModelConfigEntity, PromptTemplateEntity, AdvancedChatPromptTemplateEntity, \ - AdvancedChatMessageEntity, AdvancedCompletionPromptTemplateEntity +from core.app.app_config.entities import ( + AdvancedChatMessageEntity, + AdvancedChatPromptTemplateEntity, + AdvancedCompletionPromptTemplateEntity, + DatasetEntity, + DatasetRetrieveConfigEntity, + ExternalDataVariableEntity, + ModelConfigEntity, + PromptTemplateEntity, + VariableEntity, +) from core.helper import encrypter from core.model_runtime.entities.llm_entities import LLMMode from core.model_runtime.entities.message_entities import PromptMessageRole