mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-15 09:28:27 +08:00
### Summary - Preserve an explicitly enabled `temperature=0` in the Agent LLM configuration. - Continue excluding invalid negative temperature values. - Add a focused regression test to the existing Agent LLM test file. Fixes #16683
72 lines
2.1 KiB
Python
72 lines
2.1 KiB
Python
import pytest
|
|
|
|
from agent.component.llm import LLM, LLMParam
|
|
|
|
|
|
def _llm(prompts=None):
|
|
cpn = LLM.__new__(LLM)
|
|
cpn._param = LLMParam()
|
|
cpn._param.prompts = prompts or [{"role": "user", "content": "User query: {sys.query}"}]
|
|
return cpn
|
|
|
|
|
|
@pytest.mark.p1
|
|
def test_sys_prompt_and_msg_replaces_trailing_user_instead_of_skipping():
|
|
cpn = _llm()
|
|
msg, _ = cpn._sys_prompt_and_msg([{"role": "user", "content": ""}], {"sys.query": "test"})
|
|
assert msg == [{"role": "user", "content": "User query: test"}]
|
|
|
|
|
|
@pytest.mark.p1
|
|
def test_sys_prompt_and_msg_keeps_consecutive_configured_prompts():
|
|
cpn = _llm(
|
|
[
|
|
{"role": "user", "content": "Context: {sys.query}"},
|
|
{"role": "user", "content": "User query: {sys.query}"},
|
|
]
|
|
)
|
|
msg, _ = cpn._sys_prompt_and_msg([], {"sys.query": "test"})
|
|
assert msg == [
|
|
{"role": "user", "content": "Context: test"},
|
|
{"role": "user", "content": "User query: test"},
|
|
]
|
|
|
|
|
|
@pytest.mark.p1
|
|
def test_validate_fitted_messages_requires_trailing_user():
|
|
err = LLM.validate_fitted_messages(
|
|
[
|
|
{"role": "system", "content": "system"},
|
|
{"role": "user", "content": "still here"},
|
|
{"role": "assistant", "content": "reply"},
|
|
]
|
|
)
|
|
assert err and "empty" in err.lower()
|
|
|
|
|
|
@pytest.mark.p1
|
|
def test_validate_fitted_messages_rejects_empty_user():
|
|
err = LLM.validate_fitted_messages([{"role": "system", "content": "system"}, {"role": "user", "content": ""}])
|
|
assert err and "empty" in err.lower()
|
|
|
|
|
|
@pytest.mark.p1
|
|
def test_fit_messages_uses_default_context_when_max_length_zero():
|
|
msg_fit, err = LLM.fit_messages(
|
|
"s" * 845,
|
|
[{"role": "user", "content": "User query: test"}],
|
|
0,
|
|
)
|
|
assert err is None
|
|
assert msg_fit[-1]["content"] == "User query: test"
|
|
|
|
|
|
@pytest.mark.p1
|
|
def test_gen_conf_includes_zero_temperature_when_enabled():
|
|
"""Include an explicitly enabled zero temperature in the model configuration."""
|
|
param = LLMParam()
|
|
param.temperature = 0
|
|
param.temperatureEnabled = True
|
|
|
|
assert param.gen_conf()["temperature"] == 0
|