feat(agent): add debug output switches
This commit is contained in:
@@ -89,6 +89,8 @@ class AgentDebugRequest(BaseModel):
|
||||
presencePenalty: float | None = Field(default=None, ge=-2, le=2)
|
||||
frequencyPenalty: float | None = Field(default=None, ge=-2, le=2)
|
||||
maxToken: int | None = Field(default=8192, ge=1, le=100000)
|
||||
streamEnabled: int = Field(default=1, ge=0, le=1)
|
||||
reasoningVisible: int = Field(default=0, ge=0, le=1)
|
||||
|
||||
|
||||
class AgentRuntimeConfigSaveRequest(BaseModel):
|
||||
|
||||
@@ -48,6 +48,7 @@ class AgentDebugService:
|
||||
"presence_penalty": payload.presencePenalty,
|
||||
"frequency_penalty": payload.frequencyPenalty,
|
||||
"max_token": payload.maxToken,
|
||||
"stream_enabled": payload.streamEnabled,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
@@ -62,7 +63,7 @@ class AgentDebugService:
|
||||
yield {"type": "error", "message": "模型不存在"}
|
||||
return
|
||||
try:
|
||||
reasoning_visible = ReasoningPolicyService.is_visible(db)
|
||||
reasoning_visible = payload.reasoningVisible == 1
|
||||
yield {
|
||||
"type": "status",
|
||||
"stage": "retrieving",
|
||||
|
||||
@@ -169,7 +169,7 @@ def _copy_model_with_overrides(model: ModelConfig, overrides: dict[str, Any]) ->
|
||||
frequency_penalty=overrides.get("frequency_penalty"),
|
||||
max_token=overrides.get("max_token"),
|
||||
context_window=model.context_window,
|
||||
stream_enabled=model.stream_enabled,
|
||||
stream_enabled=overrides.get("stream_enabled", model.stream_enabled),
|
||||
response_format=model.response_format,
|
||||
extra_params=model.extra_params,
|
||||
remark=model.remark,
|
||||
|
||||
@@ -13,12 +13,13 @@ from app.models import Base
|
||||
from app.models.admin import Admin
|
||||
from app.models.ai_config import ModelConfig, SystemConfig
|
||||
from app.schemas.admin import AgentDebugRequest, AgentRuntimeConfigSaveRequest
|
||||
from app.services.agent_debug_service import AgentDebugService
|
||||
from app.services.model_stream_service import (
|
||||
AsyncStreamingModelResponse,
|
||||
_openai_stream_payload,
|
||||
_stream_configured_model_async,
|
||||
)
|
||||
from app.services.model_service import ModelClientService, _max_output_tokens
|
||||
from app.services.model_service import ModelClientService, _copy_model_with_overrides, _max_output_tokens
|
||||
from app.services.rag_service import RagResult
|
||||
|
||||
|
||||
@@ -146,6 +147,23 @@ def test_disabled_stream_returns_one_complete_chunk():
|
||||
assert chunks == [answer]
|
||||
|
||||
|
||||
def test_debug_stream_setting_overrides_model_without_changing_it():
|
||||
model = _model()
|
||||
debug_model = _copy_model_with_overrides(model, {"stream_enabled": 0})
|
||||
|
||||
assert model.stream_enabled == 1
|
||||
assert debug_model.stream_enabled == 0
|
||||
|
||||
payload = AgentDebugRequest(
|
||||
promptContent="测试",
|
||||
modelId=1,
|
||||
question="测试",
|
||||
streamEnabled=0,
|
||||
reasoningVisible=1,
|
||||
)
|
||||
assert AgentDebugService.overrides(payload)["stream_enabled"] == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize("reasoning_visible", [True, False])
|
||||
def test_agent_debug_stream_respects_reasoning_visibility(reasoning_visible):
|
||||
async def chunks():
|
||||
@@ -179,7 +197,7 @@ def test_agent_debug_stream_respects_reasoning_visibility(reasoning_visible):
|
||||
db.add(SystemConfig(
|
||||
id=1,
|
||||
config_key="show_model_reasoning",
|
||||
config_value="true" if reasoning_visible else "false",
|
||||
config_value="false" if reasoning_visible else "true",
|
||||
))
|
||||
db.commit()
|
||||
payload = AgentDebugRequest(
|
||||
@@ -188,6 +206,7 @@ def test_agent_debug_stream_respects_reasoning_visibility(reasoning_visible):
|
||||
knowledgeIds=[],
|
||||
question="怎么冷静",
|
||||
maxToken=8192,
|
||||
reasoningVisible=1 if reasoning_visible else 0,
|
||||
)
|
||||
with (
|
||||
patch(
|
||||
|
||||
Reference in New Issue
Block a user