summaryrefslogtreecommitdiffstats
path: root/src/utils/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/mod.rs')
-rw-r--r--src/utils/mod.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
index 9dde751..049f361 100644
--- a/src/utils/mod.rs
+++ b/src/utils/mod.rs
@@ -26,11 +26,13 @@ use anyhow::{Context, Result};
use fancy_regex::Regex;
use fuzzy_matcher::{skim::SkimMatcherV2, FuzzyMatcher};
use is_terminal::IsTerminal;
+use std::borrow::Cow;
use std::{env, path::PathBuf, process};
use unicode_segmentation::UnicodeSegmentation;
lazy_static::lazy_static! {
pub static ref CODE_BLOCK_RE: Regex = Regex::new(r"(?ms)```\w*(.*)```").unwrap();
+ pub static ref THINK_TAG_RE: Regex = Regex::new(r"(?s)^\s*<think>.*?</think>(\s*|$)").unwrap();
pub static ref IS_STDOUT_TERMINAL: bool = std::io::stdout().is_terminal();
pub static ref NO_COLOR: bool = env::var("NO_COLOR").ok().and_then(|v| parse_bool(&v)).unwrap_or_default() || !*IS_STDOUT_TERMINAL;
}
@@ -59,6 +61,10 @@ pub fn parse_bool(value: &str) -> Option<bool> {
}
}
+pub fn strip_think_tag(text: &str) -> Cow<str> {
+ THINK_TAG_RE.replace_all(text, "")
+}
+
pub fn estimate_token_length(text: &str) -> usize {
let words: Vec<&str> = text.unicode_words().collect();
let mut output: f32 = 0.0;