feat: add dynamic variables and startup result handling in batch run schemas

- Introduced dynamic_variables field in BatchRunCreate schema to support flexible input types.
- Added BatchStartupResult schema to encapsulate startup state, including greeting and auto-confirmed messages.
- Updated BatchRunCaseOut schema to include startup results, enhancing the structure for test run outputs.
- Enhanced test run orchestration to prepare and validate dynamic configurations, ensuring isolated variable management across test cases.
- Implemented changes in the frontend to accommodate new data structures for improved test case execution and result tracking.
This commit is contained in:
Xin Wang
2026-08-12 16:55:25 +08:00
parent 79a239489a
commit 7560f9a525
12 changed files with 1464 additions and 1004 deletions
+12 -1
View File
@@ -17,6 +17,7 @@ from db.session import get_session
from fastapi import APIRouter, Depends, HTTPException
from services.auth import require_admin
from services.config_resolver import resolve_runtime_config
from services.runtime_variables import DynamicVariableError, prepare_dynamic_config
from services.test_runs.orchestrator import test_run_orchestrator
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
@@ -25,6 +26,7 @@ from test_schemas import (
BatchRunCaseOut,
BatchRunCreate,
BatchRunSnapshotOut,
BatchStartupResult,
BatchTurnResult,
BatchEvaluationResult,
TestCaseDefinition,
@@ -65,6 +67,9 @@ async def _run_out(
BatchTurnResult.model_validate(item)
for item in result.get("turns") or []
],
startup=BatchStartupResult.model_validate(
result.get("startup") or {}
),
overall_criteria=[
BatchEvaluationResult.model_validate(item)
for item in result.get("overallCriteria")
@@ -118,7 +123,12 @@ async def create_test_run(
raise HTTPException(422, "评估模型不存在、已停用或不是 LLM 资源")
try:
runtime_config = await resolve_runtime_config(session, assistant.id)
except ValueError as exc:
prepare_dynamic_config(
runtime_config,
body.dynamic_variables,
assistant_id=assistant.id,
)
except (ValueError, DynamicVariableError) as exc:
raise HTTPException(422, str(exc)) from exc
rows = (
@@ -175,6 +185,7 @@ async def create_test_run(
"evaluatorModel": str(
(evaluator_resource.values or {}).get("modelId") or ""
),
"dynamicVariables": body.dynamic_variables,
**body.config.model_dump(mode="json", by_alias=True),
},
started_at=now,