getAssistantMessageFromError function
Convert an API error to an assistant-facing message.
Implementation
String getAssistantMessageFromError(ApiError error) => switch (error.type) {
ApiErrorType.rateLimited =>
'I was rate limited. Please wait a moment before sending another message.',
ApiErrorType.overloaded =>
'The API is currently overloaded. Please try again in a moment.',
ApiErrorType.authenticationError =>
'Authentication failed. Please check your API key in settings.',
ApiErrorType.permissionDenied =>
'Permission denied. Your API key may not have access to this model.',
ApiErrorType.promptTooLong =>
'The conversation is too long for this model. Try clearing the conversation or using a model with a larger context window.',
ApiErrorType.mediaTooLarge =>
'An image or PDF in the conversation exceeds the size limit.',
ApiErrorType.contentRefused =>
'The request was refused by the safety system.',
_ => 'An error occurred: ${error.message}',
};