mirror of
https://github.com/langgenius/dify.git
synced 2026-05-03 08:58:09 +08:00
refactor: remove protocol in core.app.llm
Signed-off-by: -LAN- <laipz8200@outlook.com>
This commit is contained in:
@ -3,7 +3,6 @@ from __future__ import annotations
|
||||
from typing import Any
|
||||
|
||||
from core.app.entities.app_invoke_entities import DifyRunContext, ModelConfigWithCredentialsEntity
|
||||
from core.app.llm.protocols import CredentialsProvider, ModelFactory
|
||||
from core.errors.error import ProviderTokenNotInitError
|
||||
from core.model_manager import ModelInstance, ModelManager
|
||||
from core.plugin.impl.model_runtime_factory import create_plugin_provider_manager
|
||||
@ -11,6 +10,7 @@ from core.provider_manager import ProviderManager
|
||||
from dify_graph.model_runtime.entities.model_entities import ModelType
|
||||
from dify_graph.nodes.llm.entities import ModelConfig
|
||||
from dify_graph.nodes.llm.exc import LLMModeRequiredError, ModelNotExistError
|
||||
from dify_graph.nodes.llm.protocols import CredentialsProvider
|
||||
|
||||
|
||||
class DifyCredentialsProvider:
|
||||
@ -78,7 +78,7 @@ class DifyModelFactory:
|
||||
)
|
||||
|
||||
|
||||
def build_dify_model_access(run_context: DifyRunContext) -> tuple[CredentialsProvider, ModelFactory]:
|
||||
def build_dify_model_access(run_context: DifyRunContext) -> tuple[CredentialsProvider, DifyModelFactory]:
|
||||
"""Create LLM access adapters that share the same tenant-bound manager graph."""
|
||||
provider_manager = create_plugin_provider_manager(
|
||||
tenant_id=run_context.tenant_id,
|
||||
@ -113,7 +113,7 @@ def fetch_model_config(
|
||||
*,
|
||||
node_data_model: ModelConfig,
|
||||
credentials_provider: CredentialsProvider,
|
||||
model_factory: ModelFactory,
|
||||
model_factory: DifyModelFactory,
|
||||
) -> tuple[ModelInstance, ModelConfigWithCredentialsEntity]:
|
||||
if not node_data_model.mode:
|
||||
raise LLMModeRequiredError("LLM mode is required.")
|
||||
|
||||
@ -1,21 +0,0 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Protocol
|
||||
|
||||
from core.model_manager import ModelInstance
|
||||
|
||||
|
||||
class CredentialsProvider(Protocol):
|
||||
"""Workflow-layer port for loading runtime credentials for a provider/model pair."""
|
||||
|
||||
def fetch(self, provider_name: str, model_name: str) -> dict[str, Any]:
|
||||
"""Return credentials for the target provider/model or raise a domain error."""
|
||||
...
|
||||
|
||||
|
||||
class ModelFactory(Protocol):
|
||||
"""Workflow-layer port for creating mutable ModelInstance objects."""
|
||||
|
||||
def init_model_instance(self, provider_name: str, model_name: str) -> ModelInstance:
|
||||
"""Create a model instance that is ready for workflow-side hydration."""
|
||||
...
|
||||
@ -193,7 +193,7 @@ def model_config(monkeypatch):
|
||||
|
||||
def test_fetch_model_config_hydrates_model_instance_runtime_settings(model_config: ModelConfigWithCredentialsEntity):
|
||||
mock_credentials_provider = mock.MagicMock(spec=CredentialsProvider)
|
||||
mock_model_factory = mock.MagicMock(spec=ModelFactory)
|
||||
mock_model_factory = mock.MagicMock(spec=DifyModelFactory)
|
||||
|
||||
provider_model_bundle = model_config.provider_model_bundle
|
||||
model_type_instance = provider_model_bundle.model_type_instance
|
||||
|
||||
Reference in New Issue
Block a user