Skip to content

Commit

Permalink
fix: check context length exceeded phrases on lowercased response (#771)
Browse files Browse the repository at this point in the history
  • Loading branch information
salman1993 authored Jan 26, 2025
1 parent cb0049f commit d771cc1
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions crates/goose/src/providers/databricks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,17 @@ impl DatabricksProvider {
}
StatusCode::BAD_REQUEST => {
// Databricks provides a generic 'error' but also includes 'external_model_message' which is provider specific
// we try our best to extract the error message from the payload
let payload_str = serde_json::to_string(&payload).unwrap_or_default();
if payload_str.contains("too long")
|| payload_str.contains("context length")
|| payload_str.contains("context_length_exceeded")
|| payload_str.contains("reduce the length")
|| payload_str.contains("token count")
|| payload_str.contains("exceeds")
{
// We try to extract the error message from the payload and check for phrases that indicate context length exceeded
let payload_str = serde_json::to_string(&payload).unwrap_or_default().to_lowercase();
let check_phrases = [
"too long",
"context length",
"context_length_exceeded",
"reduce the length",
"token count",
"exceeds",
];
if check_phrases.iter().any(|c| payload_str.contains(c)) {
return Err(ProviderError::ContextLengthExceeded(payload_str));
}

Expand Down

0 comments on commit d771cc1

Please sign in to comment.