Allow Anthropic custom models to override temperature (#18160)

Release Notes:

- Allow Anthropic custom models to override "temperature"

This also centralized the defaulting of "temperature" to be inside of
each model's `into_x` call instead of being sprinkled around the code.
This commit is contained in:
Roy Williams 2024-09-20 16:59:12 -04:00 committed by GitHub
parent 7d62fda5a3
commit 5905fbb9ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 54 additions and 17 deletions

View file

@ -236,7 +236,7 @@ pub struct LanguageModelRequest {
pub messages: Vec<LanguageModelRequestMessage>,
pub tools: Vec<LanguageModelRequestTool>,
pub stop: Vec<String>,
pub temperature: f32,
pub temperature: Option<f32>,
}
impl LanguageModelRequest {
@ -262,7 +262,7 @@ impl LanguageModelRequest {
.collect(),
stream,
stop: self.stop,
temperature: self.temperature,
temperature: self.temperature.unwrap_or(1.0),
max_tokens: max_output_tokens,
tools: Vec::new(),
tool_choice: None,
@ -290,7 +290,7 @@ impl LanguageModelRequest {
candidate_count: Some(1),
stop_sequences: Some(self.stop),
max_output_tokens: None,
temperature: Some(self.temperature as f64),
temperature: self.temperature.map(|t| t as f64).or(Some(1.0)),
top_p: None,
top_k: None,
}),
@ -298,7 +298,12 @@ impl LanguageModelRequest {
}
}
pub fn into_anthropic(self, model: String, max_output_tokens: u32) -> anthropic::Request {
pub fn into_anthropic(
self,
model: String,
default_temperature: f32,
max_output_tokens: u32,
) -> anthropic::Request {
let mut new_messages: Vec<anthropic::Message> = Vec::new();
let mut system_message = String::new();
@ -400,7 +405,7 @@ impl LanguageModelRequest {
tool_choice: None,
metadata: None,
stop_sequences: Vec::new(),
temperature: Some(self.temperature),
temperature: self.temperature.or(Some(default_temperature)),
top_k: None,
top_p: None,
}