cache_control removed from databricks
This commit is contained in:
@@ -51,7 +51,6 @@ pub struct DatabricksConfig {
|
|||||||
pub model: String,
|
pub model: String,
|
||||||
pub max_tokens: Option<u32>,
|
pub max_tokens: Option<u32>,
|
||||||
pub temperature: Option<f32>,
|
pub temperature: Option<f32>,
|
||||||
pub cache_config: Option<String>, // "ephemeral", "5minute", "1hour", or None to disable
|
|
||||||
pub use_oauth: Option<bool>, // Default to true if token not provided
|
pub use_oauth: Option<bool>, // Default to true if token not provided
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +134,6 @@ impl Default for Config {
|
|||||||
model: "databricks-claude-sonnet-4".to_string(),
|
model: "databricks-claude-sonnet-4".to_string(),
|
||||||
max_tokens: Some(4096),
|
max_tokens: Some(4096),
|
||||||
temperature: Some(0.1),
|
temperature: Some(0.1),
|
||||||
cache_config: None,
|
|
||||||
use_oauth: Some(true),
|
use_oauth: Some(true),
|
||||||
}),
|
}),
|
||||||
embedded: None,
|
embedded: None,
|
||||||
|
|||||||
@@ -1513,15 +1513,6 @@ If you can complete it with 1-2 tool calls, skip TODO.
|
|||||||
"anthropic" => self.config.providers.anthropic.as_ref()
|
"anthropic" => self.config.providers.anthropic.as_ref()
|
||||||
.and_then(|c| c.cache_config.as_ref())
|
.and_then(|c| c.cache_config.as_ref())
|
||||||
.and_then(|config| Self::parse_cache_control(config)),
|
.and_then(|config| Self::parse_cache_control(config)),
|
||||||
"databricks" => self.config.providers.databricks.as_ref()
|
|
||||||
.and_then(|c| {
|
|
||||||
if c.model.contains("claude") {
|
|
||||||
c.cache_config.as_ref()
|
|
||||||
.and_then(|config| Self::parse_cache_control(config))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
_ => None,
|
_ => None,
|
||||||
} {
|
} {
|
||||||
let provider = self.providers.get(None)?;
|
let provider = self.providers.get(None)?;
|
||||||
@@ -1621,15 +1612,6 @@ If you can complete it with 1-2 tool calls, skip TODO.
|
|||||||
"anthropic" => self.config.providers.anthropic.as_ref()
|
"anthropic" => self.config.providers.anthropic.as_ref()
|
||||||
.and_then(|c| c.cache_config.as_ref())
|
.and_then(|c| c.cache_config.as_ref())
|
||||||
.and_then(|config| Self::parse_cache_control(config)),
|
.and_then(|config| Self::parse_cache_control(config)),
|
||||||
"databricks" => self.config.providers.databricks.as_ref()
|
|
||||||
.and_then(|c| {
|
|
||||||
if c.model.contains("claude") {
|
|
||||||
c.cache_config.as_ref()
|
|
||||||
.and_then(|config| Self::parse_cache_control(config))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
_ => None,
|
_ => None,
|
||||||
} {
|
} {
|
||||||
Message::with_cache_control_validated(MessageRole::Assistant, response_content.clone(), cache_config, provider)
|
Message::with_cache_control_validated(MessageRole::Assistant, response_content.clone(), cache_config, provider)
|
||||||
@@ -3680,15 +3662,6 @@ If you can complete it with 1-2 tool calls, skip TODO.
|
|||||||
"anthropic" => self.config.providers.anthropic.as_ref()
|
"anthropic" => self.config.providers.anthropic.as_ref()
|
||||||
.and_then(|c| c.cache_config.as_ref())
|
.and_then(|c| c.cache_config.as_ref())
|
||||||
.and_then(|config| Self::parse_cache_control(config)),
|
.and_then(|config| Self::parse_cache_control(config)),
|
||||||
"databricks" => self.config.providers.databricks.as_ref()
|
|
||||||
.and_then(|c| {
|
|
||||||
if c.model.contains("claude") {
|
|
||||||
c.cache_config.as_ref()
|
|
||||||
.and_then(|config| Self::parse_cache_control(config))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
_ => None,
|
_ => None,
|
||||||
} {
|
} {
|
||||||
Message::with_cache_control_validated(MessageRole::Assistant, raw_clean, cache_config, provider)
|
Message::with_cache_control_validated(MessageRole::Assistant, raw_clean, cache_config, provider)
|
||||||
|
|||||||
@@ -238,11 +238,6 @@ impl DatabricksProvider {
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn convert_cache_control(cache_control: &crate::CacheControl) -> crate::CacheControl {
|
|
||||||
// Databricks uses the same format, so just clone it
|
|
||||||
cache_control.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn convert_messages(&self, messages: &[Message]) -> Result<Vec<DatabricksMessage>> {
|
fn convert_messages(&self, messages: &[Message]) -> Result<Vec<DatabricksMessage>> {
|
||||||
let mut databricks_messages = Vec::new();
|
let mut databricks_messages = Vec::new();
|
||||||
|
|
||||||
@@ -253,20 +248,8 @@ impl DatabricksProvider {
|
|||||||
MessageRole::Assistant => "assistant",
|
MessageRole::Assistant => "assistant",
|
||||||
};
|
};
|
||||||
|
|
||||||
// If message has cache_control, use content array format
|
// Always use simple string format (Databricks doesn't support cache_control)
|
||||||
let content = if message.cache_control.is_some() {
|
let content = serde_json::Value::String(message.content.clone());
|
||||||
// Use array format with cache_control
|
|
||||||
let content_block = DatabricksContent::Text {
|
|
||||||
content_type: "text".to_string(),
|
|
||||||
text: message.content.clone(),
|
|
||||||
cache_control: message.cache_control.as_ref()
|
|
||||||
.map(Self::convert_cache_control),
|
|
||||||
};
|
|
||||||
serde_json::to_value(vec![content_block])?
|
|
||||||
} else {
|
|
||||||
// Use simple string format
|
|
||||||
serde_json::Value::String(message.content.clone())
|
|
||||||
};
|
|
||||||
|
|
||||||
databricks_messages.push(DatabricksMessage {
|
databricks_messages.push(DatabricksMessage {
|
||||||
role: role.to_string(),
|
role: role.to_string(),
|
||||||
@@ -1070,8 +1053,7 @@ impl LLMProvider for DatabricksProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn supports_cache_control(&self) -> bool {
|
fn supports_cache_control(&self) -> bool {
|
||||||
// Databricks supports cache control when using Anthropic models
|
false
|
||||||
self.model.contains("claude")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1100,18 +1082,6 @@ struct DatabricksFunction {
|
|||||||
parameters: serde_json::Value,
|
parameters: serde_json::Value,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
#[serde(untagged)]
|
|
||||||
enum DatabricksContent {
|
|
||||||
Text {
|
|
||||||
#[serde(rename = "type")]
|
|
||||||
content_type: String,
|
|
||||||
text: String,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
cache_control: Option<crate::CacheControl>,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
struct DatabricksMessage {
|
struct DatabricksMessage {
|
||||||
role: String,
|
role: String,
|
||||||
@@ -1322,7 +1292,7 @@ mod tests {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Test message WITHOUT cache_control - should use string format
|
// Test message WITHOUT cache_control
|
||||||
let messages_without = vec![Message::new(MessageRole::User, "Hello".to_string())];
|
let messages_without = vec![Message::new(MessageRole::User, "Hello".to_string())];
|
||||||
let databricks_messages_without = provider.convert_messages(&messages_without).unwrap();
|
let databricks_messages_without = provider.convert_messages(&messages_without).unwrap();
|
||||||
let json_without = serde_json::to_string(&databricks_messages_without).unwrap();
|
let json_without = serde_json::to_string(&databricks_messages_without).unwrap();
|
||||||
@@ -1331,7 +1301,7 @@ mod tests {
|
|||||||
assert!(!json_without.contains("cache_control"),
|
assert!(!json_without.contains("cache_control"),
|
||||||
"JSON should not contain 'cache_control' field when not configured");
|
"JSON should not contain 'cache_control' field when not configured");
|
||||||
|
|
||||||
// Test message WITH cache_control - should use array format
|
// Test message WITH cache_control - should still NOT include it (Databricks doesn't support it)
|
||||||
let messages_with = vec![Message::with_cache_control(
|
let messages_with = vec![Message::with_cache_control(
|
||||||
MessageRole::User,
|
MessageRole::User,
|
||||||
"Hello".to_string(),
|
"Hello".to_string(),
|
||||||
@@ -1341,22 +1311,31 @@ mod tests {
|
|||||||
let json_with = serde_json::to_string(&databricks_messages_with).unwrap();
|
let json_with = serde_json::to_string(&databricks_messages_with).unwrap();
|
||||||
|
|
||||||
println!("JSON with cache_control: {}", json_with);
|
println!("JSON with cache_control: {}", json_with);
|
||||||
assert!(json_with.contains("cache_control"),
|
assert!(!json_with.contains("cache_control"),
|
||||||
"JSON should contain 'cache_control' field when configured");
|
"JSON should NOT contain 'cache_control' field - Databricks doesn't support it");
|
||||||
assert!(json_with.contains("ephemeral"),
|
}
|
||||||
"JSON should contain 'ephemeral' type");
|
|
||||||
assert!(!json_with.contains("null"),
|
|
||||||
"JSON should not contain null values");
|
|
||||||
|
|
||||||
// Verify the structure is correct
|
#[test]
|
||||||
let msg_with = &databricks_messages_with[0];
|
fn test_databricks_does_not_support_cache_control() {
|
||||||
if let Some(content) = &msg_with.content {
|
let claude_provider = DatabricksProvider::from_token(
|
||||||
if let Some(arr) = content.as_array() {
|
"https://test.databricks.com".to_string(),
|
||||||
assert_eq!(arr.len(), 1, "Content array should have one element");
|
"test-token".to_string(),
|
||||||
assert!(arr[0].get("cache_control").is_some(), "Content should have cache_control");
|
"databricks-claude-sonnet-4".to_string(),
|
||||||
} else {
|
None,
|
||||||
panic!("Content should be an array when cache_control is present");
|
None,
|
||||||
}
|
)
|
||||||
}
|
.unwrap();
|
||||||
|
|
||||||
|
let llama_provider = DatabricksProvider::from_token(
|
||||||
|
"https://test.databricks.com".to_string(),
|
||||||
|
"test-token".to_string(),
|
||||||
|
"databricks-meta-llama-3-3-70b-instruct".to_string(),
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert!(!claude_provider.supports_cache_control(), "Databricks should not support cache_control even for Claude models");
|
||||||
|
assert!(!llama_provider.supports_cache_control(), "Databricks should not support cache_control for Llama models");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user