refactor: rename plugin manager to plugin client and rename path from manager to impl (#18876)

This commit is contained in:
Yeuoly
2025-04-27 14:22:25 +08:00
committed by GitHub
parent d91828dd90
commit abafa68647
38 changed files with 116 additions and 103 deletions

View File

@@ -26,7 +26,7 @@ from core.model_runtime.errors.invoke import (
)
from core.model_runtime.model_providers.__base.tokenizers.gpt2_tokenzier import GPT2Tokenizer
from core.plugin.entities.plugin_daemon import PluginDaemonInnerError, PluginModelProviderEntity
from core.plugin.manager.model import PluginModelManager
from core.plugin.impl.model import PluginModelClient
class AIModel(BaseModel):
@@ -141,7 +141,7 @@ class AIModel(BaseModel):
:param credentials: model credentials
:return: model schema
"""
plugin_model_manager = PluginModelManager()
plugin_model_manager = PluginModelClient()
cache_key = f"{self.tenant_id}:{self.plugin_id}:{self.provider_name}:{self.model_type.value}:{model}"
# sort credentials
sorted_credentials = sorted(credentials.items()) if credentials else []

View File

@@ -21,7 +21,7 @@ from core.model_runtime.entities.model_entities import (
)
from core.model_runtime.model_providers.__base.ai_model import AIModel
from core.model_runtime.utils.helper import convert_llm_result_chunk_to_str
from core.plugin.manager.model import PluginModelManager
from core.plugin.impl.model import PluginModelClient
logger = logging.getLogger(__name__)
@@ -141,7 +141,7 @@ class LargeLanguageModel(AIModel):
result: Union[LLMResult, Generator[LLMResultChunk, None, None]]
try:
plugin_model_manager = PluginModelManager()
plugin_model_manager = PluginModelClient()
result = plugin_model_manager.invoke_llm(
tenant_id=self.tenant_id,
user_id=user or "unknown",
@@ -329,7 +329,7 @@ class LargeLanguageModel(AIModel):
:return:
"""
if dify_config.PLUGIN_BASED_TOKEN_COUNTING_ENABLED:
plugin_model_manager = PluginModelManager()
plugin_model_manager = PluginModelClient()
return plugin_model_manager.get_llm_num_tokens(
tenant_id=self.tenant_id,
user_id="unknown",

View File

@@ -5,7 +5,7 @@ from pydantic import ConfigDict
from core.model_runtime.entities.model_entities import ModelType
from core.model_runtime.model_providers.__base.ai_model import AIModel
from core.plugin.manager.model import PluginModelManager
from core.plugin.impl.model import PluginModelClient
class ModerationModel(AIModel):
@@ -31,7 +31,7 @@ class ModerationModel(AIModel):
self.started_at = time.perf_counter()
try:
plugin_model_manager = PluginModelManager()
plugin_model_manager = PluginModelClient()
return plugin_model_manager.invoke_moderation(
tenant_id=self.tenant_id,
user_id=user or "unknown",

View File

@@ -3,7 +3,7 @@ from typing import Optional
from core.model_runtime.entities.model_entities import ModelType
from core.model_runtime.entities.rerank_entities import RerankResult
from core.model_runtime.model_providers.__base.ai_model import AIModel
from core.plugin.manager.model import PluginModelManager
from core.plugin.impl.model import PluginModelClient
class RerankModel(AIModel):
@@ -36,7 +36,7 @@ class RerankModel(AIModel):
:return: rerank result
"""
try:
plugin_model_manager = PluginModelManager()
plugin_model_manager = PluginModelClient()
return plugin_model_manager.invoke_rerank(
tenant_id=self.tenant_id,
user_id=user or "unknown",

View File

@@ -4,7 +4,7 @@ from pydantic import ConfigDict
from core.model_runtime.entities.model_entities import ModelType
from core.model_runtime.model_providers.__base.ai_model import AIModel
from core.plugin.manager.model import PluginModelManager
from core.plugin.impl.model import PluginModelClient
class Speech2TextModel(AIModel):
@@ -28,7 +28,7 @@ class Speech2TextModel(AIModel):
:return: text for given audio file
"""
try:
plugin_model_manager = PluginModelManager()
plugin_model_manager = PluginModelClient()
return plugin_model_manager.invoke_speech_to_text(
tenant_id=self.tenant_id,
user_id=user or "unknown",

View File

@@ -6,7 +6,7 @@ from core.entities.embedding_type import EmbeddingInputType
from core.model_runtime.entities.model_entities import ModelPropertyKey, ModelType
from core.model_runtime.entities.text_embedding_entities import TextEmbeddingResult
from core.model_runtime.model_providers.__base.ai_model import AIModel
from core.plugin.manager.model import PluginModelManager
from core.plugin.impl.model import PluginModelClient
class TextEmbeddingModel(AIModel):
@@ -38,7 +38,7 @@ class TextEmbeddingModel(AIModel):
:return: embeddings result
"""
try:
plugin_model_manager = PluginModelManager()
plugin_model_manager = PluginModelClient()
return plugin_model_manager.invoke_text_embedding(
tenant_id=self.tenant_id,
user_id=user or "unknown",
@@ -61,7 +61,7 @@ class TextEmbeddingModel(AIModel):
:param texts: texts to embed
:return:
"""
plugin_model_manager = PluginModelManager()
plugin_model_manager = PluginModelClient()
return plugin_model_manager.get_text_embedding_num_tokens(
tenant_id=self.tenant_id,
user_id="unknown",

View File

@@ -6,7 +6,7 @@ from pydantic import ConfigDict
from core.model_runtime.entities.model_entities import ModelType
from core.model_runtime.model_providers.__base.ai_model import AIModel
from core.plugin.manager.model import PluginModelManager
from core.plugin.impl.model import PluginModelClient
logger = logging.getLogger(__name__)
@@ -42,7 +42,7 @@ class TTSModel(AIModel):
:return: translated audio file
"""
try:
plugin_model_manager = PluginModelManager()
plugin_model_manager = PluginModelClient()
return plugin_model_manager.invoke_tts(
tenant_id=self.tenant_id,
user_id=user or "unknown",
@@ -65,7 +65,7 @@ class TTSModel(AIModel):
:param credentials: The credentials required to access the TTS model.
:return: A list of voices supported by the TTS model.
"""
plugin_model_manager = PluginModelManager()
plugin_model_manager = PluginModelClient()
return plugin_model_manager.get_tts_model_voices(
tenant_id=self.tenant_id,
user_id="unknown",

View File

@@ -22,8 +22,8 @@ from core.model_runtime.schema_validators.model_credential_schema_validator impo
from core.model_runtime.schema_validators.provider_credential_schema_validator import ProviderCredentialSchemaValidator
from core.plugin.entities.plugin import ModelProviderID
from core.plugin.entities.plugin_daemon import PluginModelProviderEntity
from core.plugin.manager.asset import PluginAssetManager
from core.plugin.manager.model import PluginModelManager
from core.plugin.impl.asset import PluginAssetManager
from core.plugin.impl.model import PluginModelClient
logger = logging.getLogger(__name__)
@@ -40,7 +40,7 @@ class ModelProviderFactory:
self.provider_position_map = {}
self.tenant_id = tenant_id
self.plugin_model_manager = PluginModelManager()
self.plugin_model_manager = PluginModelClient()
if not self.provider_position_map:
# get the path of current classes