make prompt caching optional, run clippy
This commit is contained in:
@@ -45,6 +45,9 @@ pub struct ClaudeConfig {
|
|||||||
/// Maximum tool use iterations before giving up.
|
/// Maximum tool use iterations before giving up.
|
||||||
#[conf(long, env, default_value = "10")]
|
#[conf(long, env, default_value = "10")]
|
||||||
pub claude_max_iterations: u32,
|
pub claude_max_iterations: u32,
|
||||||
|
/// Enable prompt caching (adds cache_control to system prompts).
|
||||||
|
#[conf(long, env)]
|
||||||
|
pub prompt_caching: bool,
|
||||||
/// Compaction configuration.
|
/// Compaction configuration.
|
||||||
#[conf(flatten, prefix)]
|
#[conf(flatten, prefix)]
|
||||||
pub compaction: CompactionConfig,
|
pub compaction: CompactionConfig,
|
||||||
|
|||||||
@@ -253,9 +253,11 @@ impl ClaudeWorker {
|
|||||||
if !self.summary.is_empty() {
|
if !self.summary.is_empty() {
|
||||||
system.push(SystemContent::text(&self.summary));
|
system.push(SystemContent::text(&self.summary));
|
||||||
}
|
}
|
||||||
// Mark the last one as cached
|
// Mark the last one as cached if prompt caching is enabled
|
||||||
if let Some(last) = system.last_mut() {
|
if self.config.prompt_caching
|
||||||
*last = std::mem::take(last).cached();
|
&& let Some(last) = system.last_mut()
|
||||||
|
{
|
||||||
|
last.set_cached();
|
||||||
}
|
}
|
||||||
|
|
||||||
let request_body = MessagesRequest {
|
let request_body = MessagesRequest {
|
||||||
@@ -347,14 +349,16 @@ impl ClaudeWorker {
|
|||||||
let mut system: Vec<SystemContent> = self
|
let mut system: Vec<SystemContent> = self
|
||||||
.system_prompts
|
.system_prompts
|
||||||
.iter()
|
.iter()
|
||||||
.map(|text| SystemContent::text(text))
|
.map(SystemContent::text)
|
||||||
.collect();
|
.collect();
|
||||||
if !self.summary.is_empty() {
|
if !self.summary.is_empty() {
|
||||||
system.push(SystemContent::text(&self.summary));
|
system.push(SystemContent::text(&self.summary));
|
||||||
}
|
}
|
||||||
// Mark the last one as cached
|
// Mark the last one as cached if prompt caching is enabled
|
||||||
if let Some(last) = system.last_mut() {
|
if self.config.prompt_caching
|
||||||
*last = std::mem::take(last).cached();
|
&& let Some(last) = system.last_mut()
|
||||||
|
{
|
||||||
|
last.set_cached();
|
||||||
}
|
}
|
||||||
|
|
||||||
for iteration in 0..max_iterations {
|
for iteration in 0..max_iterations {
|
||||||
@@ -506,9 +510,8 @@ impl SystemContent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cached(mut self) -> Self {
|
fn set_cached(&mut self) {
|
||||||
self.cache_control = Some(CacheControl::ephemeral());
|
self.cache_control = Some(CacheControl::ephemeral());
|
||||||
self
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -558,7 +561,9 @@ impl MessageContent {
|
|||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
#[serde(tag = "type", rename_all = "snake_case")]
|
#[serde(tag = "type", rename_all = "snake_case")]
|
||||||
enum ContentBlock {
|
enum ContentBlock {
|
||||||
Text { text: Box<str> },
|
Text {
|
||||||
|
text: Box<str>,
|
||||||
|
},
|
||||||
ToolUse {
|
ToolUse {
|
||||||
id: Box<str>,
|
id: Box<str>,
|
||||||
name: Box<str>,
|
name: Box<str>,
|
||||||
|
|||||||
Reference in New Issue
Block a user