Feat: tenant llm provider (#14595)

### What problem does this PR solve?

Python implementation of the Go-based model_provider API suite.

### Type of change

- [x] New Feature (non-breaking change which adds functionality)

---------

Co-authored-by: bill <yibie_jingnian@163.com>
This commit is contained in:
Lynn
2026-05-29 17:39:41 +08:00
committed by GitHub
parent b79f79d9b9
commit dc4b82523b
148 changed files with 6059 additions and 3075 deletions

View File

@@ -120,9 +120,8 @@ def _load_dify_retrieval(monkeypatch, *, kb, accessible, request_body, chunks=No
_stub(
monkeypatch,
"api.db.joint_services.tenant_model_service",
get_model_config_by_id=lambda *_a, **_k: {},
get_model_config_by_type_and_name=lambda *_a, **_k: {},
get_tenant_default_model_by_type=lambda *_a, **_k: {},
get_model_config_from_provider_instance=lambda *_a, **_k: {},
)
_stub(

View File

@@ -203,7 +203,7 @@ def test_async_ask_final_event_carries_decorated_answer(monkeypatch):
dialog_service.KnowledgebaseService, "get_by_ids", lambda _ids: [_KB]
)
monkeypatch.setattr(
dialog_service, "get_model_config_by_type_and_name",
dialog_service, "get_model_config_from_provider_instance",
lambda _tid, _type, _name: _LLM_CONFIG,
)
monkeypatch.setattr(dialog_service, "LLMBundle", lambda _tid, _cfg: chat_mdl)
@@ -257,7 +257,7 @@ def test_async_ask_delta_events_carry_incremental_text_only(monkeypatch):
dialog_service.KnowledgebaseService, "get_by_ids", lambda _ids: [_KB]
)
monkeypatch.setattr(
dialog_service, "get_model_config_by_type_and_name",
dialog_service, "get_model_config_from_provider_instance",
lambda _tid, _type, _name: _LLM_CONFIG,
)
monkeypatch.setattr(dialog_service, "LLMBundle", lambda _tid, _cfg: chat_mdl)
@@ -345,10 +345,11 @@ def test_async_chat_final_event_carries_decorated_answer(monkeypatch):
# Stub out the heavy service/model calls
monkeypatch.setattr(
dialog_service.TenantLLMService, "llm_id2llm_type", lambda _llm_id: "chat"
dialog_service, "get_model_type_by_name",
lambda _tid, _llm_id: ["chat"]
)
monkeypatch.setattr(
dialog_service.TenantLLMService, "get_model_config",
dialog_service, "get_model_config_from_provider_instance",
lambda _tid, _type, _llm_id: _LLM_CONFIG,
)
monkeypatch.setattr(
@@ -406,10 +407,11 @@ def test_async_chat_langfuse_uses_start_observation(monkeypatch):
retriever = _StubRetriever()
monkeypatch.setattr(
dialog_service.TenantLLMService, "llm_id2llm_type", lambda _llm_id: "chat"
dialog_service, "get_model_type_by_name",
lambda _tid, _llm_id: ["chat"]
)
monkeypatch.setattr(
dialog_service.TenantLLMService, "get_model_config",
dialog_service, "get_model_config_from_provider_instance",
lambda _tid, _type, _llm_id: _LLM_CONFIG,
)
monkeypatch.setattr(
@@ -475,10 +477,11 @@ def test_async_chat_continues_when_langfuse_observation_start_fails(monkeypatch)
retriever = _StubRetriever()
monkeypatch.setattr(
dialog_service.TenantLLMService, "llm_id2llm_type", lambda _llm_id: "chat"
dialog_service, "get_model_type_by_name",
lambda _tid, _llm_id: ["chat"]
)
monkeypatch.setattr(
dialog_service.TenantLLMService, "get_model_config",
dialog_service, "get_model_config_from_provider_instance",
lambda _tid, _type, _llm_id: _LLM_CONFIG,
)
monkeypatch.setattr(

View File

@@ -282,11 +282,14 @@ def test_async_chat_uses_all_docs_when_no_doc_ids_selected(monkeypatch):
)
monkeypatch.setattr(dialog_service.settings, "retriever", retriever, raising=False)
monkeypatch.setattr(dialog_service.TenantLLMService, "llm_id2llm_type", lambda _llm_id: "chat")
monkeypatch.setattr(
dialog_service.TenantLLMService,
"get_model_config",
lambda *_args, **_kwargs: {"llm_factory": "unit", "max_tokens": 4096},
dialog_service, "get_model_type_by_name",
lambda _tid, _llm_id: ["chat"]
)
monkeypatch.setattr(
dialog_service,
"get_model_config_from_provider_instance",
lambda *_args, **_kwargs: {"llm_factory": "unit", "max_tokens": 4096, "model_type": "chat"},
)
monkeypatch.setattr(dialog_service.TenantLangfuseService, "filter_by_tenant", lambda **_kwargs: None)
monkeypatch.setattr(