Skip to content

Commit

Permalink
amend clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
snowmead committed Apr 11, 2024
1 parent 3fc8028 commit b682d38
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,9 @@ impl<T: Config> TapestryFragment<T> {
fn push_message(&mut self, msg: ContextMessage<T>) -> Result<()> {
let tokens = T::PromptModel::count_tokens(&msg.content)?;
let new_token_count = self.context_tokens.checked_add(&tokens).ok_or_else(|| {
LoomError::from(WeaveError::BadConfig(format!(
"Number of tokens exceeds max tokens for model"
)))
LoomError::from(WeaveError::BadConfig(
"Number of tokens exceeds max tokens for model".to_string(),
))
})?;

self.context_tokens = new_token_count;
Expand All @@ -312,7 +312,7 @@ impl<T: Config> TapestryFragment<T> {
fn extend_messages(&mut self, msgs: Vec<ContextMessage<T>>) -> Result<()> {
let total_new_tokens = msgs
.iter()
.map(|m| T::PromptModel::count_tokens(&m.content).unwrap().clone())
.map(|m| T::PromptModel::count_tokens(&m.content).unwrap())
.collect::<Vec<_>>();

let sum: PromptModelTokens<T> = total_new_tokens
Expand All @@ -321,9 +321,9 @@ impl<T: Config> TapestryFragment<T> {

// Check the total token count before proceeding
let new_token_count = self.context_tokens.checked_add(&sum).ok_or_else(|| {
LoomError::from(WeaveError::BadConfig(format!(
"Number of tokens exceeds max tokens for model"
)))
LoomError::from(WeaveError::BadConfig(
"Number of tokens exceeds max tokens for model".to_string(),
))
})?;

// Update the token count and messages only if all checks pass
Expand Down

0 comments on commit b682d38

Please sign in to comment.