Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Fix: kimi k3 temperature (#18564)

Lynnb8b35aa9abd1
diff --git a/api/apps/restful_apis/_generation_params.py b/api/apps/restful_apis/_generation_params.py
index 50f0f7582f..e5fa79c2bf 100644
--- a/api/apps/restful_apis/_generation_params.py
+++ b/api/apps/restful_apis/_generation_params.py
@@ -18,48 +18,6 @@ from copy import deepcopy
GENERATION_CONFIG_KEYS = ("temperature", "top_p", "frequency_penalty", "presence_penalty", "max_tokens")
-# Default values for the four LLM generation parameters stored in
-# search_config.llm_setting. When the corresponding ``_enabled`` flag is
-# ``False`` (or the key is absent), the default is used instead of whatever
-# the user may have stored in ``llm_setting``.
-LLM_SETTING_DEFAULTS = {
- "temperature": 0.1,
- "top_p": 0.3,
- "frequency_penalty": 0.7,
- "presence_penalty": 0.4,
-}
-
-
-def resolve_llm_setting(llm_setting):
- """Resolve *llm_setting* values according to their enable flags.
-
- For each of the four generation parameters the dictionary may carry a
- ``{key}_enabled`` boolean. When the flag is ``True`` and the value
- exists in *llm_setting*, the user-configured value is kept; otherwise
- the default from :data:`LLM_SETTING_DEFAULTS` is substituted.
-
- Keys whose name ends with ``_enabled`` are stripped from the result so
- they are never forwarded to the downstream LLM call.
- """
- if not llm_setting:
- return dict(LLM_SETTING_DEFAULTS)
-
- resolved = {}
- for key, default_val in LLM_SETTING_DEFAULTS.items():
- enabled_key = f"{key}_enabled"
- if llm_setting.get(enabled_key, True) and key in llm_setting:
- resolved[key] = llm_setting[key]
- else:
- resolved[key] = default_val
-
- # Carry over any extra keys that are not generation parameters and not
- # enable flags (e.g. ``llm_id``, ``model_type``).
- for key, val in llm_setting.items():
- if key not in resolved and not key.endswith("_enabled"):
- resolved[key] = val
-
- return resolved
-
def extract_generation_config(req):
return {key: req[key] for key in GENERATION_CONFIG_KEYS if key in req and req[key] is not None}
diff --git a/api/apps/restful_apis/bot_api.py b/api/apps/restful_apis/bot_api.py
index c16e3d6ca7..16ef203b4e 100644
--- a/api/apps/restful_apis/bot_api.py
+++ b/api/apps/restful_apis/bot_api.py
@@ -36,7 +36,7 @@ from common.metadata_utils import apply_meta_data_filter
from api.db.services.search_service import SearchService
from api.db.services.user_service import UserTenantService
from api.db.joint_services.tenant_model_service import get_tenant_default_model_by_type, resolve_model_config
-from api.apps.restful_apis._generation_params import resolve_llm_setting
+from api.db.services.llm_service import resolve_llm_setting
from common.misc_utils import thread_pool_exec
from api.utils.api_utils import get_error_data_result, get_json_result, add_tenant_id_to_kwargs, get_result, get_request_json, server_error_response, validate_request
from rag.app.tag import label_question
diff --git a/api/apps/restful_apis/chat_api.py b/api/apps/restful_apis/chat_api.py
index cb2643d8bd..e3ba9cfd54 100644
--- a/api/apps/restful_apis/chat_api.py
+++ b/api/apps/restful_apis/chat_api.py
@@ -27,7 +27,8 @@ from quart import Response, request
from werkzeug.exceptions import BadRequest
from api.apps import current_user, login_required
-from api.apps.restful_apis._generation_params import merge_generation_config, pop_generation_config, resolve_llm_setting
+from api.apps.restful_apis._generation_params import merge_generation_config, pop_generation_config
+from api.db.services.llm_service import resolve_llm_setting
from api.db.joint_services.tenant_model_service import (
get_api_key,
get_composite_model_name_by_id,
diff --git a/api/apps/services/provider_api_service.py b/api/apps/services/provider_api_service.py
index dc5f38357b..4fd476a130 100644
--- a/api/apps/services/provider_api_service.py
+++ b/api/apps/services/provider_api_service.py
@@ -1288,6 +1288,9 @@ def update_model(tenant_id: str, provider_id_or_name: str, instance_id_or_name:
return False, f"No instance found for provider '{provider_id_or_name}' and instance '{instance_id_or_name}'"
model_obj = TenantModelService.get_by_provider_id_and_instance_id_and_model_name(provider_obj.id, instance_obj.id, model_name)
+ if not model_obj:
+ return False, f"Model '{model_name}' not added for provider '{provider_id_or_name}' and instance '{instance_id_or_name}'"
+
to_update = {}
if "status" in update_dict and update_dict.get("status") != model_obj.status:
to_update.update({"status": update_dict["status"]})
diff --git a/api/db/services/dialog_service.py b/api/db/services/dialog_service.py
index cccd19f752..5058f155fa 100644
--- a/api/db/services/dialog_service.py
+++ b/api/db/services/dialog_service.py
@@ -35,7 +35,7 @@ from api.db.services.common_service import CommonService
from api.db.services.doc_metadata_service import DocMetadataService
from api.db.services.knowledgebase_service import KnowledgebaseService, validate_dataset_embedding_models
from api.db.services.langfuse_service import TenantLangfuseService
-from api.db.services.llm_service import LLMBundle
+from api.db.services.llm_service import LLMBundle, resolve_llm_setting
from common.metadata_utils import apply_meta_data_filter
from api.utils.reference_metadata_utils import (
enrich_chunks_with_document_metadata,
@@ -1859,7 +1859,10 @@ async def async_ask(question, kb_ids, tenant_id, chat_llm_name=None, search_conf
refs["chunks"] = chunks_format(refs)
return {"answer": answer, "reference": refs}
- stream_iter = chat_mdl.async_chat_streamly_delta(sys_prompt, msg, {"temperature": 0.1})
+ gen_conf = resolve_llm_setting(search_config.get("llm_setting"))
+ if "parameter" in gen_conf:
+ del gen_conf["parameter"]
+ stream_iter = chat_mdl.async_chat_streamly_delta(sys_prompt, msg, gen_conf)
last_state = None
async for kind, value, state in _stream_with_think_delta(stream_iter):
last_state = state
diff --git a/api/db/services/llm_service.py b/api/db/services/llm_service.py
index 9537e260da..653f512940 100644
--- a/api/db/services/llm_service.py
+++ b/api/db/services/llm_service.py
@@ -29,6 +29,48 @@ from api.db.services.common_service import CommonService
from api.db.services.tenant_llm_service import LLM4Tenant
from common.token_utils import langfuse_run_attrs, num_tokens_from_string, record_run_token_usage, truncate
+# Default values for the four LLM generation parameters stored in
+# search_config.llm_setting. When the corresponding ``_enabled`` flag is
+# ``False`` (or the key is absent), the default is used instead of whatever
+# the user may have stored in ``llm_setting``.
+LLM_SETTING_DEFAULTS = {
+ "temperature": 0.1,
+ "top_p": 0.3,
+ "frequency_penalty": 0.7,
+ "presence_penalty": 0.4,
+}
+
+
+def resolve_llm_setting(llm_setting):
+ """Resolve *llm_setting* values according to their enable flags.
+
+ For each of the four generation parameters the dictionary may carry a
+ ``{key}_enabled`` boolean. When the flag is ``True`` and the value
+ exists in *llm_setting*, the user-configured value is kept; otherwise
+ the default from :data:`LLM_SETTING_DEFAULTS` is substituted.
+
+ Keys whose name ends with ``_enabled`` are stripped from the result so
+ they are never forwarded to the downstream LLM call.
+ """
+ if not llm_setting:
+ return dict(LLM_SETTING_DEFAULTS)
+
+ resolved = {}
+ for key, default_val in LLM_SETTING_DEFAULTS.items():
+ enabled_key = f"{key}_enabled"
+ if llm_setting.get(enabled_key, True) and key in llm_setting:
+ resolved[key] = llm_setting[key]
+ else:
+ resolved[key] = default_val
+
+ # Carry over any extra keys that are not generation parameters and not
+ # enable flags (e.g. ``llm_id``, ``model_type``).
+ for key, val in llm_setting.items():
+ if key not in resolved and not key.endswith("_enabled"):
+ resolved[key] = val
+
+ return resolved
+
class LLMService(CommonService):
model = LLM
diff --git a/test/testcases/restful_api/test_chats.py b/test/testcases/restful_api/test_chats.py
index b058816f4a..701eda4fc8 100644
--- a/test/testcases/restful_api/test_chats.py
+++ b/test/testcases/restful_api/test_chats.py
@@ -757,6 +757,7 @@ def _load_chat_routes_unit_module(monkeypatch):
llm_service_mod = ModuleType("api.db.services.llm_service")
llm_service_mod.LLMBundle = lambda *_args, **_kwargs: None
+ llm_service_mod.resolve_llm_setting = lambda *_args, **_kwargs: {}
monkeypatch.setitem(sys.modules, "api.db.services.llm_service", llm_service_mod)
search_service_mod = ModuleType("api.db.services.search_service")
diff --git a/test/testcases/restful_api/test_dify_retrieval_routes_unit.py b/test/testcases/restful_api/test_dify_retrieval_routes_unit.py
index fe6c4148aa..9a7e02f30b 100644
--- a/test/testcases/restful_api/test_dify_retrieval_routes_unit.py
+++ b/test/testcases/restful_api/test_dify_retrieval_routes_unit.py
@@ -172,6 +172,7 @@ def _load_dify_retrieval_module(monkeypatch):
llm_service_mod.LLMService = SimpleNamespace(query=lambda llm_name: [_StubLLM(llm_name)] if llm_name else [])
llm_service_mod.LLMBundle = _StubLLMBundle
+ llm_service_mod.resolve_llm_setting = lambda *_args, **_kwargs: {}
monkeypatch.setitem(sys.modules, "api.db.services.llm_service", llm_service_mod)
# 4. api.utils.api_utils
diff --git a/test/testcases/restful_api/test_user_tenant_routes_unit.py b/test/testcases/restful_api/test_user_tenant_routes_unit.py
index f95b84ea71..1832bf45f5 100644
--- a/test/testcases/restful_api/test_user_tenant_routes_unit.py
+++ b/test/testcases/restful_api/test_user_tenant_routes_unit.py
@@ -486,6 +486,7 @@ def _load_user_app(monkeypatch):
llm_service_mod = ModuleType("api.db.services.llm_service")
llm_service_mod.get_init_tenant_llm = lambda _user_id: []
+ llm_service_mod.resolve_llm_setting = lambda *_args, **_kwargs: {}
monkeypatch.setitem(sys.modules, "api.db.services.llm_service", llm_service_mod)
tenant_llm_service_mod = ModuleType("api.db.services.tenant_llm_service")
@@ -1530,6 +1531,7 @@ def _load_chat_routes_unit_module(monkeypatch):
llm_service_mod = ModuleType("api.db.services.llm_service")
llm_service_mod.LLMBundle = lambda *_args, **_kwargs: None
+ llm_service_mod.resolve_llm_setting = lambda *_args, **_kwargs: {}
monkeypatch.setitem(sys.modules, "api.db.services.llm_service", llm_service_mod)
search_service_mod = ModuleType("api.db.services.search_service")
diff --git a/test/testcases/test_http_api/test_chat_assistant_management/test_chat_sdk_routes_unit.py b/test/testcases/test_http_api/test_chat_assistant_management/test_chat_sdk_routes_unit.py
index 639e2abcea..78a067bf69 100644
--- a/test/testcases/test_http_api/test_chat_assistant_management/test_chat_sdk_routes_unit.py
+++ b/test/testcases/test_http_api/test_chat_assistant_management/test_chat_sdk_routes_unit.py
@@ -360,6 +360,7 @@ def _load_chat_module(monkeypatch):
pass
llm_service_mod.LLMBundle = _StubLLMBundle
+ llm_service_mod.resolve_llm_setting = lambda *_args, **_kwargs: {}
monkeypatch.setitem(sys.modules, "api.db.services.llm_service", llm_service_mod)
search_service_mod = ModuleType("api.db.services.search_service")
diff --git a/test/testcases/test_http_api/test_dataset_management/test_dify_retrieval_routes_unit.py b/test/testcases/test_http_api/test_dataset_management/test_dify_retrieval_routes_unit.py
index 92a00e1afd..ada3f86d23 100644
--- a/test/testcases/test_http_api/test_dataset_management/test_dify_retrieval_routes_unit.py
+++ b/test/testcases/test_http_api/test_dataset_management/test_dify_retrieval_routes_unit.py
@@ -231,6 +231,7 @@ def _load_dify_retrieval_module(monkeypatch):
llm_service_mod.LLMService = SimpleNamespace(query=lambda llm_name: [_StubLLM(llm_name)] if llm_name else [])
llm_service_mod.LLMBundle = _StubLLMBundle
+ llm_service_mod.resolve_llm_setting = lambda *_args, **_kwargs: {}
monkeypatch.setitem(sys.modules, "api.db.services.llm_service", llm_service_mod)
# 4. api.utils.api_utils
diff --git a/test/testcases/test_http_api/test_file_management_within_dataset/test_doc_sdk_routes_unit.py b/test/testcases/test_http_api/test_file_management_within_dataset/test_doc_sdk_routes_unit.py
index 4430a50793..16fde92230 100644
--- a/test/testcases/test_http_api/test_file_management_within_dataset/test_doc_sdk_routes_unit.py
+++ b/test/testcases/test_http_api/test_file_management_within_dataset/test_doc_sdk_routes_unit.py
@@ -499,6 +499,7 @@ def _load_doc_module(monkeypatch, module_basename="chunk_api"):
llm_service_mod.LLMService = SimpleNamespace(query=lambda llm_name: [_StubLLM(llm_name)] if llm_name else [])
llm_service_mod.LLMBundle = _StubLLMBundle
+ llm_service_mod.resolve_llm_setting = lambda *_args, **_kwargs: {}
monkeypatch.setitem(sys.modules, "api.db.services.llm_service", llm_service_mod)
# Mock tenant_model_service to ensure it uses mocked services
diff --git a/test/testcases/test_http_api/test_session_management/test_session_sdk_routes_unit.py b/test/testcases/test_http_api/test_session_management/test_session_sdk_routes_unit.py
index b8dd422dd4..70021acca6 100644
--- a/test/testcases/test_http_api/test_session_management/test_session_sdk_routes_unit.py
+++ b/test/testcases/test_http_api/test_session_management/test_session_sdk_routes_unit.py
@@ -422,6 +422,7 @@ def _load_session_module(monkeypatch):
return "mock transcription"
llm_service_mod.LLMBundle = _StubLLMBundle
+ llm_service_mod.resolve_llm_setting = lambda *_args, **_kwargs: {}
monkeypatch.setitem(sys.modules, "api.db.services.llm_service", llm_service_mod)
# Mock tenant_model_service to ensure it uses mocked services
@@ -569,6 +570,13 @@ def _load_session_module(monkeypatch):
quart_mod.websocket = SimpleNamespace()
monkeypatch.setitem(sys.modules, "quart", quart_mod)
+ api_apps_mod = ModuleType("api.apps")
+ api_apps_mod.__path__ = [str(repo_root / "api" / "apps")]
+ api_apps_mod.AUTH_BETA = False
+ api_apps_mod.current_user = SimpleNamespace(id="tenant-1")
+ api_apps_mod.login_required = lambda func: func
+ monkeypatch.setitem(sys.modules, "api.apps", api_apps_mod)
+
quart_auth_mod = ModuleType("quart_auth")
class _StubAuthUser:
@@ -2298,7 +2306,10 @@ def _load_chat_api_module(monkeypatch):
tenant_model_svc = ModuleType("api.db.joint_services.tenant_model_service")
tenant_model_svc.get_tenant_default_model_by_type = lambda *_a, **_k: {}
tenant_model_svc.get_model_config_from_provider_instance = lambda **_k: {}
+ tenant_model_svc.get_model_config_by_id = lambda **_k: {}
tenant_model_svc.resolve_model_config = lambda **_k: {}
+ tenant_model_svc.resolve_model_id = lambda *_a, **_k: "model-id"
+ tenant_model_svc.get_composite_model_name_by_id = lambda *_a, **_k: "composite-model-name"
tenant_model_svc.get_api_key = lambda **_k: "fake-api-key"
tenant_model_svc.split_model_name = lambda model_name: (model_name, "", "")
monkeypatch.setitem(sys.modules, "api.db.joint_services.tenant_model_service", tenant_model_svc)
@@ -2353,6 +2364,7 @@ def _load_chat_api_module(monkeypatch):
)
dialog_svc_mod.async_chat = lambda *_a, **_k: None
dialog_svc_mod.gen_mindmap = lambda *_a, **_k: None
+ dialog_svc_mod.rag_agent = lambda *_a, **_k: None
monkeypatch.setitem(sys.modules, "api.db.services.dialog_service", dialog_svc_mod)
kb_svc_mod = ModuleType("api.db.services.knowledgebase_service")
@@ -2366,6 +2378,7 @@ def _load_chat_api_module(monkeypatch):
llm_svc_mod = ModuleType("api.db.services.llm_service")
llm_svc_mod.LLMBundle = _FakeLLMBundle
+ llm_svc_mod.resolve_llm_setting = lambda *_args, **_kwargs: {}
monkeypatch.setitem(sys.modules, "api.db.services.llm_service", llm_svc_mod)
search_svc_mod = ModuleType("api.db.services.search_service")
diff --git a/test/testcases/test_web_api/test_canvas_app/test_iteration_runtime_unit.py b/test/testcases/test_web_api/test_canvas_app/test_iteration_runtime_unit.py
index 8f3c90585e..4ba1ea0371 100644
--- a/test/testcases/test_web_api/test_canvas_app/test_iteration_runtime_unit.py
+++ b/test/testcases/test_web_api/test_canvas_app/test_iteration_runtime_unit.py
@@ -88,6 +88,7 @@ def _load_canvas_runtime(monkeypatch):
llm_service = ModuleType("api.db.services.llm_service")
llm_service.LLMBundle = object
+ llm_service.resolve_llm_setting = lambda *_args, **_kwargs: {}
monkeypatch.setitem(sys.modules, "api.db.services.llm_service", llm_service)
task_service = ModuleType("api.db.services.task_service")
diff --git a/test/testcases/test_web_api/test_chunk_app/test_chunk_routes_unit.py b/test/testcases/test_web_api/test_chunk_app/test_chunk_routes_unit.py
index 194bbb6259..7ecbbd32a9 100644
--- a/test/testcases/test_web_api/test_chunk_app/test_chunk_routes_unit.py
+++ b/test/testcases/test_web_api/test_chunk_app/test_chunk_routes_unit.py
@@ -508,6 +508,7 @@ def _load_chunk_module(monkeypatch):
llm_service_mod = ModuleType("api.db.services.llm_service")
llm_service_mod.LLMService = _DummyLLMService
llm_service_mod.LLMBundle = _DummyLLMBundle
+ llm_service_mod.resolve_llm_setting = lambda *_args, **_kwargs: {}
monkeypatch.setitem(sys.modules, "api.db.services.llm_service", llm_service_mod)
services_pkg.llm_service = llm_service_mod
diff --git a/test/testcases/test_web_api/test_llm_app/test_llm_list_unit.py b/test/testcases/test_web_api/test_llm_app/test_llm_list_unit.py
index e9ca796dab..386188c648 100644
--- a/test/testcases/test_web_api/test_llm_app/test_llm_list_unit.py
+++ b/test/testcases/test_web_api/test_llm_app/test_llm_list_unit.py
@@ -190,6 +190,7 @@ def _load_llm_app(monkeypatch):
return []
llm_service_mod.LLMService = _StubLLMService
+ llm_service_mod.resolve_llm_setting = lambda *_args, **_kwargs: {}
monkeypatch.setitem(sys.modules, "api.db.services.llm_service", llm_service_mod)
api_utils_mod = ModuleType("api.utils.api_utils")
diff --git a/test/testcases/test_web_api/test_user_app/test_user_app_unit.py b/test/testcases/test_web_api/test_user_app/test_user_app_unit.py
index 778893c045..6843a6478d 100644
--- a/test/testcases/test_web_api/test_user_app/test_user_app_unit.py
+++ b/test/testcases/test_web_api/test_user_app/test_user_app_unit.py
@@ -210,6 +210,7 @@ def _load_user_app(monkeypatch):
llm_service_mod = ModuleType("api.db.services.llm_service")
llm_service_mod.get_init_tenant_llm = lambda _user_id: []
+ llm_service_mod.resolve_llm_setting = lambda *_args, **_kwargs: {}
monkeypatch.setitem(sys.modules, "api.db.services.llm_service", llm_service_mod)
tenant_llm_service_mod = ModuleType("api.db.services.tenant_llm_service")
diff --git a/test/unit_test/agent/test_canvas_at_split.py b/test/unit_test/agent/test_canvas_at_split.py
index 1666202eca..d23a86644a 100644
--- a/test/unit_test/agent/test_canvas_at_split.py
+++ b/test/unit_test/agent/test_canvas_at_split.py
@@ -35,7 +35,7 @@ from __future__ import annotations
import importlib.util
import sys
from pathlib import Path
-from types import ModuleType, SimpleNamespace
+from types import ModuleType
from unittest.mock import MagicMock
import pytest
@@ -125,7 +125,11 @@ def _load_canvas_module(monkeypatch):
# `api.*` services imported at the top of canvas.py
_stub_module("api.db.services.file_service", FileService=MagicMock())
- _stub_module("api.db.services.llm_service", LLMBundle=MagicMock())
+ _stub_module(
+ "api.db.services.llm_service",
+ LLMBundle=MagicMock(),
+ resolve_llm_setting=lambda *_args, **_kwargs: {},
+ )
_stub_module("api.db.services.task_service", has_canceled=MagicMock(return_value=False))
_stub_module(
"api.db.joint_services.tenant_model_service",
diff --git a/test/unit_test/api/apps/restful_apis/test_agentbots_access_control.py b/test/unit_test/api/apps/restful_apis/test_agentbots_access_control.py
index 93cd6e6371..510be1ae21 100644
--- a/test/unit_test/api/apps/restful_apis/test_agentbots_access_control.py
+++ b/test/unit_test/api/apps/restful_apis/test_agentbots_access_control.py
@@ -73,7 +73,6 @@ def _load_bot_api(monkeypatch, *, accessible, calls):
_stub(monkeypatch, "quart", Response=lambda *a, **k: SimpleNamespace(headers=SimpleNamespace(add_header=lambda *aa, **kk: None)), request=SimpleNamespace())
_stub(monkeypatch, "api.apps", AUTH_BETA="beta", login_required=lambda *_a, **_k: lambda func: func, __path__=[])
_stub(monkeypatch, "api.apps.restful_apis", __path__=[])
- _stub(monkeypatch, "api.apps.restful_apis._generation_params", resolve_llm_setting=lambda s: s or {"temperature": 0.1, "top_p": 0.3, "frequency_penalty": 0.7, "presence_penalty": 0.4})
_stub(monkeypatch, "agent.canvas", Canvas=lambda *a, **k: SimpleNamespace(get_component_input_form=lambda _n: {}, get_prologue=lambda: "", get_mode=lambda: "agent"))
_stub(monkeypatch, "api.db.db_models", APIToken=SimpleNamespace(query=lambda **_k: [SimpleNamespace(tenant_id="attacker-tenant")]))
_stub(monkeypatch, "api.db.services.api_service", API4ConversationService=SimpleNamespace())
@@ -83,7 +82,12 @@ def _load_bot_api(monkeypatch, *, accessible, calls):
_stub(monkeypatch, "api.db.services.dialog_service", DialogService=SimpleNamespace(), async_ask=lambda *_a, **_k: None, gen_mindmap=lambda *_a, **_k: None)
_stub(monkeypatch, "api.db.services.doc_metadata_service", DocMetadataService=SimpleNamespace())
_stub(monkeypatch, "api.db.services.knowledgebase_service", KnowledgebaseService=SimpleNamespace())
- _stub(monkeypatch, "api.db.services.llm_service", LLMBundle=SimpleNamespace())
+ _stub(
+ monkeypatch,
+ "api.db.services.llm_service",
+ LLMBundle=SimpleNamespace(),
+ resolve_llm_setting=lambda s: s or {"temperature": 0.1, "top_p": 0.3, "frequency_penalty": 0.7, "presence_penalty": 0.4},
+ )
_stub(monkeypatch, "common.metadata_utils", apply_meta_data_filter=lambda *_a, **_k: None)
_stub(monkeypatch, "api.db.services.search_service", SearchService=SimpleNamespace())
_stub(
diff --git a/test/unit_test/api/apps/sdk/test_dify_retrieval.py b/test/unit_test/api/apps/sdk/test_dify_retrieval.py
index 3a9727f6c6..358d65fe2f 100644
--- a/test/unit_test/api/apps/sdk/test_dify_retrieval.py
+++ b/test/unit_test/api/apps/sdk/test_dify_retrieval.py
@@ -155,7 +155,12 @@ def _load_dify_retrieval(
KnowledgebaseService=SimpleNamespace(get_by_id=lambda _id: kb, accessible=acc_fn),
)
- _stub(monkeypatch, "api.db.services.llm_service", LLMBundle=lambda *_a, **_k: SimpleNamespace())
+ _stub(
+ monkeypatch,
+ "api.db.services.llm_service",
+ LLMBundle=lambda *_a, **_k: SimpleNamespace(),
+ resolve_llm_setting=lambda *_a, **_k: {},
+ )
_stub(
monkeypatch,
diff --git a/test/unit_test/api/apps/services/test_gaussdb_dataset_embedding.py b/test/unit_test/api/apps/services/test_gaussdb_dataset_embedding.py
index 4aca9efce5..21cc664ad1 100644
--- a/test/unit_test/api/apps/services/test_gaussdb_dataset_embedding.py
+++ b/test/unit_test/api/apps/services/test_gaussdb_dataset_embedding.py
@@ -186,7 +186,12 @@ def _load_dataset_module(monkeypatch):
def test_tc_wrt_206_check_embedding_ignores_gaussdb_invalid_placeholder_vectors(monkeypatch):
module = _load_dataset_module(monkeypatch)
- _install_module(monkeypatch, "api.db.services.llm_service", LLMBundle=FailIfCalledBundle)
+ _install_module(
+ monkeypatch,
+ "api.db.services.llm_service",
+ LLMBundle=FailIfCalledBundle,
+ resolve_llm_setting=lambda *_args, **_kwargs: {},
+ )
ok, result = module.check_embedding("kb1", "tenant1", {"embd_id": "new-embd", "check_num": 1})
@@ -198,7 +203,12 @@ def test_tc_wrt_207_check_embedding_compares_gaussdb_valid_vectors_once(monkeypa
module = _load_dataset_module(monkeypatch)
module.settings.docStoreConn = ValidVectorGaussDBStore()
CompatibleEmbeddingBundle.encode_calls.clear()
- _install_module(monkeypatch, "api.db.services.llm_service", LLMBundle=CompatibleEmbeddingBundle)
+ _install_module(
+ monkeypatch,
+ "api.db.services.llm_service",
+ LLMBundle=CompatibleEmbeddingBundle,
+ resolve_llm_setting=lambda *_args, **_kwargs: {},
+ )
ok, result = module.check_embedding("kb1", "tenant1", {"embd_id": "new-embd", "check_num": 1})
diff --git a/test/unit_test/api/db/services/test_dialog_service_final_answer.py b/test/unit_test/api/db/services/test_dialog_service_final_answer.py
index 33218622ec..466746029d 100644
--- a/test/unit_test/api/db/services/test_dialog_service_final_answer.py
+++ b/test/unit_test/api/db/services/test_dialog_service_final_answer.py
@@ -346,6 +346,91 @@ def test_async_ask_stale_kb_ids_yields_error_final_event(monkeypatch):
assert events[0]["reference"] == {}
+class _RecordingChatModel(_StreamingChatModel):
+ """Records the gen_conf handed to async_chat_streamly_delta."""
+
+ def __init__(self, answer: str = "Answer"):
+ super().__init__(answer)
+ self.gen_conf = None
+
+ async def async_chat_streamly_delta(self, system_prompt, messages, gen_conf, **_kwargs):
+ self.gen_conf = dict(gen_conf)
+ yield self.answer
+
+
+def _drive_async_ask_with_config(monkeypatch, search_config):
+ chat_mdl = _RecordingChatModel()
+ retriever = _StubRetriever()
+ monkeypatch.setattr(dialog_service.KnowledgebaseService, "get_by_ids", lambda _ids: [_KB])
+ monkeypatch.setattr(
+ dialog_service,
+ "resolve_model_config",
+ lambda _tid, _type, _name: _LLM_CONFIG,
+ )
+ monkeypatch.setattr(dialog_service, "LLMBundle", lambda _tid, _cfg: chat_mdl)
+ monkeypatch.setattr(dialog_service.settings, "retriever", retriever, raising=False)
+ monkeypatch.setattr(dialog_service.settings, "kg_retriever", retriever, raising=False)
+ monkeypatch.setattr(dialog_service.DocMetadataService, "get_flatted_meta_by_kbs", lambda _ids: {})
+ monkeypatch.setattr(dialog_service, "label_question", lambda _q, _kbs: "")
+ monkeypatch.setattr(
+ dialog_service,
+ "kb_prompt",
+ lambda _kbinfos, _max_tokens, **_kw: ["RAGFlow is a RAG engine."],
+ )
+
+ events = _collect(
+ dialog_service.async_ask(
+ question="What is RAGFlow?",
+ kb_ids=["kb-1"],
+ tenant_id="tenant-1",
+ search_config=search_config,
+ )
+ )
+ assert events, "async_ask must yield at least one event"
+ return chat_mdl
+
+
+def test_async_ask_forwards_llm_setting_temperature(monkeypatch):
+ """AI summary must honor the temperature configured in search_config.llm_setting."""
+ chat_mdl = _drive_async_ask_with_config(
+ monkeypatch,
+ search_config={
+ "llm_setting": {
+ "temperature": 1.0,
+ "temperature_enabled": True,
+ "top_p": 0.3,
+ "top_p_enabled": False,
+ "frequency_penalty": 0.7,
+ "frequency_penalty_enabled": False,
+ "presence_penalty": 0.4,
+ "presence_penalty_enabled": False,
+ }
+ },
+ )
+
+ assert chat_mdl.gen_conf is not None, "model must be invoked with a gen_conf"
+ assert chat_mdl.gen_conf["temperature"] == 1.0
+ assert not any(k.endswith("_enabled") for k in chat_mdl.gen_conf), "enable flags must not reach the model"
+
+
+def test_async_ask_falls_back_to_default_temperature_when_disabled(monkeypatch):
+ """Disabled temperature falls back to the LLM_SETTING_DEFAULTS value (0.1)."""
+ chat_mdl = _drive_async_ask_with_config(
+ monkeypatch,
+ search_config={
+ "llm_setting": {
+ "temperature": 1.0,
+ "temperature_enabled": False,
+ }
+ },
+ )
+
+ assert chat_mdl.gen_conf is not None, "model must be invoked with a gen_conf"
+ assert chat_mdl.gen_conf["temperature"] == 0.1
+
+
# ---------------------------------------------------------------------------
# Tests for async_chat (production code path)
# ---------------------------------------------------------------------------
diff --git a/test/unit_test/api/db/services/test_gaussdb_dialog_sql.py b/test/unit_test/api/db/services/test_gaussdb_dialog_sql.py
index 665d3e04c2..d8a51608d9 100644
--- a/test/unit_test/api/db/services/test_gaussdb_dialog_sql.py
+++ b/test/unit_test/api/db/services/test_gaussdb_dialog_sql.py
@@ -217,7 +217,11 @@ def _install_settings_import_stubs(monkeypatch):
validate_dataset_embedding_models=lambda _kbs: None,
)
install_module("api.db.services.langfuse_service", TenantLangfuseService=_Dummy)
- install_module("api.db.services.llm_service", LLMBundle=_Dummy)
+ install_module(
+ "api.db.services.llm_service",
+ LLMBundle=_Dummy,
+ resolve_llm_setting=lambda *_args, **_kwargs: {},
+ )
install_module(
"api.db.joint_services.tenant_model_service",
get_tenant_default_model_by_type=lambda *_args, **_kwargs: {"model_type": "chat", "max_tokens": 8192},
diff --git a/test/unit_test/deepdoc/parser/test_figure_parser.py b/test/unit_test/deepdoc/parser/test_figure_parser.py
index b92fa0e6e7..b11dadf401 100644
--- a/test/unit_test/deepdoc/parser/test_figure_parser.py
+++ b/test/unit_test/deepdoc/parser/test_figure_parser.py
@@ -70,6 +70,7 @@ def _load_figure_parser(monkeypatch):
monkeypatch,
"api.db.services.llm_service",
LLMBundle=Mock(),
+ resolve_llm_setting=Mock(return_value={}),
)
_module(
monkeypatch,
diff --git a/test/unit_test/rag/app/test_picture_video.py b/test/unit_test/rag/app/test_picture_video.py
index 5923c05ffc..e36866893d 100644
--- a/test/unit_test/rag/app/test_picture_video.py
+++ b/test/unit_test/rag/app/test_picture_video.py
@@ -45,6 +45,7 @@ def _load_picture_module(tokenized_texts, ocr_text="", vision_error=""):
llm_service = ModuleType("api.db.services.llm_service")
llm_service.LLMBundle = FakeLLMBundle
+ llm_service.resolve_llm_setting = lambda *_args, **_kwargs: {}
def resolve_default_model(*_args, **_kwargs):
if vision_error:
diff --git a/test/unit_test/rag/flow/parser/test_vision_language.py b/test/unit_test/rag/flow/parser/test_vision_language.py
index 4c6622e4cd..36bb11c9ba 100644
--- a/test/unit_test/rag/flow/parser/test_vision_language.py
+++ b/test/unit_test/rag/flow/parser/test_vision_language.py
@@ -53,7 +53,12 @@ def _load_flow_utils(monkeypatch):
):
_package(monkeypatch, package_name)
- _module(monkeypatch, "api.db.services.llm_service", LLMBundle=Mock())
+ _module(
+ monkeypatch,
+ "api.db.services.llm_service",
+ LLMBundle=Mock(),
+ resolve_llm_setting=Mock(return_value={}),
+ )
_module(
monkeypatch,
"api.db.joint_services.tenant_model_service",