Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions llm_client/src/clients/anthropic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ enum ContentBlockDeltaType {
},
}

#[derive(serde::Serialize, Debug, Clone)]
struct AnthropicThinking {
#[serde(rename = "type")]
thinking_type: String,
budget_tokens: usize,
}

#[derive(serde::Serialize, Debug, Clone)]
struct AnthropicRequest {
system: Vec<AnthropicMessageContent>,
Expand All @@ -238,6 +245,8 @@ struct AnthropicRequest {
stream: bool,
#[serde(skip_serializing_if = "Option::is_none")]
max_tokens: Option<usize>,
#[serde(skip_serializing_if = "Option::is_none")]
thinking: Option<AnthropicThinking>,
model: String,
}

Expand All @@ -262,6 +271,12 @@ impl AnthropicRequest {
}
}
};
let thinking = completion_request
.thinking_budget()
.map(|budget| AnthropicThinking {
thinking_type: "enabled".to_owned(),
budget_tokens: budget,
});
let messages = completion_request.messages();
// grab the tools over here ONLY from the system message
let tools = messages
Expand Down Expand Up @@ -346,6 +361,7 @@ impl AnthropicRequest {
tools,
stream: true,
max_tokens,
thinking,
model: model_str,
}
}
Expand All @@ -356,6 +372,12 @@ impl AnthropicRequest {
) -> Self {
let temperature = completion_request.temperature();
let max_tokens = completion_request.get_max_tokens();
let thinking = completion_request
.thinking_budget()
.map(|budget| AnthropicThinking {
thinking_type: "enabled".to_owned(),
budget_tokens: budget,
});
let messages = vec![AnthropicMessage::new(
"user".to_owned(),
completion_request.prompt().to_owned(),
Expand All @@ -367,6 +389,7 @@ impl AnthropicRequest {
tools: vec![],
stream: true,
max_tokens,
thinking,
model: model_str,
}
}
Expand Down
22 changes: 22 additions & 0 deletions llm_client/src/clients/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ pub struct LLMClientCompletionRequest {
frequency_penalty: Option<f32>,
stop_words: Option<Vec<String>>,
max_tokens: Option<usize>,
thinking_budget: Option<usize>,
}

#[derive(Clone)]
Expand All @@ -703,6 +704,7 @@ pub struct LLMClientCompletionStringRequest {
frequency_penalty: Option<f32>,
stop_words: Option<Vec<String>>,
max_tokens: Option<usize>,
thinking_budget: Option<usize>,
}

impl LLMClientCompletionStringRequest {
Expand All @@ -719,6 +721,7 @@ impl LLMClientCompletionStringRequest {
frequency_penalty,
stop_words: None,
max_tokens: None,
thinking_budget: None,
}
}

Expand Down Expand Up @@ -755,6 +758,15 @@ impl LLMClientCompletionStringRequest {
pub fn get_max_tokens(&self) -> Option<usize> {
self.max_tokens
}

pub fn set_thinking_budget(mut self, thinking_budget: usize) -> Self {
self.thinking_budget = Some(thinking_budget);
self
}

pub fn thinking_budget(&self) -> Option<usize> {
self.thinking_budget
}
}

impl LLMClientCompletionRequest {
Expand All @@ -771,6 +783,7 @@ impl LLMClientCompletionRequest {
frequency_penalty,
stop_words: None,
max_tokens: None,
thinking_budget: None,
}
}

Expand Down Expand Up @@ -859,6 +872,15 @@ impl LLMClientCompletionRequest {
pub fn get_max_tokens(&self) -> Option<usize> {
self.max_tokens
}

pub fn set_thinking_budget(mut self, thinking_budget: usize) -> Self {
self.thinking_budget = Some(thinking_budget);
self
}

pub fn thinking_budget(&self) -> Option<usize> {
self.thinking_budget
}
}

#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
Expand Down
Loading