From 8e5d4e55b1a5158a1f35adaf044dec545159f426 Mon Sep 17 00:00:00 2001 From: sigoden Date: Wed, 6 Mar 2024 08:35:40 +0800 Subject: refactor: rename model's `max_tokens` to `max_input_tokens` (#339) BREAKING CHANGE: rename model's `max_tokens` to `max_input_tokens` --- src/config/mod.rs | 6 +++--- src/config/session.rs | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src/config') diff --git a/src/config/mod.rs b/src/config/mod.rs index 4a37378..909e751 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -750,7 +750,7 @@ impl Config { pub fn prepare_send_data(&self, input: &Input, stream: bool) -> Result { let messages = self.build_messages(input)?; - self.model.max_tokens_limit(&messages)?; + self.model.max_input_tokens_limit(&messages)?; Ok(SendData { messages, temperature: self.get_temperature(), @@ -773,8 +773,8 @@ impl Config { output.insert("client_name", self.model.client_name.clone()); output.insert("model_name", self.model.name.clone()); output.insert( - "max_tokens", - self.model.max_tokens.unwrap_or_default().to_string(), + "max_input_tokens", + self.model.max_input_tokens.unwrap_or_default().to_string(), ); if let Some(temperature) = self.temperature { if temperature != 0.0 { diff --git a/src/config/session.rs b/src/config/session.rs index e824c43..dd610a5 100644 --- a/src/config/session.rs +++ b/src/config/session.rs @@ -108,8 +108,8 @@ impl Session { data["temperature"] = temperature.into(); } data["total_tokens"] = tokens.into(); - if let Some(max_tokens) = self.model.max_tokens { - data["max_tokens"] = max_tokens.into(); + if let Some(conext_window) = self.model.max_input_tokens { + data["max_input_tokens"] = conext_window.into(); } if percent != 0.0 { data["total/max"] = format!("{}%", percent).into(); @@ -138,8 +138,8 @@ impl Session { items.push(("compress_threshold", compress_threshold.to_string())); } - if let Some(max_tokens) = self.model.max_tokens { - items.push(("max_tokens", max_tokens.to_string())); + if let Some(max_input_tokens) = self.model.max_input_tokens { + items.push(("max_input_tokens", max_input_tokens.to_string())); } let mut lines: Vec = items @@ -179,11 +179,11 @@ impl Session { pub fn tokens_and_percent(&self) -> (usize, f32) { let tokens = self.tokens(); - let max_tokens = self.model.max_tokens.unwrap_or_default(); - let percent = if max_tokens == 0 { + let max_input_tokens = self.model.max_input_tokens.unwrap_or_default(); + let percent = if max_input_tokens == 0 { 0.0 } else { - let percent = tokens as f32 / max_tokens as f32 * 100.0; + let percent = tokens as f32 / max_input_tokens as f32 * 100.0; (percent * 100.0).round() / 100.0 }; (tokens, percent) -- cgit v1.2.3