fix: log primary model error before fallback
This commit is contained in:
@@ -150,13 +150,17 @@ class FallbackProvider(LLMProvider):
|
||||
on_stream_recover: Callable[[], Awaitable[None]] | None = None,
|
||||
) -> LLMResponse:
|
||||
primary_model = kwargs.get("model") or self._primary.get_default_model()
|
||||
primary_was_attempted = False
|
||||
primary_error = "unknown error"
|
||||
|
||||
if self._primary_available():
|
||||
primary_was_attempted = True
|
||||
response = await call(self._primary, kwargs)
|
||||
if response.finish_reason != "error":
|
||||
self._primary_failures = 0
|
||||
self._primary_tripped_at = None
|
||||
return response
|
||||
primary_error = (response.content or primary_error)[:120]
|
||||
|
||||
if has_streamed is not None and has_streamed[0]:
|
||||
is_timeout = (response.error_kind or "").lower() == "timeout"
|
||||
@@ -196,7 +200,7 @@ class FallbackProvider(LLMProvider):
|
||||
logger.debug("Primary model '{}' circuit open; skipping", primary_model)
|
||||
|
||||
last_response: LLMResponse | None = None
|
||||
primary_skipped = not self._primary_available()
|
||||
primary_skipped = not primary_was_attempted
|
||||
for idx, fallback in enumerate(self._fallback_presets):
|
||||
fallback_model = fallback.model
|
||||
if has_streamed is not None and has_streamed[0]:
|
||||
@@ -221,8 +225,8 @@ class FallbackProvider(LLMProvider):
|
||||
)
|
||||
elif idx == 0:
|
||||
logger.info(
|
||||
"Primary model '{}' failed, trying fallback '{}'",
|
||||
primary_model, fallback_model,
|
||||
"Primary model '{}' failed: {}; trying fallback '{}'",
|
||||
primary_model, primary_error, fallback_model,
|
||||
)
|
||||
else:
|
||||
logger.info(
|
||||
|
||||
Reference in New Issue
Block a user