fix(agent): enforce complete homework answers
This commit is contained in:
@@ -10,7 +10,7 @@ from app.models.admin import Admin
|
||||
from app.models.ai_config import ModelConfig
|
||||
from app.schemas.admin import AgentRuntimeConfigSaveRequest
|
||||
from app.services.model_stream_service import _openai_stream_payload
|
||||
from app.services.model_service import _max_output_tokens
|
||||
from app.services.model_service import ModelClientService, _max_output_tokens
|
||||
from app.services.rag_service import RagResult
|
||||
|
||||
|
||||
@@ -99,3 +99,18 @@ def test_saved_runtime_config_is_persisted_on_enabled_model():
|
||||
assert payload["top_p"] == 0.9
|
||||
assert payload["presence_penalty"] == 0.2
|
||||
assert payload["frequency_penalty"] == 0.4
|
||||
|
||||
|
||||
def test_agent_debug_does_not_truncate_long_answer(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
"app.services.model_service._call_configured_model",
|
||||
lambda *_args, **_kwargs: "长" * 6000,
|
||||
)
|
||||
|
||||
result = ModelClientService.debug_model(
|
||||
_model(),
|
||||
RagResult(question="测试", knowledge_scopes=[], chunks=[], prompt="测试", allow_general_knowledge=True),
|
||||
{"max_token": 8192},
|
||||
)
|
||||
|
||||
assert len(result["answer"]) == 6000
|
||||
|
||||
@@ -21,6 +21,7 @@ from app.models.knowledge import (
|
||||
)
|
||||
from app.models.chat import ChatMessage
|
||||
from app.services.knowledge_agent_service import Candidate, KnowledgeAgentService
|
||||
from app.services.rag_service import PromptService, RetrievedChunk
|
||||
|
||||
|
||||
def _database() -> Session:
|
||||
@@ -227,6 +228,26 @@ def test_homework_overview_keeps_all_numbered_practices_before_selection():
|
||||
assert all(item.chunk.title.startswith("练习") for item in selected)
|
||||
|
||||
|
||||
def test_homework_overview_prompt_requires_every_recalled_title():
|
||||
chunks = [
|
||||
RetrievedChunk(
|
||||
knowledge_id=1 if index <= 6 else 2,
|
||||
knowledge_name="《原生·上》" if index <= 6 else "《原生·下》",
|
||||
title=f"练习{index}:作业{index}",
|
||||
content=f"作业{index}的正式说明",
|
||||
)
|
||||
for index in range(1, 15)
|
||||
]
|
||||
|
||||
constraint = PromptService._list_completeness_constraint("原生里的作业都有哪些", chunks)
|
||||
|
||||
assert "本轮共召回 14 个正式编号练习" in constraint
|
||||
assert "必须覆盖下面全部 14 项" in constraint
|
||||
assert "不得新增清单外的作业" in constraint
|
||||
assert "练习1:作业1" in constraint
|
||||
assert "练习14:作业14" in constraint
|
||||
|
||||
|
||||
def test_complete_section_includes_child_headings_but_stops_at_next_peer():
|
||||
with _database() as db:
|
||||
knowledge = _add_published_knowledge(db, knowledge_id=1, name="合一课程")
|
||||
|
||||
Reference in New Issue
Block a user