fix: detect low balance and prompt for top up (#7166)
Signed-off-by: raj-subhankar <subhankar.rj@gmail.com> Co-authored-by: Douwe Osinga <douwe@squareup.com> Co-authored-by: raj-subhankar <subhankar.rj@gmail.com>
This commit is contained in:
@@ -1500,6 +1500,29 @@ impl Agent {
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(ref provider_err @ ProviderError::CreditsExhausted { details: _, ref top_up_url }) => {
|
||||
crate::posthog::emit_error(provider_err.telemetry_type(), &provider_err.to_string());
|
||||
error!("Error: {}", provider_err);
|
||||
|
||||
let user_msg = if top_up_url.is_some() {
|
||||
"Please add credits to your account, then resend your message to continue.".to_string()
|
||||
} else {
|
||||
"Please check your account with your provider to add more credits, then resend your message to continue.".to_string()
|
||||
};
|
||||
|
||||
let notification_data = serde_json::json!({
|
||||
"top_up_url": top_up_url,
|
||||
});
|
||||
|
||||
yield AgentEvent::Message(
|
||||
Message::assistant().with_system_notification_with_data(
|
||||
SystemNotificationType::CreditsExhausted,
|
||||
user_msg,
|
||||
notification_data,
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
Err(ref provider_err) => {
|
||||
crate::posthog::emit_error(provider_err.telemetry_type(), &provider_err.to_string());
|
||||
error!("Error: {}", provider_err);
|
||||
|
||||
Reference in New Issue
Block a user