V10.556 補 GCP-B 模型 fallback 防 111 過載
This commit is contained in:
@@ -167,6 +167,50 @@ def test_generate_forces_final_fallback_when_unhealthy_ttl_expires_mid_request()
|
||||
assert 'all 3 hosts failed' in (resp.error or '')
|
||||
|
||||
|
||||
def test_generate_uses_secondary_model_fallback_before_111():
|
||||
"""GCP-B 缺 coder 模型時,先改用 secondary fallback,不直接推到 111。"""
|
||||
from services import ollama_service as oss
|
||||
from services.ollama_service import OllamaService
|
||||
|
||||
svc = OllamaService()
|
||||
fake_ok = MagicMock(status_code=200)
|
||||
fake_ok.json.return_value = {
|
||||
'response': 'OK from secondary fallback',
|
||||
'prompt_eval_count': 10,
|
||||
'eval_count': 5,
|
||||
}
|
||||
|
||||
with patch('services.ollama_service.resolve_ollama_host', return_value=oss.OLLAMA_HOST_SECONDARY), \
|
||||
patch('services.ollama_service.requests.post', return_value=fake_ok) as mock_post:
|
||||
resp = svc.generate('test prompt', model='qwen2.5-coder:7b')
|
||||
|
||||
assert resp.success is True
|
||||
assert resp.host == oss.OLLAMA_HOST_SECONDARY
|
||||
assert resp.model == 'gemma3:4b'
|
||||
payload = mock_post.call_args.kwargs['json']
|
||||
assert payload['model'] == 'gemma3:4b'
|
||||
|
||||
|
||||
def test_generate_model_404_does_not_mark_host_unhealthy():
|
||||
"""模型不存在是 model availability,不應把整台 GCP-B 標成 unhealthy。"""
|
||||
from services import ollama_service as oss
|
||||
from services.ollama_service import OllamaService
|
||||
|
||||
svc = OllamaService()
|
||||
fake_404 = MagicMock(status_code=404, text='{"error":"model not found"}')
|
||||
fake_ok = MagicMock(status_code=200)
|
||||
fake_ok.json.return_value = {'response': 'OK', 'prompt_eval_count': 3, 'eval_count': 2}
|
||||
|
||||
with patch('services.ollama_service.resolve_ollama_host', side_effect=[
|
||||
oss.OLLAMA_HOST_SECONDARY,
|
||||
oss.OLLAMA_HOST_FALLBACK,
|
||||
]), patch('services.ollama_service.requests.post', side_effect=[fake_404, fake_ok]):
|
||||
resp = svc.generate('test prompt', model='tiny-missing-model')
|
||||
|
||||
assert resp.success is True
|
||||
assert oss.OLLAMA_HOST_SECONDARY not in oss._unhealthy_marks
|
||||
|
||||
|
||||
def test_generate_can_disable_111_fallback_for_batch_llm_work():
|
||||
"""批量 LLM 任務可選擇只跑 GCP-A/GCP-B,避免 111 承接長分析。"""
|
||||
import requests
|
||||
|
||||
Reference in New Issue
Block a user