mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-05 07:10:29 +08:00
Fix: handle llm_setting switch (#17745)
This commit is contained in:
@@ -18,6 +18,48 @@ 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}
|
||||
|
||||
Reference in New Issue
Block a user