fix: check context length exceeded phrases on lowercased response (#771)
This commit is contained in:
@@ -163,15 +163,17 @@ impl DatabricksProvider {
|
|||||||
}
|
}
|
||||||
StatusCode::BAD_REQUEST => {
|
StatusCode::BAD_REQUEST => {
|
||||||
// Databricks provides a generic 'error' but also includes 'external_model_message' which is provider specific
|
// 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
|
// 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();
|
let payload_str = serde_json::to_string(&payload).unwrap_or_default().to_lowercase();
|
||||||
if payload_str.contains("too long")
|
let check_phrases = [
|
||||||
|| payload_str.contains("context length")
|
"too long",
|
||||||
|| payload_str.contains("context_length_exceeded")
|
"context length",
|
||||||
|| payload_str.contains("reduce the length")
|
"context_length_exceeded",
|
||||||
|| payload_str.contains("token count")
|
"reduce the length",
|
||||||
|| payload_str.contains("exceeds")
|
"token count",
|
||||||
{
|
"exceeds",
|
||||||
|
];
|
||||||
|
if check_phrases.iter().any(|c| payload_str.contains(c)) {
|
||||||
return Err(ProviderError::ContextLengthExceeded(payload_str));
|
return Err(ProviderError::ContextLengthExceeded(payload_str));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user