fix: back off evaluation rate limits
This commit is contained in:
@@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
import base64
|
||||
import json
|
||||
import tempfile
|
||||
import threading
|
||||
import time
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
@@ -21,6 +22,7 @@ from src.evaluation_runtime import (
|
||||
normalize_evaluation_output,
|
||||
parse_dataset_bytes,
|
||||
prediction_is_allowed,
|
||||
transient_model_error_message,
|
||||
)
|
||||
|
||||
|
||||
@@ -282,6 +284,11 @@ class EvaluationRuntimeTests(unittest.TestCase):
|
||||
)
|
||||
self.assertEqual(result['prediction'], '地图导航')
|
||||
self.assertEqual(result['confidence'], 1.0)
|
||||
duplicated = normalize_evaluation_output(
|
||||
'{"prediction":"慢","complex":false}'
|
||||
'{"prediction":"慢","complex":false}'
|
||||
)
|
||||
self.assertEqual(duplicated['prediction'], '慢')
|
||||
self.assertTrue(labels_equivalent('Agent(tag="地图导航")', '地图导航'))
|
||||
self.assertTrue(
|
||||
labels_equivalent(
|
||||
@@ -375,6 +382,61 @@ class EvaluationRuntimeTests(unittest.TestCase):
|
||||
self.assertEqual(mapping['label_map']['慢系统'], '慢')
|
||||
self.assertEqual(mapping['label_map']['complex=Ture'], 'complex=true')
|
||||
self.assertEqual(mapping['unmapped'], ['未知'])
|
||||
self.assertIn(
|
||||
'HTTP 429',
|
||||
transient_model_error_message(
|
||||
'HTTP 429 from local model backend: Too many requests'
|
||||
),
|
||||
)
|
||||
|
||||
def test_transient_model_failure_retries_before_validation(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
runtime = EvaluationRuntime(
|
||||
root=root / 'evaluations',
|
||||
cwd_for_account=lambda _account: root,
|
||||
model_config_for=lambda _account: ModelConfig(model='test-model'),
|
||||
account_paths_for=lambda _account: {'python_env': root / '.venv'},
|
||||
max_workers=1,
|
||||
)
|
||||
transient = AgentRunResult(
|
||||
final_output='HTTP 429: Too many requests',
|
||||
turns=0,
|
||||
tool_calls=0,
|
||||
transcript=(),
|
||||
usage=UsageStats(),
|
||||
)
|
||||
success = AgentRunResult(
|
||||
final_output='{"prediction":"快"}',
|
||||
turns=1,
|
||||
tool_calls=0,
|
||||
transcript=(),
|
||||
usage=UsageStats(),
|
||||
)
|
||||
|
||||
class StubAgent:
|
||||
def __init__(self) -> None:
|
||||
self.calls = 0
|
||||
|
||||
def run(self, *_args: object, **_kwargs: object) -> AgentRunResult:
|
||||
self.calls += 1
|
||||
return transient if self.calls == 1 else success
|
||||
|
||||
agent = StubAgent()
|
||||
try:
|
||||
with patch.object(runtime, '_extend_model_cooldown') as cooldown:
|
||||
result = runtime._run_agent_with_transient_backoff(
|
||||
agent, # type: ignore[arg-type]
|
||||
'prompt',
|
||||
session_id='session',
|
||||
runtime_context='context',
|
||||
cancel_event=threading.Event(),
|
||||
)
|
||||
self.assertIs(result, success)
|
||||
self.assertEqual(agent.calls, 2)
|
||||
cooldown.assert_called_once()
|
||||
finally:
|
||||
runtime.shutdown()
|
||||
|
||||
def test_fast_slow_prompt_uses_skill_contract_and_relative_paths(self) -> None:
|
||||
skill = BundledSkill(
|
||||
|
||||
Reference in New Issue
Block a user