fix: add MinimaxHandler to strip thinking tags from content
All checks were successful
BotServer CI/CD / build (push) Successful in 4m8s
All checks were successful
BotServer CI/CD / build (push) Successful in 4m8s
This commit is contained in:
parent
ea8857ec8a
commit
2c82a8bd2e
2 changed files with 50 additions and 0 deletions
47
src/llm/llm_models/minimax.rs
Normal file
47
src/llm/llm_models/minimax.rs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
use super::ModelHandler;
|
||||
use regex::Regex;
|
||||
use std::sync::LazyLock;
|
||||
|
||||
static THINK_REGEX: LazyLock<Result<Regex, regex::Error>> =
|
||||
LazyLock::new(|| Regex::new(r"(?s)(分析).*?(/分析)"));
|
||||
static THINK_REGEX2: LazyLock<Result<Regex, regex::Error>> =
|
||||
LazyLock::new(|| Regex::new(r"(?s)<think>.*?</think>"));
|
||||
static THINK_REGEX3: LazyLock<Result<Regex, regex::Error>> =
|
||||
LazyLock::new(|| Regex::new(r"(?s)【分析】.*?【/分析】"));
|
||||
|
||||
pub fn strip_think_tags(content: &str) -> String {
|
||||
let mut result = content.to_string();
|
||||
if let Ok(re) = &*THINK_REGEX {
|
||||
result = re.replace_all(&result, "").to_string();
|
||||
}
|
||||
if let Ok(re) = &*THINK_REGEX2 {
|
||||
result = re.replace_all(&result, "").to_string();
|
||||
}
|
||||
if let Ok(re) = &*THINK_REGEX3 {
|
||||
result = re.replace_all(&result, "").to_string();
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct MinimaxHandler;
|
||||
|
||||
impl MinimaxHandler {
|
||||
pub fn new() -> Self {
|
||||
Self
|
||||
}
|
||||
}
|
||||
|
||||
impl ModelHandler for MinimaxHandler {
|
||||
fn is_analysis_complete(&self, buffer: &str) -> bool {
|
||||
buffer.contains("(/分析)") || buffer.contains("</think>") || buffer.contains("【/分析】")
|
||||
}
|
||||
|
||||
fn process_content(&self, content: &str) -> String {
|
||||
strip_think_tags(content)
|
||||
}
|
||||
|
||||
fn has_analysis_markers(&self, buffer: &str) -> bool {
|
||||
buffer.contains("(分析)") || buffer.contains("<think>") || buffer.contains("【分析】")
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
pub mod deepseek_r3;
|
||||
pub mod gpt_oss_120b;
|
||||
pub mod gpt_oss_20b;
|
||||
pub mod minimax;
|
||||
|
||||
pub trait ModelHandler: Send + Sync {
|
||||
fn is_analysis_complete(&self, buffer: &str) -> bool;
|
||||
|
|
@ -34,6 +35,8 @@ pub fn get_handler(model_path: &str) -> Box<dyn ModelHandler> {
|
|||
Box::new(gpt_oss_120b::GptOss120bHandler::new())
|
||||
} else if path.contains("20b") {
|
||||
Box::new(gpt_oss_20b::GptOss20bHandler)
|
||||
} else if path.contains("minimax") || path.contains("minimax-m") {
|
||||
Box::new(minimax::MinimaxHandler::new())
|
||||
} else {
|
||||
Box::new(PassthroughHandler)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue