Files
archie/internal/gateway/turn_failure.go
T

32 lines
1.3 KiB
Go

package gateway
import (
"context"
"errors"
"github.com/samcharles93/ai-sdk/chat"
)
// turnFailureText is what a chat reader sees when a turn fails: one complete
// sentence they can act on, shown as the reply itself. The cause carries
// provider bodies, URLs and wrapping that belong in the log, which failTurn
// writes, not in front of whoever is chatting.
func turnFailureText(err error) string {
switch {
case errors.Is(err, chat.ErrRateLimited):
return "The model provider is refusing requests right now (rate limit or spending cap). Try again later, or pick another model with /model."
case errors.Is(err, chat.ErrAuthFailed):
return "The model provider rejected Archie's credentials. An admin needs to check the provider key in Settings."
case errors.Is(err, chat.ErrProviderUnavailable):
return "The model provider is unavailable. Try again in a moment."
case errors.Is(err, chat.ErrContextLength):
return "This conversation is too long for the model. Start a new chat, or shorten this one with /compress."
case errors.Is(err, chat.ErrUnsupportedContent):
return "The model can't read one of the attachments. Remove it, or pick another model with /model."
case errors.Is(err, context.DeadlineExceeded):
return "The model took too long to answer. Try again."
default:
return "Archie couldn't reply. Try again in a moment."
}
}